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 AddTag(string parentId, string tagName, string code, string description)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                Tag tag = new Tag();
                tag.TagName = tagName;
                tag.TagCode = code;
                tag.Description = description;

                //父标签
                Guid pid;
                if (Guid.TryParse(parentId, out pid))
                {
                    tag.Parent = context.Tags.Find(pid);
                }

                tag.CreateTime = DateTime.Now;
                tag.State = (int)EnumHelper.State.Enable;//默认启用

                context.Tags.Add(tag);

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #3
0
        //添加导航时不对排序字段进行设置,默认为0,显示在最前的位置,当第一次执行排序操作时,将会对SortIndex进行更新
        public void AddNavigation(string navName, string url, string description, string parentId, bool asMenu)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                Navigation nav = new Navigation();
                nav.NavigationName = navName;
                nav.Url = url;
                nav.Description = description;
                nav.AsMenu = asMenu;

                //父导航
                Guid id;
                if (Guid.TryParse(parentId, out id))
                {
                    nav.Parent = context.Navigations.Find(id);
                }

                nav.State = (int)EnumHelper.State.Enable;
                nav.CreateTime = DateTime.Now;

                context.Navigations.Add(nav);

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
        public int AddNavigation(string parentId, string navName, string url, int type, string description)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                FrontendNavigation nav = new FrontendNavigation();

                nav.NavName = navName;
                nav.Url = url;
                nav.Type = type;

                //添加父导航
                Guid pid;
                if (Guid.TryParse(parentId, out pid))
                {
                    nav.Parent = context.FrontendNavigations.Find(pid);
                }
                nav.Description = description;
                nav.State = (int)EnumHelper.State.Enable;
                nav.CreateTime = DateTime.Now;

                context.FrontendNavigations.Add(nav);

                context.LogChangesDuringSave = true;
                return context.SaveChanges();

            }
        }
Example #5
0
        public void AddAttachImage(string infoid, string path, string description)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var info = GetDetailIncludeAll(infoid);
                context.Informations.Attach(info);
                //var info = GetDetailIncludeAll(infoid, context);
                if (info.Attachments == null)
                {
                    info.Attachments = new List<Attachment>();
                }
                long sortindex = info.Attachments.Count == 0 ? 0 : (info.Attachments.Select(a => a.SortIndex).Max() + 10);
                info.Attachments.Add(new Attachment()
                {
                    SourceUrl = path,
                    Description = description,
                    CreateTime = DateTime.Now,
                    State = (int)EnumHelper.State.Disable,
                    SortIndex = sortindex
                });

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
Example #6
0
        public void Add(string rolename, string description, IList<string> navlist)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                RoleInfo role = new RoleInfo();
                role.RoleInfoId = Guid.NewGuid();
                role.RoleName = rolename;
                role.Description = description;
                role.CreateTime = DateTime.Now;

                //设置权限
                setNavigation(context, role, navlist);

                //角色类型
                if (SiteManager == null)
                {
                    //如果没有站点管理角色
                    role.RoleType = (int)RoleType.SiteManager;
                }
                else
                {
                    role.RoleType = (int)RoleType.Common;
                }

                context.RoleInfoes.Add(role);

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
Example #7
0
        public void Add(JoinApply apply)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.Entry(apply).State = EntityState.Added;

                context.SaveChanges();
            }
        }
Example #8
0
 public IList<Navigation> GetActiveList()
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         return context.Navigations
         .Where(n => n.State == (int)EnumHelper.State.Enable)
         .OrderByDescending(n => n.CreateTime)
         .ToList();
     }
 }
Example #9
0
        public int ChangeState(Attachment attach, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.Attachments.Attach(attach);
                attach.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #10
0
        public int ChangeState(UserInfo user, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.UserInfoes.Attach(user);
                user.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #11
0
        public IList<JoinApply> GetPagedList(int pageindex, int pagesize, out int count)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var query = context.JoinApplys
                    .OrderByDescending(j => j.ApplyTime);
                count = query.Count();

                return query.Skip(pagesize * (pageindex - 1)).Take(pagesize).ToList();
            }
        }
Example #12
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();
            }
        }
        public int ChangeState(FrontendNavigation nav, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.FrontendNavigations.Attach(nav);
                nav.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #14
0
        public IList<Log> GetPagedList(int pageindex, int pagesize, out int count)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var query = context.Logs
                    .OrderByDescending(l => l.CreateTime);
                count = query.Count();

                return query.Skip(pagesize * (pageindex - 1)).Take(pagesize).ToList();
            }
        }
Example #15
0
        public int ChangeState(Recruitment item, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.Recruitments.Attach(item);
                item.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #16
0
        public int ChangeState(RoleInfo role, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.RoleInfoes.Attach(role);
                role.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #17
0
 public UserInfo GetDetail(string userid)
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         Guid id;
         if (Guid.TryParse(userid, out id))
         {
             return context.UserInfoes.Find(id);
         }
         return null;
     }
 }
