예제 #1
0
        public async Task <TResponse <bool> > CanUpdate(UpdateRoleGroupReq roleGroup)
        {
            try
            {
                var roleGroups = await _readOnlyRepository.QueryAsync <RoleGroup>(
                    SqlQuery.ROLE_GROUP_FIND_BY_NAME_AND_ID,
                    new
                {
                    roleGroup.Name,
                    roleGroup.Id
                });

                if (roleGroups != null)
                {
                    if (roleGroups.IsSuccess)
                    {
                        if (roleGroups.Data.Any())
                        {
                            return(await Fail <bool>(ErrorEnum.RoleGroupNameHasExist.GetStringValue()));
                        }

                        return(await Ok(true));
                    }

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

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
예제 #2
0
        public async Task <TResponse <bool> > Update(int userId,
                                                     UpdateRoleGroupReq roleGroup)
        {
            try
            {
                var canUpdate = await CanUpdate(roleGroup);

                if (canUpdate.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.ROLE_GROUP_UPDATE, new
                    {
                        roleGroup.Id,
                        roleGroup.Name,
                        UserUpdated = userId,
                        DateUpdated = DateTime.Now
                    });

                    if (result != null)
                    {
                        if (result.IsSuccess)
                        {
                            if (result.Data == 0)
                            {
                                return(await Fail <bool>($"Update ROLE_GROUP {roleGroup.Id} is failure"));
                            }

                            return(await Ok(true));
                        }

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

                    return(await Fail <bool>($"Update ROLE_GROUP {roleGroup.Id} is failure"));
                }

                return(await Fail <bool>(canUpdate.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
예제 #3
0
 public async Task <ActionResult <int> > Update(UpdateRoleGroupReq req)
 {
     return(Ok(await _roleGroupService.Update(UserId,
                                              req)));
 }