so I used code first approach and ViewModel. Now I complete the Insertion process . Now I want to know how to do Update and Delete process using Code First approach and ViewModel. Please any one give me the solution
My Model
public class CustomerModel1
{
public System.Guid CustomerID { get; set; }
public string DisplayName { get; set; }
public string PrintName { get; set; }
}
public partial class ContactModel
{
public System.Guid ContactID { get; set; }
public string DisplayName { get; set; }
public string PrintName { get; set; }
public string Mobile1 { get; set; }
public string Mobile2 { get; set; }
public string Phone1 { get; set; }
public string Phone2 { get; set; }
public string Email1 { get; set; }
public string Website1 { get; set; }
}
My VieModel
public class CustomerViewModel
{
public System.Guid CustomerID { get; set; }
public string CustomerName { get; set; }
public System.Guid ContactID { get; set; }
public string ContactPerson { get; set; }
public string PhoneNo1 { get; set; }
public string PhoneNo2 { get; set; }
public string MobileNo1 { get; set; }
public string MobileNo2 { get; set; }
public string Website1 { get; set; }
}
public class VisitorsEntities1 : DbContext
{
public DbSet Customer { get; set; }
public DbSet Contact { get; set; }
}
My Controllerpublic ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(CustomerViewModel viewmodel)
{
var Customerobj = new Customer()
{
CustomerID= Guid .NewGuid (),
DisplayName = viewmodel.CustomerName,
PrintName = viewmodel .CustomerName
};
var Contactobj = new Contact()
{
ContactID= Guid.NewGuid(),
DisplayName= viewmodel.CustomerName,
PrintName=viewmodel.CustomerName,
Mobile1=viewmodel.MobileNo1,
Mobile2 = viewmodel.MobileNo2,
Phone1= viewmodel.PhoneNo1,
Phone2=viewmodel.PhoneNo2,
Email1=viewmodel.Email1,
Website1=viewmodel.Website1
db.Customer.Add(Customerobj);
db.Contact.Add(Contactobj);
db.SaveChanges();
return View();
}
Here i complete the insert process using CodeFirstApproach and ViewModel. Insertion is working fine. Now I want to do Update ,Delete and Details (Index) Process . How to do that using code first approach and ViewModel.
Thanks
Ravi PatelRank #439 · 5.7K reputationPosted Dec 15, 2015, 5:04 AM EST
Ravi PatelRank #439 · 5.7K reputationPosted Dec 15, 2015, 5:18 AM EST
Sneha KRank #2,496 · 563 reputationPosted Dec 15, 2015, 6:47 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts