Exemplo n.º 1
0
        public IActionResult Create(RoleCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.RoleName.Trim().Length <= 0)
            {
                response.SetFailed("请输入角色名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.SystemRole.Count(x => x.RoleName == model.RoleName) > 0)
                {
                    response.SetFailed("角色已存在");
                    return(Ok(response));
                }
                var entity = new SystemRole();
                entity.SystemRoleUuid = Guid.NewGuid();
                entity.RoleName       = model.RoleName;
                entity.AddTime        = DateTime.Now.ToString("yyyy-MM-dd");
                entity.AddPeople      = AuthContextService.CurrentUser.DisplayName;
                entity.IsDeleted      = 0;
                _dbContext.SystemRole.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:系统角色管理列表数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
Exemplo n.º 2
0
 public IActionResult Create(Entities.RestsData model)
 {
     using (_dbContext)
     {
         var response = ResponseModelFactory.CreateResultInstance;
         var query    = _dbContext.RestsData.FirstOrDefault(x => x.Name == model.Name && x.Type == model.Type);
         if (query != null)
         {
             response.SetFailed("该类别名称已存在");
             return(Ok(response));
         }
         var entity = new Entities.RestsData
         {
             RestsDataUuid = Guid.NewGuid(),
             Name          = model.Name,
             Accessory     = model.Accessory,
             Type          = model.Type,
             UpdatePeople  = AuthContextService.CurrentUser.LoginName,
             UpdateTime    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
             AddPeople     = AuthContextService.CurrentUser.LoginName,
             AddTime       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
         };
         _dbContext.RestsData.Add(entity);
         var res = _dbContext.SaveChanges();
         if (res > 0)
         {
             ToLog.AddLog("添加", "成功:添加:其他数据信息一条数据", _dbContext);
         }
         response.SetSuccess();
         return(Ok(response));
     }
 }
Exemplo n.º 3
0
        public IActionResult Create(ProclamationViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = new Proclamation();
                entity.ProclamationTitle   = model.ProclamationTitle;
                entity.ProclamationContent = model.ProclamationContent;
                entity.Remark           = model.Remark;
                entity.SortId           = model.SortId;
                entity.IsStick          = model.IsStick;
                entity.ProclamationUuid = Guid.NewGuid();
                entity.IsDeleted        = 0;
                entity.AddPeople        = AuthContextService.CurrentUser.LoginName;
                entity.AddTime          = DateTime.Now.ToString("yyyy-MM-dd");
                _dbContext.Proclamation.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:通知公告列表信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
        public IActionResult Create(ColumnViewModel vmodel)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                if (_dbContext.Content.Any(x => x.ColumnTitle == vmodel.ColumnTitle && x.IsDeleted == 0))
                {
                    response.SetFailed("已存在该名称的栏目");
                    return(Ok(response));
                }

                var query = _dbContext.Column.FirstOrDefault(x => x.ColumnUuid == vmodel.SuperiorUuid);
                if (query == null)
                {
                    response.SetFailed("请填写上级栏目");
                    return(Ok(response));
                }
                if (vmodel.IssueTime == "")
                {
                    response.SetFailed("请选择发布时间");
                    return(Ok(response));
                }
                var entity = new Content();
                entity.ColumnUuid  = Guid.NewGuid();
                entity.IsDeleted   = 0;
                entity.ColumnTitle = vmodel.ColumnTitle;
                entity.AddTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                entity.AddPeople   = AuthContextService.CurrentUser.LoginName;

                entity.SuperiorUuid    = vmodel.SuperiorUuid;
                entity.SuperiorMenu    = query.SuperiorMenu + 1;
                entity.ColumnTitleText = query.ColumnTitle;
                entity.ColumnModel     = "列表栏目";
                entity.ColumnContent   = vmodel.ColumnContent;
                entity.Staue           = vmodel.Staue;
                entity.SortId          = vmodel.SortId;
                entity.IsStick         = vmodel.IsStick;
                if (!string.IsNullOrEmpty(vmodel.IssueTime))
                {
                    entity.IssueTime = Convert.ToDateTime(vmodel.IssueTime).ToString("yyyy-MM-dd");
                }
                _dbContext.Content.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:内容管理信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
Exemplo n.º 5
0
        public IActionResult Create(ColumnViewModel vmodel)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                if (_dbContext.Column.Any(x => x.ColumnTitle == vmodel.ColumnTitle && x.IsDeleted == 0 && x.SuperiorUuid == vmodel.SuperiorUuid))
                {
                    response.SetFailed("已存在该名称的栏目");
                    return(Ok(response));
                }
                var entity = new Column();

                entity.ColumnUuid  = Guid.NewGuid();
                entity.IsDeleted   = 0;
                entity.ColumnTitle = vmodel.ColumnTitle;
                entity.AddTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                entity.AddPeople   = AuthContextService.CurrentUser.LoginName;
                //if (vmodel.SuperiorUuid == null || vmodel.SuperiorUuid == Guid.Empty)
                //{
                //    entity.SuperiorUuid = Guid.Empty;
                //    entity.SuperiorMenu = 0;
                //}
                //else
                //{
                //    Guid? newuuid = vmodel.SuperiorUuid;
                //    var supentity = _dbContext.Column.FirstOrDefault(x => x.ColumnUuid == newuuid);
                //    entity.SuperiorMenu = supentity.SuperiorMenu + 1;
                //    entity.SuperiorUuid = newuuid;
                //}
                entity.SuperiorUuid  = vmodel.SuperiorUuid;
                entity.SuperiorMenu  = vmodel.SuperiorUuid == null ? 0 : 1;
                entity.ColumnModel   = vmodel.ColumnModel;
                entity.IsStick       = vmodel.IsStick;
                entity.ColumnContent = vmodel.ColumnContent;
                entity.SortId        = vmodel.SortId;
                _dbContext.Column.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:栏目列表信息一条数据", _dbContext);
                }
                response.SetSuccess("操作成功");
                return(Ok(response));
            }
        }
