public async Task <ActionResult <AppUser_AppUserDTO> > Create([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.Create(AppUser);

            AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);
            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
        private AppUser ConvertDTOToEntity(AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            AppUser AppUser = new AppUser();

            AppUser.Id           = AppUser_AppUserDTO.Id;
            AppUser.Username     = AppUser_AppUserDTO.Username;
            AppUser.Password     = AppUser_AppUserDTO.Password;
            AppUser.DisplayName  = AppUser_AppUserDTO.DisplayName;
            AppUser.Email        = AppUser_AppUserDTO.Email;
            AppUser.Phone        = AppUser_AppUserDTO.Phone;
            AppUser.LocationLogs = AppUser_AppUserDTO.LocationLogs?
                                   .Select(x => new LocationLog
            {
                Id             = x.Id,
                PreviousId     = x.PreviousId,
                Latitude       = x.Latitude,
                Longtitude     = x.Longtitude,
                UpdateInterval = x.UpdateInterval,
                Previous       = x.Previous == null ? null : new LocationLog
                {
                    Id             = x.Previous.Id,
                    PreviousId     = x.Previous.PreviousId,
                    AppUserId      = x.Previous.AppUserId,
                    Latitude       = x.Previous.Latitude,
                    Longtitude     = x.Previous.Longtitude,
                    UpdateInterval = x.Previous.UpdateInterval,
                },
            }).ToList();
            AppUser.BaseLanguage = CurrentContext.Language;
            return(AppUser);
        }
Example #3
0
        public async Task <ActionResult <AppUser_AppUserDTO> > Signup([FromBody] AppUser_SignupDTO AppUser_SignupDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            AppUser AppUser = new AppUser
            {
                Username    = AppUser_SignupDTO.Username,
                Password    = AppUser_SignupDTO.Password,
                DisplayName = AppUser_SignupDTO.DisplayName,
                SexId       = AppUser_SignupDTO.SexId,
                Birthday    = AppUser_SignupDTO.Birthday,
                Email       = AppUser_SignupDTO.Email,
                Phone       = AppUser_SignupDTO.Phone,
                RoleId      = RoleEnum.User.Id,
            };

            AppUser = await AppUserService.Create(AppUser);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Example #4
0
        public async Task <ActionResult <AppUser_AppUserDTO> > Login([FromBody] AppUser_LoginDTO AppUser_LoginDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            AppUser AppUser = new AppUser
            {
                Username     = AppUser_LoginDTO.Username,
                Password     = AppUser_LoginDTO.Password,
                BaseLanguage = "vi",
            };

            AppUser.BaseLanguage = CurrentContext.Language;
            AppUser = await AppUserService.Login(AppUser);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            if (AppUser.IsValidated)
            {
                Response.Cookies.Append("Token", AppUser.Token);
                AppUser_AppUserDTO.Token        = AppUser.Token;
                AppUser_AppUserDTO.RefreshToken = AppUser.RefreshToken;
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Example #5
0
        public async Task <ActionResult <AppUser_AppUserDTO> > RecoveryPassword([FromBody] AppUser_RecoveryPassword AppUser_RecoveryPassword)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            var     UserId  = ExtractUserId();
            AppUser AppUser = new AppUser
            {
                Id       = UserId,
                Password = AppUser_RecoveryPassword.Password,
            };

            AppUser.BaseLanguage = CurrentContext.Language;
            AppUser = await AppUserService.RecoveryPassword(AppUser);

            if (AppUser == null)
            {
                return(Unauthorized());
            }
            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            return(AppUser_AppUserDTO);
        }
Example #6
0
        public async Task <ActionResult <AppUser_AppUserDTO> > VerifyCode([FromBody] AppUser_VerifyOtpDTO AppUser_VerifyOtpDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            AppUser AppUser = new AppUser
            {
                Email   = AppUser_VerifyOtpDTO.Email,
                OtpCode = AppUser_VerifyOtpDTO.OtpCode,
            };

            AppUser.BaseLanguage = CurrentContext.Language;
            AppUser = await AppUserService.VerifyOtpCode(AppUser);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            if (AppUser.IsValidated)
            {
                HttpContext.Response.Cookies.Append("Token", AppUser.Token);
                return(AppUser_AppUserDTO);
            }

            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Example #7
0
        public async Task <ActionResult <AppUser_AppUserDTO> > ForgotPassword([FromBody] AppUser_ForgotPassword AppUser_ForgotPassword)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            AppUser AppUser = new AppUser
            {
                Email = AppUser_ForgotPassword.Email,
            };

            AppUser.BaseLanguage = CurrentContext.Language;

            AppUser = await AppUserService.ForgotPassword(AppUser);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Example #8
0
        public async Task <ActionResult <AppUser_AppUserDTO> > ChangePassword([FromBody] AppUser_ProfileChangePasswordDTO AppUser_ProfileChangePasswordDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            this.CurrentContext.UserId = ExtractUserId();
            AppUser AppUser = new AppUser
            {
                Id          = CurrentContext.UserId,
                Password    = AppUser_ProfileChangePasswordDTO.OldPassword,
                NewPassword = AppUser_ProfileChangePasswordDTO.NewPassword,
            };

            AppUser.BaseLanguage = CurrentContext.Language;
            AppUser = await AppUserService.ChangePassword(AppUser);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }
Example #9
0
        public async Task <ActionResult <AppUser_AppUserDTO> > GetMe()
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            var     UserId  = ExtractUserId();
            AppUser AppUser = await AppUserService.Get(UserId);

            AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);

            return(AppUser_AppUserDTO);
        }
        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));
        }
Example #11
0
        private AppUser ConvertDTOToEntity(AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            AppUser AppUser = new AppUser();

            AppUser.Id          = AppUser_AppUserDTO.Id;
            AppUser.Username    = AppUser_AppUserDTO.Username;
            AppUser.Password    = AppUser_AppUserDTO.Password;
            AppUser.DisplayName = AppUser_AppUserDTO.DisplayName;
            //AppUser.Avatar = AppUser_AppUserDTO.Avatar;
            AppUser.Birthday = AppUser_AppUserDTO.Birthday;
            AppUser.Email    = AppUser_AppUserDTO.Email;
            AppUser.Phone    = AppUser_AppUserDTO.Phone;
            AppUser.SexId    = AppUser_AppUserDTO.SexId;
            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.BaseLanguage = CurrentContext.Language;
            return(AppUser);
        }
Example #12
0
        public async Task <ActionResult <AppUser_AppUserDTO> > UpdateMe([FromBody] AppUser_AppUserDTO AppUser_AppUserDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            this.CurrentContext.UserId = ExtractUserId();
            AppUser AppUser = ConvertDTOToEntity(AppUser_AppUserDTO);

            AppUser.Id = CurrentContext.UserId;
            AppUser    = await AppUserService.Update(AppUser);

            AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser);
            if (AppUser.IsValidated)
            {
                return(AppUser_AppUserDTO);
            }
            else
            {
                return(BadRequest(AppUser_AppUserDTO));
            }
        }