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

            if (string.IsNullOrEmpty(model.SecurityName) || string.IsNullOrEmpty(model.IdentityCard
                                                                                 ))
            {
                response.SetFailed("请输入名称和身份证号");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.Security.Any(x => x.IdentityCard == model.IdentityCard && x.IsDeleted == 0))
                {
                    response.SetFailed("角色已存在");
                    return(Ok(response));
                }
                var entity = new Security()
                {
                    SecurityUuid = Guid.NewGuid(),
                    SecurityName = model.SecurityName,
                    AddPeople    = AuthContextService.CurrentUser.DisplayName,
                    AddTime      = DateTime.Now.ToString("yyyy-MM-dd"),
                    IsDeleted    = 0,
                    Phone        = model.Phone,
                    SecurityTime
                                   = model.SecurityTime == ""?null : Convert.ToDateTime(model.SecurityTime).ToString("yyyy-MM-dd"),
                    SecurityStaues = model.SecurityStaues,
                    IdentityCard
                                    = model.IdentityCard.Trim(),
                    SecurityAddress = model.SecurityAddress,
                };
                _dbContext.Security.Add(entity);
                var num = _dbContext.SaveChanges();
                if (num > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:安防人员信息一条数据", _dbContext);
                    response.SetSuccess();
                }
                else
                {
                    response.SetFailed("添加失败");
                }
                return(Ok(response));
            }
        }
Exemplo n.º 2
0
        public IActionResult Edit(SecurityPViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = _dbContext.Security.FirstOrDefault(x => x.SecurityUuid == model.SecurityUuid && x.IsDeleted == 0);
                if (entity == null)
                {
                    response.SetFailed("该人员不存在");
                    return(Ok(response));
                }
                if (entity.IdentityCard != model.IdentityCard && _dbContext.Security.Any(x => x.IdentityCard == model.IdentityCard && x.IsDeleted == 0))
                {
                    response.SetFailed("该身份证号已存在");
                    return(Ok(response));
                }

                entity.SecurityName    = model.SecurityName;
                entity.SecurityAddress = model.SecurityAddress;
                entity.IdentityCard    = model.IdentityCard;
                entity.Phone           = model.Phone;
                entity.SecurityTime    = model.SecurityTime == null? null : model.SecurityTime == ""?null: Convert.ToDateTime(model.SecurityTime).ToString("yyyy-MM-dd");
                entity.SecurityStaues  = model.SecurityStaues;


                var success = _dbContext.SaveChanges() > 0;
                if (success)
                {
                    ToLog.AddLog("编辑", "成功:编辑:安防人员信息一条数据", _dbContext);
                    response.SetSuccess();
                }
                else
                {
                    response.SetFailed("保存失败");
                }
                response = ResponseModelFactory.CreateInstance;
                return(Ok(response));
            }
        }