Exemplo n.º 6
0
        public IActionResult Create(NewsViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                if (_dbContext.News.Count(x => x.NewsTitle == model.NewsTitle) > 0)
                {
                    response.SetFailed("标题已存在");
                    return(Ok(response));
                }
                var entity = new News();
                entity.NewsTitle    = model.NewsTitle;
                entity.NewSubhead   = model.NewSubhead;
                entity.NewsTypeUuid = model.NewsTypeUuid;
                entity.NewsContent  = model.NewsContent;
                entity.NewsPic      = model.NewsPic;
                if (!string.IsNullOrEmpty(model.NewsUrl))
                {
                    entity.NewsUrl = Convert.ToDateTime(model.NewsUrl).ToString("yyyy-MM-dd HH:mm:ss");
                }
                entity.Video     = model.Video;
                entity.File      = model.File;
                entity.Staue     = model.Staue;
                entity.SortId    = model.SortId;
                entity.IsStick   = model.IsStick;
                entity.NewsUuid  = Guid.NewGuid();
                entity.IsDeleted = 0;
                entity.AddPeople = AuthContextService.CurrentUser.LoginName;
                entity.AddTime   = DateTime.Now.ToString("yyyy-MM-dd");
                _dbContext.News.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:新闻列表信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
Exemplo n.º 7
0
 public IActionResult Create(MenuCreateViewModel model)
 {
     using (_dbContext)
     {
         var entity = _mapper.Map <MenuCreateViewModel, SystemMenu>(model);
         entity.CreatedOn         = DateTime.Now.ToString("yyyy-MM-dd");
         entity.SystemMenuUuid    = Guid.NewGuid();
         entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
         entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;
         entity.IsDeleted         = 0;
         entity.Icon = string.IsNullOrEmpty(entity.Icon) ? "md-menu" : entity.Icon;
         _dbContext.SystemMenu.Add(entity);
         int res = _dbContext.SaveChanges();
         if (res > 0)
         {
             ToLog.AddLog("添加", "成功:添加:系统菜单管理列表数据", _dbContext);
         }
         var response = ResponseModelFactory.CreateInstance;
         response.SetSuccess();
         return(Ok(response));
     }
 }
        public IActionResult Create(NewsTypeViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = new NewsType();
                entity.NewsTypeName = model.NewsTypeName;
                entity.NewsTypeUuid = Guid.NewGuid();
                entity.Remark       = model.Remark;
                entity.IsDeleted    = 0;
                entity.AddPeople    = AuthContextService.CurrentUser.LoginName;
                entity.AddTime      = DateTime.Now.ToString("yyyy-MM-dd");
                _dbContext.NewsType.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:新闻类型列表信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
        public IActionResult Create(PermissionCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入权限名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.SystemPermission.Count(x => x.ActionCode == model.ActionCode && x.SystemMenuUuid == model.SystemMenuUuid) > 0)
                {
                    response.SetFailed("权限操作码已存在");
                    return(Ok(response));
                }
                if (_dbContext.SystemPermission.Count(x => x.Name == model.Name && x.SystemMenuUuid == model.SystemMenuUuid) > 0)
                {
                    response.SetFailed("权限名称已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <PermissionCreateViewModel, SystemPermission>(model);
                entity.CreatedOn            = DateTime.Now.ToString("yyyy-MM-dd");
                entity.SystemPermissionUuid = Guid.NewGuid();
                entity.CreatedByUserGuid    = AuthContextService.CurrentUser.Guid;
                entity.CreatedByUserName    = AuthContextService.CurrentUser.DisplayName;
                _dbContext.SystemPermission.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:系统权限管理列表数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
Exemplo n.º 10
0
        public IActionResult Edit(GlobalViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;
            using (_dbContext)
            {
                var query = _dbContext.SystemSetting.FirstOrDefault(x => x.ClobalUuid == model.ClobalUuid);
                query.ClobalName = model.ClobalName;
                query.GlobalLogo = model.GlobalLogo;
                query.Globalurl = model.Globalurl;
                query.CountTime = Convert.ToDateTime(model.CountTime).ToString("yyyy-MM-dd");
                query.AddTime = DateTime.Now;
                _dbContext.SaveChanges();
                response.SetSuccess();
                return Ok(response);
            }

        }
Exemplo n.º 11
0
        public static string AddLog(string Typem, string Content, haiKanChemistryContext _dbContext)
        {
            string messange = "";
            var    entity   = new HaikanCMS.Api.Entities.SystemLog();

            entity.SystemLogUuid    = Guid.NewGuid();
            entity.UserId           = AuthContextService.CurrentUser.Guid.ToString();
            entity.UserName         = AuthContextService.CurrentUser.LoginName;
            entity.Type             = Typem;
            entity.OperationContent = Content;
            entity.OperationTime    = DateTime.Now;
            entity.AddTime          = DateTime.Now;
            entity.AddPeople        = "系统日志";
            entity.IsDelete         = 0;
            _dbContext.SystemLog.Add(entity);
            _dbContext.SaveChanges();
            return(messange);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 获取访问量
        /// </summary>
        /// <returns></returns>
        public IActionResult SetVisit()
        {
            using (_dbContext)
            {
                var response = ResponseModelFactory.CreateResultInstance;

                Visit model = new Visit();
                model.VisitUuid = Guid.NewGuid();
                model.AddTime   = DateTime.Now;
                _dbContext.Visit.Add(model);
                _dbContext.SaveChanges();
                var sysset   = _dbContext.SystemSetting.First();
                var ctime    = Convert.ToDateTime(sysset.CountTime);
                var date     = ctime.ToString("yyyy年MM月dd日");
                var datalist = _dbContext.Visit.Count();
                if (datalist > 0)
                {
                    datalist = _dbContext.Visit.Where(x => x.AddTime >= ctime).Count();
                }
                response.SetData(new { date, datalist });
                return(Ok(response));
            }
        }
Exemplo n.º 13
0
        public IActionResult Create(UserCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.LoginName.Trim().Length <= 0)
            {
                response.SetFailed("请输入登录名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.SystemUser.Count(x => x.LoginName == model.LoginName) > 0)
                {
                    response.SetFailed("登录名已存在");
                    return(Ok(response));
                }
                //if ((!string.IsNullOrEmpty(model.UserIdCard))&& _dbContext.SystemUser.Count(x => x.UserIdCard == model.UserIdCard) > 0)
                //{
                //    response.SetFailed("身份证号已存在");
                //    return Ok(response);
                //}
                if (string.IsNullOrEmpty(model.SystemRoleUuid))
                {
                    response.SetFailed("请选择角色");
                    return(Ok(response));
                }
                var entity = _mapper.Map <UserCreateViewModel, SystemUser>(model);
                entity.AddTime        = DateTime.Now.ToString("yyyy-MM-dd");
                entity.SystemUserUuid = Guid.NewGuid();

                var rolename = _dbContext.SystemRole.FirstOrDefault(x => x.RoleName == "超级管理员");
                if (model.SystemRoleUuid.Contains(rolename.SystemRoleUuid.ToString()))
                {
                    entity.UserType = 0;
                }
                else
                {
                    entity.UserType = 2;
                }
                entity.SystemRoleUuid = "";
                entity.PassWord       = Haikan3.Utils.DesEncrypt.Encrypt(model.PassWord.Trim(), MdDesEncrypt.SecretKey);
                //for (int i = 0; i < model.SystemRoleUuid.Count; i++)
                //{
                //    entity.SystemRoleUuid += model.SystemRoleUuid[i] + ",";
                //}
                entity.SystemRoleUuid = model.SystemRoleUuid;
                entity.SystemRoleUuid = entity.SystemRoleUuid.TrimEnd(',');
                //entity.OldCard = model.OldCard;
                entity.Phone            = model.Phone;
                entity.Sex              = model.Sex;
                entity.Placeofresidence = model.Placeofresidence;
                entity.Age              = model.Age;
                entity.Nickname         = model.Nickname;
                _dbContext.SystemUser.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:系统用户管理列表数据", _dbContext);
                }
                _dbContext.Database.ExecuteSqlRaw("DELETE FROM SystemUserRoleMapping WHERE SystemUserUUID={0}", entity.SystemUserUuid);
                var success = true;
                //循环加权限
                //for (int i = 0; i < model.SystemRoleUuid.Count; i++)
                //{
                //    if (model.SystemRoleUuid[i] != "")
                //    {
                //        var roles = new SystemUserRoleMapping();
                //        roles.SystemUserUuid = entity.SystemUserUuid;
                //        roles.SystemRoleUuid = Guid.Parse(model.SystemRoleUuid[i]);
                //        roles.AddTime = DateTime.Now.ToString("yyyy-MM-dd");
                //        roles.AddPeople = AuthContextService.CurrentUser.DisplayName;

                //        _dbContext.SystemUserRoleMapping.Add(roles);

                //    }
                //}
                //非循环加权
                var roles = new SystemUserRoleMapping();
                roles.SystemUserUuid = entity.SystemUserUuid;
                roles.SystemRoleUuid = Guid.Parse(model.SystemRoleUuid);
                roles.AddTime        = DateTime.Now.ToString("yyyy-MM-dd");
                roles.AddPeople      = AuthContextService.CurrentUser.DisplayName;
                _dbContext.SystemUserRoleMapping.Add(roles);

                success = _dbContext.SaveChanges() > 0;
                if (success)
                {
                    response.SetSuccess();
                }
                else
                {
                    _dbContext.Database.ExecuteSqlRaw("DELETE FROM SystemUser WHERE SystemUserUUID={0}", entity.SystemUserUuid);
                    response.SetFailed("保存用户角色数据失败");
                }
                return(Ok(response));
            }
        }
Exemplo n.º 14
0
        public IActionResult WXAuth(WXUserInfo info)
        {
            var        response = ResponseModelFactory.CreateInstance;
            SystemUser user     = new SystemUser();

            using (_dbContext)
            {
                var    entity  = _dbContext.SystemUser.FirstOrDefault(x => x.Wechat == info.Openid);
                string nowdate = DateTime.Now.ToString("yyyy-MM-dd");
                if (entity == null)
                {
                    user.SystemUserUuid = Guid.NewGuid();
                    user.LoginName      = info.NickName;
                    user.Nickname       = info.NickName;
                    user.RealName       = "";
                    user.Wechat         = info.Openid;
                    //授权登录的普通用户
                    user.UserType = 5;
                    user.AddTime  = DateTime.Now.ToString("yyyy-MM-dd");
                    if (info.Sex == 0)
                    {
                        user.Sex = "未知";
                    }
                    if (info.Sex == 1)
                    {
                        user.Sex = "男";
                    }
                    if (info.Sex == 2)
                    {
                        user.Sex = "女";
                    }
                    //user.Phone = info.Phone;
                    user.IsDeleted      = 0;
                    user.SystemRoleUuid = _dbContext.SystemRole.FirstOrDefault(x => x.RoleName == "微信用户").SystemRoleUuid.ToString();
                    _dbContext.SystemUser.Add(user);



                    //判断当天用户增加次数
                    //var ac = _dbContext.ActiveQuantity.FirstOrDefault(x => x.Type == 1 && x.AddTime== nowdate);
                    //if (ac == null)
                    //{
                    //    ac = new ActiveQuantity();
                    //    ac.ActiveQuantityUuid = Guid.NewGuid();
                    //    ac.AddTime = DateTime.Now.ToString("yyyy-MM-dd");
                    //    ac.Num = 1;
                    //    ac.Type = 1;
                    //    _dbContext.ActiveQuantity.Add(ac);
                    //}
                    //else
                    //{
                    //    ac.Num = ac.Num + 1;
                    //}
                }
                else
                {
                    entity.LoginName = info.NickName;
                    entity.IsDeleted = 0;

                    //判断当天用户登录次数
                    //var ac = _dbContext.ActiveQuantity.FirstOrDefault(x => x.Type == 2 && x.AddTime == nowdate);
                    //if(ac==null)
                    //{
                    //    ac = new ActiveQuantity();
                    //    ac.ActiveQuantityUuid = Guid.NewGuid();
                    //    ac.AddTime = DateTime.Now.ToString("yyyy-MM-dd");
                    //    ac.Num = 1;
                    //    ac.Type = 2;
                    //    _dbContext.ActiveQuantity.Add(ac);
                    //}
                    //else
                    //{
                    //    ac.Num = ac.Num + 1;
                    //}
                }

                _dbContext.SaveChanges();

                response.SetSuccess("授权成功");
                return(Ok(response));
            }
        }