示例#1
0
        public async Task <IActionResult> ChangePassword(ChangePasswordModel changePasswordModel)
        {
            try
            {
                var Email = flightDBContext.FlightUsers.Where(x => x.Username == changePasswordModel.UserName)
                            .Select(x => x.Email).FirstOrDefault();

                FlightUsers flightUsers = flightDBContext.FlightUsers.
                                          Where(x => x.Email == Email)
                                          .Select(x => x).FirstOrDefault();
                flightUsers.Password = changePasswordModel.Password;
                flightDBContext.SaveChanges();
                ChangePasswordResponse changePasswordResponse =
                    new ChangePasswordResponse();
                changePasswordResponse.IsPasswordChanged = true;
                return(Ok(SerializeIntoJson(changePasswordResponse)));
            }
            catch (Exception e)
            {
                return(BadRequest("Invalid Request" + e.StackTrace + e.Message));
            }
        }
示例#2
0
        public async Task <IActionResult> RegisterUser([FromBody] RegisterUserModel registerUserModel)
        {
            try
            {
                var user = flightDBContext.FlightUsers.Where(x => x.Username ==
                                                             registerUserModel.Username).Select(x => x).Any();

                if (!user)
                {
                    FlightUsers flightUsers = new FlightUsers();
                    flightUsers.Username    = registerUserModel.Username;
                    flightUsers.Password    = registerUserModel.Password;
                    flightUsers.Email       = registerUserModel.Email;
                    flightUsers.PhoneNumber = registerUserModel.PhoneNumber;
                    flightUsers.DateOfBirth = registerUserModel.DateOfBirth;

                    flightDBContext.FlightUsers.Add(flightUsers);
                    flightDBContext.SaveChanges();
                    FlightRegisterResponse flightRegisterResponse = new FlightRegisterResponse();
                    flightRegisterResponse.IsUserRegistered    = true;
                    flightRegisterResponse.ReponseMessage      = "User Registered Successfully";
                    flightRegisterResponse.IsUserAlreadyExists = false;
                    return(Ok(SerializeIntoJson(flightRegisterResponse)));
                }
                else
                {
                    FlightRegisterResponse flightRegisterResponse = new FlightRegisterResponse();
                    flightRegisterResponse.IsUserRegistered    = false;
                    flightRegisterResponse.ReponseMessage      = "User Not Registered";
                    flightRegisterResponse.IsUserAlreadyExists = true;
                    return(Ok(SerializeIntoJson(flightRegisterResponse)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Invalid Request"));
            }
        }