Beispiel #1
0
        public async Task <TResponse <bool> > CanInsert(InsertRoleGroupReq roleGroup)
        {
            try
            {
                var roleGroups = await _readOnlyRepository.QueryAsync <RoleGroup>(SqlQuery.ROLE_GROUP_FIND_BY_NAME,
                                                                                  new
                {
                    roleGroup.Name
                });

                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));
            }
        }
Beispiel #2
0
        public async Task <TResponse <bool> > Add(int userId,
                                                  InsertRoleGroupReq roleGroup)
        {
            try
            {
                var canInsert = await CanInsert(roleGroup);

                if (canInsert.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.ROLE_GROUP_INSERT, new
                    {
                        roleGroup.Name,
                        UserCreated = userId,
                        DateCreated = DateTime.Now,
                        UserUpdated = userId,
                        DateUpdated = DateTime.Now
                    });

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

                            return(await Ok(true));
                        }

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

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

                return(await Fail <bool>(canInsert.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
 public async Task <ActionResult <int> > Add(InsertRoleGroupReq req)
 {
     return(Ok(await _roleGroupService.Add(UserId,
                                           req)));
 }