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
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sneha KPosted Dec 15, 2015, 11:47 AM
Ravi PatelPosted Dec 15, 2015, 10:18 AM
Ravi PatelPosted Dec 15, 2015, 10:04 AM