Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task OnExceptionAsync(ExceptionContext context)
        {
            var    request = context.HttpContext.Request;
            string url     = request.Path + (request.QueryString.HasValue ? $"?{request.QueryString.Value}" : "");

            NLogger.Error("" + url + "\r\n" + context.Exception.Message + "\r\n" + context.Exception.StackTrace + "");
            //context.ExceptionHandled = true;
            ResultDto  Meta = ResultDto.Err();
            JsonResult json = new JsonResult(new
            {
                Meta
            }
                                             );
            JsonSerializerSettings jsetting = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };

            jsetting.Converters.Add(
                new Newtonsoft.Json.Converters.IsoDateTimeConverter()
            {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
            }
                );
            json.SerializerSettings = jsetting;
            json.ContentType        = "application/json; charset=utf-8";
            context.Result          = json;
            return(base.OnExceptionAsync(context));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var modelState = context.ModelState;

            if (!modelState.IsValid)
            {
                string error = string.Empty;
                foreach (var key in modelState.Keys)
                {
                    var state = modelState[key];
                    if (state.Errors.Any())
                    {
                        error = state.Errors.First().ErrorMessage;
                        break;
                    }
                }
                ResultDto  Meta = ResultDto.Err();
                JsonResult json = new JsonResult(new
                {
                    Meta
                }
                                                 );
                JsonSerializerSettings jsetting = new JsonSerializerSettings();
                jsetting.NullValueHandling = NullValueHandling.Ignore;
                jsetting.Converters.Add(
                    new Newtonsoft.Json.Converters.IsoDateTimeConverter()
                {
                    DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
                }
                    );
                json.SerializerSettings = jsetting;
                json.ContentType        = "application/json; charset=utf-8";
                context.Result          = json;
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(UserEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err(GetErrorFromModelStateStr())));
            }

            if (!string.IsNullOrWhiteSpace(model.Avatar))
            {
                if (model.Avatar.Contains("["))
                {
                    var saveUrl = IMGOperate.BaseSave(ImagePathType.员工头像, model.Avatar);
                    model.Avatar = saveUrl;
                }
            }

            var m = await UserApp.GetAsync(model.Id);

            if (m == null)
            {
                return(Json(ResultDto.Err("数据不存在或已被删除")));
            }

            m = model.MapToMeg <UserEditModel, User>(m);

            var r = await UserApp.UpdateUserInfoAsync(m, await CurrentUser());

            return(Json(r));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 删除管理人员
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <ResultDto> DeleteAsync(long Id, long agentId, CurrentUser curUser)
        {
            var r = await DeleteAsync(Id, agentId, curUser.Id);

            if (!string.IsNullOrEmpty(r.Error))
            {
                return(ResultDto.Err(msg: r.Error));
            }
            return(ResultDto.Suc());
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResultDto> DeleteAsync(long id)
        {
            if (await ModuleButtonRep.GetCountAsync(o => o.ParentId == id) > 0)
            {
                return(ResultDto.Err(msg: "删除失败!操作的对象包含了下级数据。"));
            }
            await ModuleButtonRep.DeleteAsync(o => o.Id == id);

            return(ResultDto.Suc());
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     if (context.HttpContext.Request != null && context.HttpContext.Request.Headers != null && context.HttpContext.Request.Headers["Authorization"].Count > 0)
     {
         var token = context.HttpContext.Request.Headers["Authorization"];
         if (string.IsNullOrWhiteSpace(token))
         {
             ResultDto  meta = ResultDto.Err("Unauthorized");
             JsonResult json = new JsonResult(new
             {
                 Meta = meta
             }
                                              );
             JsonSerializerSettings jsetting = new JsonSerializerSettings();
             jsetting.NullValueHandling = NullValueHandling.Ignore;
             jsetting.Converters.Add(
                 new Newtonsoft.Json.Converters.IsoDateTimeConverter()
             {
                 DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
             }
                 );
             json.SerializerSettings = jsetting;
             json.ContentType        = "application/json; charset=utf-8";
             context.Result          = json;
         }
         else
         {
             GenericIdentity ci = new GenericIdentity(token);
             ci.Label = "conan1111111";
             context.HttpContext.User = new GenericPrincipal(ci, null);
         }
     }
     else
     {
         ResultDto  meta = ResultDto.Err("Unauthorized");
         JsonResult json = new JsonResult(new
         {
             Meta = meta
         }
                                          );
         JsonSerializerSettings jsetting = new JsonSerializerSettings();
         jsetting.NullValueHandling = NullValueHandling.Ignore;
         jsetting.Converters.Add(
             new Newtonsoft.Json.Converters.IsoDateTimeConverter()
         {
             DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
         }
             );
         json.SerializerSettings = jsetting;
         json.ContentType        = "application/json; charset=utf-8";
         context.Result          = json;
     }
     base.OnActionExecuting(context);
 }
Exemplo n.º 7
0
        public async Task <IActionResult> ChangePassword(ChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err(GetErrorFromModelStateStr())));
            }
            var c = await CurrentUser();

            var r = await UserApp.ChangePasswordAsync(c.Id, model.Password, model.NewPassword, 0, c);

            return(Json(r));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResultDto> DeleteAsync(long id, CurrentUser currentUser)
        {
            var entity = await WebConfigAppRep.FindSingleAsync(o => o.Id == id);

            if (entity == null)
            {
                return(ResultDto.Err(msg: "数据不存在"));
            }
            await WebConfigAppRep.DeleteAsync(o => o.Id == id);

            return(ResultDto.Suc());
        }
