public void InsertPublisher(PublisherVM pub) { pub.CreatedBy = 1; pub.CreatedDate = DateTime.Now; if (pub.PublisherUrl == null) { var url = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(pub.PublisherName); pub.PublisherUrl = url; } JavaScriptSerializer serializer = new JavaScriptSerializer(); var c = serializer.Serialize(pub); PublisherMaster pubmaster = serializer.Deserialize <PublisherMaster>(c); try { db.PublisherMasters.Add(pubmaster); db.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
public void PublisherEdit(PublisherVM pub) { pub.ModifiedBy = 1; pub.ModifiedDate = DateTime.Now; JavaScriptSerializer serializer = new JavaScriptSerializer(); var publish = serializer.Serialize(pub); PublisherMaster pubmast = serializer.Deserialize <PublisherMaster>(publish); db.Entry(pubmast).State = EntityState.Modified; db.SaveChanges(); }