public bool AddSize(string sizeName, int width, int height, int thumb_width, int thumb_height, int cover_width, int cover_height, out IList<string> errors) { using (var context = new WSI.DataAccess.WSICmsContext()) { var entity = new ImageSize() { SizeName = sizeName, Width = width, Height = height, ThumbWidth = thumb_width, ThumbHeight = thumb_height, CoverWidth = cover_width, CoverHeight = cover_height, State = (int)EnumHelper.State.Enable, CreateTime = DateTime.Now }; var validate = context.Entry(entity).GetValidationResult(); if (!validate.IsValid) { errors = validate.ValidationErrors.Select(e => e.ErrorMessage).ToList(); return false; } context.ImageSizes.Add(entity); context.LogChangesDuringSave = true; context.SaveChanges(); errors = null; return true; } }
public int Delete(string userid) { using (var context = new WSI.DataAccess.WSICmsContext()) { var user = GetDetail(userid); context.UserInfoes.Attach(user); //加载个人信息和角色信息到内存中 context.Entry(user).Reference(u => u.Profile).Load(); context.Entry(user).Collection(u => u.RoleList).Load(); context.UserInfoes.Remove(user); context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void Add(JoinApply apply) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.Entry(apply).State = EntityState.Added; context.SaveChanges(); } }
public int Delete(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(id); context.Entry(item).State = EntityState.Deleted; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public bool UpdateSize(string sizeid, string sizeName, int width, int height, int thumb_width, int thumb_height, int cover_width, int cover_height, out IList<string> errors) { using (var context = new WSI.DataAccess.WSICmsContext()) { var entity = GetDetail(sizeid); context.ImageSizes.Attach(entity); entity.SizeName = sizeName; entity.Width = width; entity.Height = height; entity.ThumbWidth = thumb_width; entity.ThumbHeight = thumb_height; entity.CoverWidth = cover_width; entity.CoverHeight = cover_height; var validate = context.Entry(entity).GetValidationResult(); if (validate.IsValid) { context.LogChangesDuringSave = true; context.SaveChanges(); errors = null; return true; } else { errors = validate.ValidationErrors.Select(e => e.ErrorMessage).ToList(); return false; } } }
public int Update(UserInfo user) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.Entry<UserInfo>(user).State = EntityState.Modified; return context.SaveChanges(); } }
//info中包含所有级联数据,删除时也同时删除级联数据 public int Delete(string infoid) { using (var context = new WSI.DataAccess.WSICmsContext()) { var info = GetDetail(infoid); context.Informations.Attach(info); //栏目关联信息,关键字关联信息,附件信息(不包括图片)都将被自动删除 var entry = context.Entry(info); entry.Collection(i => i.NavigationList).Load(); entry.Collection(i => i.KeyWords).Load(); entry.Collection(i => i.Attachments).Load(); context.Informations.Remove(info); //删除所有附件的文件 context.LogChangesDuringSave = true; return context.SaveChanges(); } }