TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sneha K
1.2k
527
195.9k
ieqwupdate Delete method using CodeFirstApproach and V
Dec 15 2015 8:51 AM
Hi I want to do update delete Process using Code First approach and view model in mvc4.I had create the view and i done insertion process using Code First approach and ViewModel because my DB is fully normalized and i used EF .
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 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
Reply
Answers (
3
)
c# codefor text steganography using vedic numeric code table
.Net database