public Models.Vendor Create(Models.Vendor entity) { try { entity = VendorDataProccessor.ValidationAndProcess(entity); if (((new RestfulModels.Vendor()).Search(new Models.VendorSearchModel() { Title = entity.Title })).Count() > 0) { var e = new RestfulModels.ValidationException(); e.ValidationErrors.Add("已经存在"); throw e; } DbEntities.Vendors.AddObject(entity); DbEntities.SaveChanges(); DbEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, entity); return(entity); } catch { throw; } }
public Models.Vendor Update(int id, Models.Vendor entity) { try { entity = VendorDataProccessor.ValidationAndProcess(entity); entity.Id = id; DbEntities.ApplyCurrentValues("Vendors", entity); DbEntities.SaveChanges(); return(entity); } catch { throw; } }