public ActionResult AuditUserProduct(Audit.UserProductAuditDto dto)
        => TryTransaction(db =>
        {
            var product = _zdDBContext.UserProduct.FirstOrDefault(x => x.Id == dto.ID);
            if (product == null)
            {
                return(ActionResult.Bad("未查询到产品信息"));
            }
            var preStatus  = product.Status;
            product.Status = dto.Status;

            db.AuditRecord.Add(new AuditRecord
            {
                AuditId   = product.Id.ToString(),
                AuditType = (int)AuditType.Product,
                AuditDate = DateTime.Now,
                AuditorId = _loginUserProvider.GetUserID(),
                Remark    = dto.AuditRemark,
                PreStatus = preStatus,
                ToStatus  = product.Status
            });
            if (db.SaveChanges() <= 0)
            {
                return(ActionResult.Bad("审核更新数据失败"));
            }
            return(ActionResult.Ok());
        });
Esempio n. 2
0
        //文章审核
        public ActionResult AuditUserArticle(Audit.UserArticleAuditDto dto)
        => TryTransaction(db =>
        {
            var article = _zdDBContext.UserArticle.FirstOrDefault(x => x.Id == dto.ID);                          // 根据ID查询数据是否存在
            if (article == null)
            {
                return(ActionResult.Bad("数据不存在"));                                                           // 不存在返回信息
            }
            var preStatus  = article.Status;                                                                 //获取原本状态
            article.IsHot  = dto.IsHot;                                                                      // 是否推送热门
            article.Status = dto.Status;                                                                     // 更改状态

            db.AuditRecord.Add(new AuditRecord
            {
                AuditId   = article.Id.ToString(),
                AuditType = (int)AuditType.Article,
                AuditDate = DateTime.Now,
                AuditorId = _loginUserProvider.GetUserID(),
                Remark    = dto.Remark,
                PreStatus = preStatus,
                ToStatus  = dto.Status
            });
            if (db.SaveChanges() <= 0)
            {
                return(ActionResult.Bad("审核失败,请重新审核"));                                //提交失败返回信息
            }
            return(ActionResult.Ok());
        });
Esempio n. 3
0
 public ActionResult CreateFeedBack(CreateFeedBackDto dto)
 => TryCatch(db =>
 {
     var userInfo = _zdDBContext.UserInfo.FirstOrDefault(x => x.UserName == dto.Name.Trim());
     if (userInfo == null)
     {
         return(ActionResult.Bad("用户不存在"));
     }
     db.UserReport.Add(new UserReport
     {
         ReportUserId = userInfo.UserId,
         UserId       = userInfo.UserId,
         Contact      = dto.Contact,
         CreateDate   = dto.CreateDate,    //DateTime.Now,
         UpdateDate   = dto.CreateDate,
         Reason       = dto.Reason,
         Photos       = dto.Photos,
         ReportType   = 0.ToString(),
         SourceType   = 1.ToString(),
     });
     if (db.SaveChanges() < 0)
     {
         return(ActionResult.Bad("录入失败"));
     }
     return(ActionResult.Ok("录入成功"));
 });
 //修改密码
 public ActionResult ChangePassword(System.ChangePasswordDto dto)
 => TryTransaction(db =>
 {
     var userID    = _httpContext?.User?.Claims.FirstOrDefault(x => x.Type.Equals("UserID"))?.Value;
     var changePwd = _zdDBContext.SystemOperator.FirstOrDefault(x => x.OperatorId == userID && Hash.Validate(dto.Password, x.Password));
     if (changePwd == null)
     {
         return(ActionResult.Bad("密码错误"));
     }
     if (dto.FirstPassword != dto.LastPassword)
     {
         return(ActionResult.Bad("两次输入不一样"));
     }
     else if (dto.Password == dto.FirstPassword)
     {
         return(ActionResult.Bad("不能与原密码相同"));
     }
     else
     {
         changePwd.Password = Hash.Create(dto.FirstPassword);
     }
     if (db.SaveChanges() <= 0)
     {
         return(ActionResult.Bad("修改失败"));
     }
     return(ActionResult.Ok());
 });
        public ActionResult AssignPermission(System.AssignPermissionDto dto)
        => TryTransaction(db =>
        {
            var role = db.SystemRoles.Find(dto.RoleID);
            if (role == null)
            {
                return(ActionResult.Bad("角色不存在!"));
            }

            var beforePermission = db.SystemAuthorization.Where(x => x.RoleId == dto.RoleID);
            if (beforePermission != null)
            {
                db.SystemAuthorization.RemoveRange(beforePermission);
            }

            foreach (var id in dto.PermissionIDs)
            {
                db.SystemAuthorization.Add(new SystemAuthorization
                {
                    RoleId       = dto.RoleID,
                    PermissionId = id
                });
            }
            var effectRows = db.SaveChanges();
            return(ActionResult.Ok(effectRows));
        });
        public ActionResult AssignRoles(System.AssignRolesDto dto)
        => TryTransaction(db =>
        {
            var op = base.Get(x => x.OperatorId == dto.OperatorID);
            if (op == null)
            {
                return(ActionResult.Bad("操作员不存在!"));
            }

            var beforeRoles = db.SystemOperatorRole.Where(x => x.Operator == dto.OperatorID);
            if (beforeRoles != null)
            {
                db.SystemOperatorRole.RemoveRange(beforeRoles);
            }

            foreach (var roleID in dto.RoleIDs)
            {
                db.SystemOperatorRole.Add(new SystemOperatorRole
                {
                    Role     = roleID,
                    Operator = dto.OperatorID
                });
            }
            var effectRows = db.SaveChanges();
            return(ActionResult.Ok(effectRows));
        });
Esempio n. 7
0
 public ActionResult DBResult(Func <int> func)
 {
     if (func() > 0)
     {
         return(ActionResult.Ok());
     }
     return(ActionResult.Bad());
 }
        public ActionResult AuditUserIDcard(Audit.UserIDCardAuditDto model)
        => TryTransaction(db =>
        {
            var card = db.UserIdcard.Single(x => x.UserId == model.UserID);
            if (card == null)
            {
                return(ActionResult.Bad("未查询到身份证信息"));
            }
            var preStatus = card.Status;
            card.Status   = model.Status;
            // 审核通过
            if (card.Status == (int)AuditStatus.Pass)
            {
                //card.Gender = model.Gender;
                //card.Nation = model.Nation;
                //card.Address = model.Address;
                //card.Birthday = model.Birthday;
                card.UserName          = model.UserName;
                card.IdcardNo          = model.IdCardNbr;
                card.IssuingAgency     = model.IssuingAgency;
                card.ValidityEndTime   = model.ValidityEndTime;
                card.ValidityStartTime = model.ValidityStartTime;
                card.UpdateTime        = DateTime.Now;
            }
            else
            {
                card.Remark = model.Remark;
            }

            db.AuditRecord.Add(new AuditRecord
            {
                AuditId   = card.UserId.ToString(),
                AuditType = AuditType.IDCard.ToValue(),
                AuditDate = DateTime.Now,
                AuditorId = _loginUserProvider.GetUserID(),
                Remark    = card.Remark,
                PreStatus = (int)preStatus,
                ToStatus  = (int)card.Status
            });

            var userInfo          = db.UserInfo.Single(x => x.UserId == card.UserId);
            userInfo.IdentityAuth = model.Status;

            if (db.SaveChanges() <= 0)
            {
                return(ActionResult.Bad("审核更新数据失败"));
            }

            // 更新Redis用户缓存
            _zdUserCacheService.AddUserCacheAsync(userInfo.Map <GlobalUserInfo>());

            if (!_neo4JBase.UpdateSingleNode("Person", userInfo))
            {
                throw new Exception("图形数据库更新失败");
            }

            return(ActionResult.Ok("审核成功"));
        });
Esempio n. 9
0
 protected JsonResult JsonResultTryCatch <T>(Func <T> func) where T : JsonResult
 {
     try
     {
         return(func());
     }
     catch (Exception ex)
     {
         return(new JsonResult(ActionResult.Bad(ex.Message)));
     }
 }
Esempio n. 10
0
 protected IActionResult TryCatchR <T>(Func <T> func) where T : class
 {
     try
     {
         return(new OkObjectResult(func()));
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ActionResult.Bad(ex.Message)));
     }
 }
Esempio n. 11
0
 protected IActionResult TryCatch(Action action)
 {
     try
     {
         action();
         return(new OkObjectResult(ActionResult.Ok()));
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ActionResult.Bad(ex.Message)));
     }
 }
Esempio n. 12
0
        protected IActionResult OnAction <T>(T model, Func <T, ActionResult> func) where T : class, new()
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("数据异常")));
            }
            var result = func(model);

            if (result.IsSuccess)
            {
                return(new OkObjectResult(result));
            }
            return(new BadRequestObjectResult(result));
        }
Esempio n. 13
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("数据异常")));
            }
            var op = await _loginUserProvider.Login(model.UserName, model.Password);

            if (op == null)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("账户名或密码错误")));
            }
            return(new OkObjectResult(ActionResult.Ok(new { op.Name, roles = op.RoleNames.ToArray() })));
        }
Esempio n. 14
0
        public ActionResult UpdateMomentsTags(UpdateMomentsDto model)
        {
            var filter = Builders <Moments> .Filter.Eq(x => x.Id, model.Id);

            var update = Builders <Moments> .Update.Set(x => x.Tags, model.TagsString);

            var result = _mongoDBBase.UpdateManay <Moments>(colName, filter, update);
            var tags   = _tagLibraryRepo.TagSynchronization(model.Tags.ToArray(), TagCategory.Moment.ToValue(), model.Id);

            if (result.ModifiedCount > 0)
            {
                return(ActionResult.Ok());
            }
            return(ActionResult.Bad("添加失败"));
        }
Esempio n. 15
0
 /*新增角色*/
 public ActionResult CreateRole(string name, string description)
 => TryCatch(db =>
 {
     var role = _zdDBContext.SystemRoles.FirstOrDefault(x => x.RoleName == name.Trim());
     //var role = base.Get(r => r.Name == name.Trim());
     if (role != null)
     {
         return(ActionResult.Bad("角色已存在"));
     }
     db.LoadStoredProc("dbo.CreateRole")
     .AddParam("name", name)
     .AddParam("description", description)
     .ExecNonQuery();
     return(ActionResult.Of(true));
 });
Esempio n. 16
0
 /*开启角色状态 */
 public ActionResult IsEnableRole(System.IsEnableDto dto)
 => TryCatch(db =>
 {
     var role = _zdDBContext.SystemRoles.FirstOrDefault(x => x.RoleId == dto.Id);
     if (role == null)
     {
         return(ActionResult.Bad("角色不存在"));
     }
     role.Status = dto.Status == 0 ? 1 : 0;
     if (db.SaveChanges() <= 0)
     {
         return(ActionResult.Bad("数据异常"));
     }
     return(ActionResult.Of(true));
 });
Esempio n. 17
0
        /// T: ViewModel
        /// R: DTO
        /// func: 增删改的仓储接口方法
        protected IActionResult OnAction <T, R>(T model, Func <R, ActionResult> func) where T : class, new() where R : class, new()
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("数据异常")));
            }
            var auditDto = model.MapTo <T, R>();
            var result   = func(auditDto);

            if (result.IsSuccess)
            {
                return(new OkObjectResult(result));
            }
            return(new BadRequestObjectResult(result));
        }
Esempio n. 18
0
        public ActionResult AuditUserCareer(Audit.UserCareerAuditDto dto)
        => TryTransaction((db) =>
        {
            var career = db.UserCareer.FirstOrDefault(x => x.Id == dto.ID);
            if (career == null)
            {
                return(ActionResult.Bad("未匹配到名片信息"));
            }

            var preStatus = career.Status;
            career.Status = dto.Status;
            career.Remark = dto.Remark;

            var userInfo        = db.UserInfo.FirstOrDefault(x => x.UserId == career.UserId);
            userInfo.CareerAuth = dto.Status;
            userInfo.CareerType = dto.CareerType;

            db.AuditRecord.Add(new AuditRecord
            {
                AuditId   = career.Id.ToString(),
                AuditType = (int)AuditType.Career,
                AuditDate = DateTime.Now,
                AuditorId = _loginUserProvider.GetUserID(),
                Remark    = career.Remark,
                PreStatus = preStatus,
                ToStatus  = career.Status
            });

            if (db.SaveChanges() <= 0)
            {
                return(ActionResult.Bad("审核失败"));
            }

            // 更新Redis用户缓存
            _zdUserCacheService.AddUserCacheAsync(userInfo.Map <GlobalUserInfo>());

            if (!_neo4JBase.UpdateSingleNode("Person", userInfo))
            {
                throw new Exception("图形数据库更新失败");
            }

            return(ActionResult.Ok(true));
        });
Esempio n. 19
0
        public ActionResult DeleteMoment(DeleteMomentsDto model)
        {
            var moment = _mongoDBBase.FindOne <Moments>(colName, model.Id, true, MGExt.GetModelFields <Moments>(typeof(Moments.UserInfo)).ToArray());
            var result = _mongoDBBase.Delete <Moments>(colName, model.Id);
            var filter = Builders <Timelines> .Filter.Eq("Moments.MomentId", model.Id);

            var update = Builders <Timelines> .Update.PullFilter(s => s.Moments, r => r.MomentId == model.Id);

            var timeLines = _mongoDBBase.UpdateManay <Timelines>("TimeLines", filter, update);

            _mongoDBBase.GetClient <Backups>("Backups").InsertOne(new Backups {
                JsonItem = JsonConvert.SerializeObject(moment), Remark = model.Remark
            });
            if (result.DeletedCount > 0)
            {
                return(ActionResult.Ok());
            }
            return(ActionResult.Bad("删除失败"));
        }
Esempio n. 20
0
        public IActionResult Authenticate([FromBody] LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("数据异常")));
            }
            var op = _loginUserProvider.Authenticate(model.UserName, model.Password);

            if (op == null)
            {
                return(new BadRequestObjectResult(ActionResult.Bad("账户名或密码错误")));
            }
            return(new OkObjectResult(ActionResult.Ok(new
            {
                access_token = op.Token,
                token_type = "Bearer",
                name = op.Name
            })));
        }
 public ActionResult ProductAddTags(Audit.UserProductAuditDto dto)
 => TryTransaction(db =>
 {
     var product = _zdDBContext.UserProduct.FirstOrDefault(x => x.Id == dto.ID);
     if (product == null)
     {
         return(ActionResult.Bad("未查询到产品信息"));
     }
     product.Tags = string.Join(" ", dto.Tags);
     if (UpdateResult(product) <= 0)
     {
         return(ActionResult.Bad("标签添加失败"));
     }
     // 审核通过才同步mongoDB的标签库
     if (product.Status == (int)AuditStatus.Pass && dto.Tags.Count > 0)
     {
         _tagLibraryRepo.TagSynchronization(dto.Tags.ToArray(), (int)TagCategory.Product, dto.ID.ToString());
     }
     return(ActionResult.Ok());
 });
Esempio n. 22
0
 //添加标签
 public ActionResult ArticleAddTags(Audit.UserArticleAuditDto dto)
 => TryTransaction(db =>
 {
     var article = _zdDBContext.UserArticle.FirstOrDefault(x => x.Id == dto.ID);
     if (article == null)
     {
         return(ActionResult.Bad("数据不存在"));
     }
     article.Tags = string.Join(" ", dto.Tags);
     if (UpdateResult(article) <= 0)
     {
         return(ActionResult.Bad("添加标签失败"));
     }
     // 审核通过才同步mongoDB的标签库
     if (article.Status == (int)AuditStatus.Pass && dto.Tags.Count > 0)
     {
         _tagLibraryRepo.TagSynchronization(dto.Tags.ToArray(), (int)TagCategory.Article, dto.ID.ToString());
     }
     return(ActionResult.Ok());
 });
Esempio n. 23
0
        public ActionResult CreateOperator(string name)
        => TryCatch(db =>
        {
            var op = base.Get(o => o.Name == name.Trim());
            if (op != null)
            {
                return(ActionResult.Bad("登录名已存在!"));
            }

            db.LoadStoredProc("dbo.NewPassword")
            .AddParam("password", out IOutParam <string> outParam, new ParamExtra()
            {
                Size = 20
            })
            .ExecNonQuery();
            var password = outParam.Value;

            db.LoadStoredProc("dbo.CreateOperator")
            .AddParam("name", name)
            .AddParam("password", Hash.Create(password))
            .ExecNonQuery();

            return(ActionResult.Ok(password));
        });