Exemplo n.º 9
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResultDto> DeleteAsync(long id)
        {
            if (await DepartmentRep.GetCountAsync(o => o.ParentId == id) > 0)
            {
                return(ResultDto.Err(msg: "含有子部门不能删除"));
            }
            await DepartmentRep.DeleteAsync(o => o.Id == id);

            await RemoveCacheAsync();

            return(ResultDto.Suc());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create(ModuleModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err("数据验证失败")));
            }
            var module = model.MapTo <Module>();

            module.CreatorTime = DateTime.Now;
            var r = await ModuleApp.CreateAsync(module);

            return(Json(r));
        }
        public async Task <IActionResult> Create(ModuleButtonModel model, long moduleId, long parentId)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err("数据验证失败")));
            }
            var module = model.MapTo <ModuleButton>();

            module.ParentId = parentId;
            module.ModuleId = moduleId;
            var r = await ModuleButtonApp.CreateAsync(module);

            return(Json(r));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 添加管理人员
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <ResultDto> InsertAsync(User entity, CurrentUser curUser)
        {
            entity.UserSecretkey = "";
            entity.CreatorTime   = DateTime.Now;
            entity.CreatorUserId = curUser.Id;
            var r = await InsertAsync(entity);

            if (!string.IsNullOrEmpty(r.Error))
            {
                return(ResultDto.Err(msg: r.Error));
            }
            await OperateLogApp.InsertLogAsync <User>(curUser, "添加用户", entity);

            return(ResultDto.Suc());
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="moduleEntity"></param>
        /// <returns></returns>
        public async Task <ResultDto> UpdateAsync(Module moduleEntity)
        {
            moduleEntity.FullName   = moduleEntity.FullName?.Trim();
            moduleEntity.UrlAddress = moduleEntity.UrlAddress?.Trim();
            int count = await ModuleRep.GetCountAsync(o => o.FullName == moduleEntity.FullName && o.Id != moduleEntity.Id);

            if (count > 0)
            {
                return(ResultDto.Err(msg: moduleEntity.FullName + " 已存在"));
            }
            await ModuleRep.UpdateAsync(moduleEntity);

            await RemoveCacheAsync();

            return(ResultDto.Suc());
        }
Exemplo n.º 14
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entityDto"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResultDto <long> > CreateAsync(CreateWebConfigDto entityDto, CurrentUser currentUser)
        {
            var isExist = await WebConfigAppRep.Find(o => o.ConfigKey == entityDto.ConfigKey).AnyAsync();

            if (isExist)
            {
                return(ResultDto <long> .Err(msg : "key已存在"));
            }
            var dto = entityDto.MapTo <WebConfig>();

            dto.CreatorUserId = currentUser?.Id;
            dto.CreatorTime   = DateTime.Now;
            await WebConfigAppRep.AddAsync(dto);

            return(ResultDto <long> .Suc(dto.Id));
        }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="moduleEntity"></param>
        /// <returns></returns>
        public async Task <ResultDto> CreateAsync(ItemsData moduleEntity)
        {
            moduleEntity.Name    = moduleEntity.Name?.Trim();
            moduleEntity.Remarks = moduleEntity.Remarks?.Trim();
            int count = await ItemsDataRep.GetCountAsync(o => o.Name == moduleEntity.Name && o.ParentId == moduleEntity.ParentId);

            if (count > 0)
            {
                return(ResultDto.Err(msg: moduleEntity.Name + " 已存在"));
            }
            await ItemsDataRep.AddAsync(moduleEntity);

            await RemoveCacheAsync();

            return(ResultDto.Suc());
        }
Exemplo n.º 16
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="newPassword"></param>
        /// <param name="agentId"></param>
        /// <returns></returns>
        public async Task <ResultDto> ResetPasswordAsync(long Id, string password, long agentId, CurrentUser curUser)
        {
            User user = await UserRep.FindSingleAsync(o => o.Id == Id);

            if (user == null)
            {
                return(ResultDto.Err($"帐号({Id})不存在"));
            }
            password = MD5Encrypt.MD5(password);
            await UserRep.UpdateAsync(o => o.Id == Id, o => new User()
            {
                Password = password
            });

            return(ResultDto.Suc());
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Edit(ItemsDataModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err(GetErrorFromModelStateStr())));
            }
            var m = await ItemsDataApp.GetAsync(model.Id);

            if (m == null)
            {
                return(Json(ResultDto.Err("数据不存在或已被删除")));
            }
            m = model.MapToMeg <ItemsDataModel, ItemsData>(m);
            var r = await ItemsDataApp.UpdateAsync(m);

            return(Json(r));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="moduleEntity"></param>
        /// <returns></returns>
        public async Task <ResultDto> CreateAsync(Department moduleEntity)
        {
            moduleEntity.Name          = moduleEntity.Name?.Trim();
            moduleEntity.Code          = moduleEntity.Code?.Trim();
            moduleEntity.ContactNumber = moduleEntity.ContactNumber?.Trim();
            moduleEntity.Remarks       = moduleEntity.Remarks?.Trim();
            int count = await DepartmentRep.GetCountAsync(o => o.Code == moduleEntity.Code);

            if (count > 0)
            {
                return(ResultDto.Err(msg: moduleEntity.Code + " 已存在"));
            }
            await DepartmentRep.AddAsync(moduleEntity);

            await RemoveCacheAsync();

            return(ResultDto.Suc());
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Create(UserCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ResultDto.Err("数据验证失败;" + GetErrorFromModelStateStr())));
            }
            var user = model.MapTo <User>();

            user.Password = CompanyName.ProjectName.Core.Security.MD5Encrypt.MD5(user.Password);
            if (!string.IsNullOrWhiteSpace(user.Avatar))
            {
                var saveUrl = IMGOperate.BaseSave(ImagePathType.员工头像, user.Avatar);
                user.Avatar = saveUrl;
            }
            var r = await UserApp.InsertAsync(user, await CurrentUser());

            return(Json(r));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entityDto"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResultDto> UpdateAsync(UpdateWebConfigDto entityDto, CurrentUser currentUser)
        {
            var entity = await WebConfigAppRep.FindSingleAsync(o => o.Id == entityDto.Id);

            if (entity == null)
            {
                return(ResultDto.Err(msg: "数据不存在"));
            }
            var isExist = await WebConfigAppRep.Find(o => o.ConfigKey == entityDto.ConfigKey && o.Id != entityDto.Id).AnyAsync();

            if (isExist)
            {
                return(ResultDto.Err("key已存在"));
            }
            var dto = entityDto.MapToMeg <UpdateWebConfigDto, WebConfig>(entity);
            await WebConfigAppRep.UpdateAsync(dto);

            return(ResultDto.Suc());
        }