Example #18
0
 public JoinApply GetDetail(string applyid)
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         Guid id;
         if (Guid.TryParse(applyid, out id))
         {
             return context.JoinApplys.Find(id);
         }
         return null;
     }
 }
Example #19
0
        public IList<Recruitment> GetActivePagedList(int pageindex, int pagesize, out int count)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var query = context.Recruitments
                    .Where(r => r.State == (int)EnumHelper.State.Enable)
                    .OrderByDescending(r => r.PublishTime);
                count = query.Count();

                return query.Skip(pagesize * (pageindex - 1)).Take(pagesize).ToList();
            }
        }
Example #20
0
 public Log GetDetail(string logid)
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         Guid id;
         if (Guid.TryParse(logid, out id))
         {
             return context.Logs.Find(id);
         }
         return null;
     }
 }
Example #21
0
 public Attachment GetDetail(string attachId)
 {
     using (var context = new WSI.DataAccess.WSICmsContext())
     {
         Guid id;
         if (Guid.TryParse(attachId, out id))
         {
             return context.Attachments.Find(id);
         }
         return null;
     }
 }
Example #22
0
        public int Delete(string id)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var nav = GetDetailIncludeAll(id);
                context.Navigations.Attach(nav);

                context.Navigations.Remove(nav);

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #23
0
        public int AddInformation(
            string title,
            string subtitle,
            string source,
            string author,
            string adder,
            string summary,
            string content,
            string referenceUrl,
            bool isTop,
            IList<string> keywords,
            IList<string> navidlist,
            DateTime publishTime,
            string resourcePath
            )
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                Information info = new Information();

                info.Title = title;
                info.SubTitle = subtitle;
                info.Source = source;
                info.Author = author;
                info.Adder = adder;
                info.Summary = summary;
                info.Content = content;
                info.ReferenceUrl = referenceUrl;
                info.IsTop = isTop;
                info.PublishTime = publishTime;
                info.ResourcePath = resourcePath;

                //默认字段
                info.CreateTime = DateTime.Now;
                info.UpdateTime = DateTime.Now;
                info.State = (int)EnumHelper.State.Disable;//默认禁用,因为还要在列表页添加附件和预览

                //关键字
                setKeyWords(context, info, keywords);

                //所属栏目
                setNavigation(context, info, navidlist);

                context.Informations.Add(info);

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #24
0
        public void UpdateAttach(string attachId, string description, int sortIndex)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var attach = GetDetail(attachId);
                if (attach != null)
                {
                    context.Attachments.Attach(attach);
                    attach.Description = description;
                    attach.SortIndex = sortIndex;

                    context.LogChangesDuringSave = true;
                    context.SaveChanges();
                }
            }
        }
Example #25
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();
            }
        }
        public int Delete(string id)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                //只能删除没有子项的栏目
                if (GetSortedListByParentId(id).Count == 0)
                {
                    var nav = GetDetail(id);
                    context.FrontendNavigations.Attach(nav);

                    context.FrontendNavigations.Remove(nav);

                    context.LogChangesDuringSave = true;
                    return context.SaveChanges();
                }
                return 0;
            }
        }
Example #27
0
        public int Delete(string id)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var item = GetDetail(id);
                if (item != null)
                {
                    context.Attachments.Attach(item);

                    var info = context.Informations.Find(item.InformationId);
                    //先将该附件从信息中移除
                    info.Attachments.Remove(item);
                    context.Attachments.Remove(item);
                }

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Example #28
0
        public void Add(string name, string password, IList<string> roleidlist)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                UserInfo user = new UserInfo();
                //user.UserId = Guid.NewGuid();
                user.UserName = name;
                user.UserPassword = password.EncryptMD5();
                user.CreateTime = DateTime.Now;
                user.LastVisitTime = DateTime.Now;
                user.State = (int)EnumHelper.State.Disable;

                //添加角色
                setRoleInfo(context, user, roleidlist);

                context.UserInfoes.Add(user);
                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
Example #29
0
        public void AddRecruitment(string position, string department, string workplace, string duty, string requirement, DateTime publishTime)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                var recruit = new Recruitment()
                {
                    Position = position,
                    Department = department,
                    WorkPlace = workplace,
                    Duty = duty,
                    Requirement = requirement,
                    PublishTime = publishTime
                };

                context.Recruitments.Add(recruit);

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
Example #30
0
        public void AddCookBook(
            string name,
            string summary,
            string source,
            string referenceUrl,
            string materail,
            string benifits,
            string practice,
            string tips,
            string navid,
            bool isRecommend)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.CookBooks.Add(new CookBook()
                {
                    CookBookName = name,
                    Summary = summary,
                    Source = source,
                    ReferenceUrl = referenceUrl,
                    Material = materail,
                    Benifits = benifits,
                    Practice = practice,
                    Tips = tips,
                    NavigationId = Guid.Parse(navid),
                    IsRecommend = isRecommend,

                    ImageUrl = "",
                    LikeCount = 0,
                    State = (int)EnumHelper.State.Disable,
                    CreateTime = DateTime.Now
                });

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }