-->

ABOUT US

Our development agency is committed to providing you the best service.

OUR TEAM

The awesome people behind our brand ... and their life motto.

  • Kumar Atul Jaiswal

    Ethical Hacker

    Hacking is a Speed of Innovation And Technology with Romance.

  • Kumar Atul Jaiswal

    CEO Of Hacking Truth

    Loopholes are every major Security,Just need to Understand it well.

  • Kumar Atul Jaiswal

    Web Developer

    Techonology is the best way to Change Everything, like Mindset Goal.

OUR SKILLS

We pride ourselves with strong, flexible and top notch skills.

Marketing

Development 90%
Design 80%
Marketing 70%

Websites

Development 90%
Design 80%
Marketing 70%

PR

Development 90%
Design 80%
Marketing 70%

ACHIEVEMENTS

We help our clients integrate, analyze, and use their data to improve their business.

150

GREAT PROJECTS

300

HAPPY CLIENTS

650

COFFEES DRUNK

1568

FACEBOOK LIKES

STRATEGY & CREATIVITY

Phasellus iaculis dolor nec urna nullam. Vivamus mattis blandit porttitor nullam.

PORTFOLIO

We pride ourselves on bringing a fresh perspective and effective marketing to each project.

Showing posts with label CRUD. Show all posts
Showing posts with label CRUD. Show all posts
  • Create Web Application for CRUD operation

     


     

     

    Create Web API for CRUD operation


    So ladies and gentlemen here we will create a new web application project in which GET, POST, PUT, and delete method will be used for CRUD operation.
     
    So first we make one, for this you have to go to the file --> New --> Project then write on name section (whatever you want) and without disturbing the rest, you just clicked on the OK button.

     





     
    and then you choose to MVC option in next tab and same as it as click on OK button.

     


     

     

    So, as you can see this our project empty project is ready to launch on localhost...let's run first before write any code.
     

     



    For this, Shortcut command press by keyboard


    ctrl + F5

    As you can see this here are displaying the project in browser by localhost

    URL http://localhost:59322/





     

     

     

    Add Models

     

    So before proceeding here on the left side you are able to see some options, with the help of which we will create controller class, model class.
     





    Wait, if your Solution Explorer not showing there, don't worry...follow to our steps.


    Click on view --> Click Solution Explorer, Server Explorer option etc.



    First we will create class and for this you have go to Models option and right click on this and go to Add --> class --> choose first option (Class) --> change the class name like in our case (class name is Student) and then click Add. button.

     

     


     

     

     




     

     


    After creating a class then we write some code for generating a table name or attribute name like StudentID, StudentName

    In Student.cs file -


    So, write this command in your code...as it as same and don't forget to add LINE no 5 code (System.ComponentModel.DataAnnotations;)


     

    [Key]
    public int StudentID { get; set; }
    public string StudentName { get; set; }
    
    
    

     



     

     

     

    NOTE - The get method returns the value of the variable name . The set method assigns a value to the name variable. The value keyword represents the value we assign to the property.
     

    Then go to IdentityModels.cs file write this command also.
     

     

    public DbSet <Student> Student { get; set; }
    
    

     


     



     

     

    Save all file (ctrl + s).
     

     


    Before diving into long sea..let's build first and create a migrations, add migrations and update-database.


    For this Click on Build --> Build Solution
     

     


     

     


     

     


    Then,

    Go to Tools --> NuGet Package Manager --> Package Manager Console
     

     



    enable-migrations 





    And at the same time you are able to see that the file is being created inside the migrations.
     

     


     

     

    add-migration init 

     

     


     

     


     

     

    update-database

     

     


     

     


    • The Enable-Migration command creates the Migrations folder, which contains a script to initialize the database. 
    •  
    • (init is a migration name)
    •  
    • Update the database for any kind of changes





    Now, after updating the database as you can see this in Server explorer section

    Data connection --> Tables --> Table name (in our case Students is table name).

     


     

     

     

    Add Web API Controller



    So before proceeding here on the left side you are able to see some options, with the help of which we will create controller class, model class.

    For create a Controller class right click on controller --> Add --> choose Controller option.
     

     


     

     

    Choose MVC 5 Controller - Empty and then click on Add button.





    This will open Add Scaffold popup as shown below.

     

     


     

     

    Attention Please in Add Controller popup tab, here Controller name is DefaultController. So, Remove "Default" word and type any name whatever you want (in our case we are going to write "Student") then click on Add button.





     

     

     


    In StudentController.cs file write some code for doing a CRUD operation... but first we are doing a Create operation.

    Type this command -




     

    [HttpPost]
    public ActionResult Create(Student s)
            {
             ApplicationDbContext db = new ApplicationDbContext();
             db.Student.Add(s);
             db.SaveChanges();
             return View();
            }
    
    
    

     


     

     


    If in case any error are there like this shown below, then tension we are here for your help.

    Simple mouse click on this red line error and as you can see that A yellow light bulb appear here so click on little arrow and choose "using WebApplication2.Models; (In your case this name may be different, don't worry)

     


     

    Hurray Error is gone :-) :-p


    and "using WebApplication2.Models;" line is added on StudentController.cs file. DONE





     

     


    Hurray Error is gone :-) :-p





    and "using WebApplication2.Models;" line is added on StudentController.cs file. DONE
     

     



    Now, we will create a Add view. So, for this you have to right click on "Create" --> Add view --> and choose the correct all option as it as same.







    then Click on Add button.



    This will open Add Scaffold popup as shown below.





    In solution explorer, there are appear Create.cshtml file.






    and finally we will run.

    ctrl + F5

    or

    Click on Middle top side Green color button...click on it.


     





    public ActionResult Display()
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var lst = db.Student.ToList();
                return View(lst);
            }
            public ActionResult Details(int id)
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var s = db.Student.Where(x => x.StudentID == id).SingleOrDefault();
                return View(s);
            }
    
    


    Please Be Patience We Will Update Very Soon :-)



    Disclaimer

     

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.



  • CRUD in asp.net

     



     

    What is CRUD?



    CRUD is stands for "Create, Read, Update, and Delete".

    These are the four basic operation for managing data in an application.

    In HTTP we find four main methods that can perform processing on data that are defined in the REST architecture. This correspondence can also be done with CRUD.


    GET     ->  Retrieve
    POST    ->  Create
    PUT     ->  Update
    Delete  ->  Delete



    CRUD Operation


    To Insert



    Public class HomeController: Controller 
    
    [HTTPPOST]
    
    //controller is a class
    
    public ActionResult InsertData(Students s)
     {
       ApplicationDb db = new ApplicationDb();
       
       db.Students.Add(s);
       db.SaveChanges();
       
       return view();
       
      }
      
    




    To read


    ApplicationDb db = new ApplicationDb();
    
    var lst = db.Students.ToList();
    
    List<Students> list = db.students.ToList();
    
    foreach(var obj in list)
    {
    console.writeline (obj.StudentsId);
    console.writeline (obj.StudentsName);
    }
    





    To Update


    ApplicationDb db = new ApplicationDb();
    
    Students s = db.Students.Where(x => x.StudentsId == items.StudentsId).SingleOrDefault();
    
    //items is a model name
    
    s.StudentsName = new StudentsName;
    
    db.SaveChanges();
     
    



    To Edit Single Update


    Public Class HomeController: Controller
    
    {
    
    ApplicationDb db = new ApplicationDb();
    
    Students s = db.Students.Where(x => x.StudentsId == StudentsId).SingleOrDefault();
    
    return view(s);
    
    }
    
    
    



    To Delete


    List <Students> s = db.studentsToList()
    
    
    if(s!=null)
    {
      foreach(var t in s)
       {  
         db.students.remove(t);
       }
      
      db.savechanges();
     
    } 
    
    




    Disclaimer

     

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.




  • WHAT WE DO

    We've been developing corporate tailored services for clients for 30 years.

    CONTACT US

    For enquiries you can contact us in several different ways. Contact details are below.

    Hacking Truth.in

    • Street :Road Street 00
    • Person :Person
    • Phone :+045 123 755 755
    • Country :POLAND
    • Email :contact@heaven.com

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.