Example #1
0
        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;
            }
        }
Example #2
0
        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();
            }
        }
Example #3
0
        public void Add(JoinApply apply)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.Entry(apply).State = EntityState.Added;

                context.SaveChanges();
            }
        }
Example #4
0
        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();
            }
        }
Example #5
0
        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;
                }
            }
        }
Example #6
0
 public int Update(UserInfo user)
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         context.Entry<UserInfo>(user).State = EntityState.Modified;
         return context.SaveChanges();
     }
 }
Example #7
0
        //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();
            }
        }