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 Controller
public 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