private async Task <TResponse <bool> > CanUpdate(UpdateTaskLoopModel request)
        {
            try
            {
                var taskLoop = await _taskLoopCacheService.GetByName(request.Name);

                if (taskLoop != null &&
                    taskLoop.Id != request.Id)
                {
                    return(await Fail <bool>(ErrorEnum.TASK_LOOP_HAS_EXIST.GetStringValue()));
                }

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Beispiel #2
0
 public async Task <ActionResult <bool> > Update(UpdateTaskLoopModel request)
 {
     return(Ok(await _taskLoopService.Update(await GetUserId(),
                                             request,
                                             GetPermissionId())));
 }
        public async Task <TResponse <bool> > Update(int userId,
                                                     UpdateTaskLoopModel request,
                                                     int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var canUpdate = await CanUpdate(request);

                    if (canUpdate.IsSuccess)
                    {
                        var result = await WriteRepository.ExecuteAsync(SqlQuery.TASK_LOOP_UPDATE,
                                                                        new
                        {
                            request.Id,
                            request.Name,
                            request.DayCount,
                            request.SortOrder,
                            UserUpdated = userId,
                            DateUpdated = DateTime.Now
                        });

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

                                await _taskLoopCacheService.AddOrUpdate(new TaskLoopCacheModel
                                {
                                    Id        = request.Id,
                                    Name      = request.Name,
                                    DayCount  = request.DayCount,
                                    SortOrder = request.SortOrder
                                });

                                #endregion

                                return(await Ok(true));
                            }

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

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

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

                return(await Fail <bool>(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }