Esempio n. 1
0
        public async Task <ActionResult <AppUser_AppUserDTO> > UpdateRole([FromBody] AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            if (!await HasPermission(AppUser_AppUserDTO.Id))
            {
                return(Forbid());
            }

            AppUser AppUser = ConvertDTOToEntity(AppUser_AppUserDTO);

            AppUser = await AppUserService.UpdateRole(AppUser);

            AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);
            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <AppUser_AppUserDTO> > Get([FromBody] AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            if (!await HasPermission(AppUser_AppUserDTO.Id))
            {
                return(Forbid());
            }

            AppUser AppUser = await AppUserService.Get(AppUser_AppUserDTO.Id);

            return(new AppUser_AppUserDTO(AppUser));
        }
Esempio n. 3
0
        private AppUser ConvertDTOToEntity(AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            AppUser AppUser = new AppUser();

            AppUser.Id             = AppUser_AppUserDTO.Id;
            AppUser.Username       = AppUser_AppUserDTO.Username;
            AppUser.DisplayName    = AppUser_AppUserDTO.DisplayName;
            AppUser.Address        = AppUser_AppUserDTO.Address;
            AppUser.Avatar         = AppUser_AppUserDTO.Avatar;
            AppUser.Birthday       = AppUser_AppUserDTO.Birthday;
            AppUser.Email          = AppUser_AppUserDTO.Email;
            AppUser.Phone          = AppUser_AppUserDTO.Phone;
            AppUser.PositionId     = AppUser_AppUserDTO.PositionId;
            AppUser.Department     = AppUser_AppUserDTO.Department;
            AppUser.OrganizationId = AppUser_AppUserDTO.OrganizationId;
            AppUser.ERouteScopeId  = AppUser_AppUserDTO.ERouteScopeId;
            AppUser.ProvinceId     = AppUser_AppUserDTO.ProvinceId;
            AppUser.SexId          = AppUser_AppUserDTO.SexId;
            AppUser.StatusId       = AppUser_AppUserDTO.StatusId;
            AppUser.Organization   = AppUser_AppUserDTO.Organization == null ? null : new Organization
            {
                Id       = AppUser_AppUserDTO.Organization.Id,
                Code     = AppUser_AppUserDTO.Organization.Code,
                Name     = AppUser_AppUserDTO.Organization.Name,
                ParentId = AppUser_AppUserDTO.Organization.ParentId,
                Path     = AppUser_AppUserDTO.Organization.Path,
                Level    = AppUser_AppUserDTO.Organization.Level,
                StatusId = AppUser_AppUserDTO.Organization.StatusId,
                Phone    = AppUser_AppUserDTO.Organization.Phone,
                Address  = AppUser_AppUserDTO.Organization.Address,
                Email    = AppUser_AppUserDTO.Organization.Email,
            };
            AppUser.ERouteScope = AppUser_AppUserDTO.ERouteScope == null ? null : new Organization
            {
                Id       = AppUser_AppUserDTO.ERouteScope.Id,
                Code     = AppUser_AppUserDTO.ERouteScope.Code,
                Name     = AppUser_AppUserDTO.ERouteScope.Name,
                ParentId = AppUser_AppUserDTO.ERouteScope.ParentId,
                Path     = AppUser_AppUserDTO.ERouteScope.Path,
                Level    = AppUser_AppUserDTO.ERouteScope.Level,
                StatusId = AppUser_AppUserDTO.ERouteScope.StatusId,
                Phone    = AppUser_AppUserDTO.ERouteScope.Phone,
                Address  = AppUser_AppUserDTO.ERouteScope.Address,
                Email    = AppUser_AppUserDTO.ERouteScope.Email,
            };
            AppUser.Province = AppUser_AppUserDTO.Province == null ? null : new Province
            {
                Id       = AppUser_AppUserDTO.Province.Id,
                Code     = AppUser_AppUserDTO.Province.Code,
                Name     = AppUser_AppUserDTO.Province.Name,
                Priority = AppUser_AppUserDTO.Province.Priority,
                StatusId = AppUser_AppUserDTO.Province.StatusId,
            };
            AppUser.Sex = AppUser_AppUserDTO.Sex == null ? null : new Sex
            {
                Id   = AppUser_AppUserDTO.Sex.Id,
                Code = AppUser_AppUserDTO.Sex.Code,
                Name = AppUser_AppUserDTO.Sex.Name,
            };
            AppUser.Status = AppUser_AppUserDTO.Status == null ? null : new Status
            {
                Id   = AppUser_AppUserDTO.Status.Id,
                Code = AppUser_AppUserDTO.Status.Code,
                Name = AppUser_AppUserDTO.Status.Name,
            };
            AppUser.AppUserRoleMappings = AppUser_AppUserDTO.AppUserRoleMappings?
                                          .Select(x => new AppUserRoleMapping
            {
                RoleId = x.RoleId,
                Role   = x.Role == null ? null : new Role
                {
                    Id       = x.Role.Id,
                    Code     = x.Role.Code,
                    Name     = x.Role.Name,
                    StatusId = x.Role.StatusId,
                },
            }).ToList();
            AppUser.BaseLanguage = CurrentContext.Language;
            return(AppUser);
        }