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