コード例 #1
0
        private async Task <TResponse <bool> > CanInsert(InsertAppConfigModel request)
        {
            try
            {
                var appConfig = await _appConfigCacheService.GetByName(request.Name);

                if (appConfig != null)
                {
                    return(await Fail <bool>(ErrorEnum.APP_CONFIG_HAS_EXIST.GetStringValue()));
                }

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Add(InsertAppConfigModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _appConfigService.Insert(_mapper.Map <InsertAppConfigModel, InsertAppConfigRequest>(model));

                if (result.IsSuccess)
                {
                    TempData["Update"] = result.ToJson();
                    return(RedirectToAction("Index",
                                            "AppConfig"));
                }

                ModelState.AddModelError("",
                                         result.Message);
            }

            return(View(model));
        }
コード例 #3
0
        public async Task <TResponse <bool> > Add(int userId,
                                                  InsertAppConfigModel request,
                                                  int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var canInsert = await CanInsert(request);

                    if (canInsert.IsSuccess)
                    {
                        var result = await WriteRepository.ExecuteScalarAsync <int>(SqlQuery.APP_CONFIG_INSERT,
                                                                                    new
                        {
                            request.Name,
                            request.Value,
                            request.Description,
                            UserCreated = userId,
                            DateCreated = DateTime.Now,
                            UserUpdated = userId,
                            DateUpdated = DateTime.Now
                        });

                        if (result.IsSuccess)
                        {
                            if (result.Data > 0)
                            {
                                #region Update redis cache

                                await _appConfigCacheService.AddOrUpdate(new AppConfigCacheModel
                                {
                                    Id          = result.Data,
                                    Name        = request.Name,
                                    Value       = request.Value,
                                    Description = request.Description
                                });

                                #endregion

                                return(await Ok(true));
                            }

                            return(await Fail <bool>(ErrorEnum.BAD_REQUEST.GetStringValue()));
                        }

                        return(await Fail <bool>(result.Message));
                    }

                    return(await Fail <bool>(canInsert.Message));
                }

                return(await Fail <bool>(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
コード例 #4
0
 public async Task <ActionResult <bool> > Add(InsertAppConfigModel request)
 {
     return(Ok(await _appConfigService.Add(await GetUserId(),
                                           request,
                                           GetPermissionId())));
 }