Exemplo n.º 21
0
        /// <summary>
        /// 修改登录状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="agentId"></param>
        /// <param name="curUser"></param>
        /// <returns></returns>
        public async Task <ResultDto> Updatestatus(long Id, CurrentUser curUser)
        {
            var entry = await GetAsync(Id);

            if (entry == null)
            {
                return(ResultDto.Err(msg: "该用户不存在"));
            }
            int s = 1;

            if (entry.State == 1)
            {
                s = 0;
            }
            await UserRep.UpdateAsync(u => u.Id == Id, u => new User {
                State = s
            });

            return(ResultDto.Suc());
        }
Exemplo n.º 22
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="password">旧密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns></returns>
        public async Task <ResultDto> ChangePasswordAsync(long Id, string password, string newPassword, long agentId, CurrentUser curUser)
        {
            User user = await UserRep.FindSingleAsync(o => o.Id == Id);

            if (user == null || user.DeleteMark == true)
            {
                return(ResultDto.Err($"帐号({Id})不存在"));
            }
            if (user.Password != MD5Encrypt.MD5(password))
            {
                return(ResultDto.Err($"原密码不正确"));
            }
            newPassword = MD5Encrypt.MD5(newPassword);
            await UserRep.UpdateAsync(o => o.Id == Id, o => new User()
            {
                Password = newPassword
            });

            return(ResultDto.Suc());
        }
Exemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResultDto> DeleteAsync(long id)
        {
            if (await ModuleRep.GetCountAsync(o => o.ParentId == id) > 0)
            {
                return(ResultDto.Err("含有子菜单不能删除"));
            }
            try
            {
                UnitWork.Delete <Module>(o => o.Id == id);
                UnitWork.Delete <ModuleButton>(o => o.ModuleId == id);
                UnitWork.Save();
            }
            catch (Exception exc)
            {
                return(ResultDto.Err(exc.Message));
            }
            await RemoveCacheAsync();

            return(ResultDto.Suc());
        }
Exemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResultDto <WebConfigDto> > GetDetailAsync(long id)
        {
            var entity = await WebConfigAppRep.FindSingleAsync(o => o.Id == id);

            return(entity == null ? ResultDto <WebConfigDto> .Err(msg : "数据不存在") : ResultDto <WebConfigDto> .Suc(entity.MapTo <WebConfigDto>()));
        }