public async Task <SingleUserResponse> Register([FromBody] User newUser) { SingleUserResponse response = new SingleUserResponse(); response.Success = false; if (!ModelState.IsValid) { response.Message = "Invalid credentials. Please enter a valid email and password."; return(response); } if (UserExists(newUser.Email)) { response.Message = "This email address has already been registered. Please log in with this email or use a new email address."; return(response); } _context.User.Add(newUser); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { response.Message = "We encountered a database error. Please try again later or contact our team for assistance."; return(response); } response.Success = true; response.Message = "Registration successful!"; response.User = newUser; return(response); }
public static async Task <SingleUserResponse> GetUserByUsername(string username) { SingleUserResponse failedResponse = null; try { var response = await client.GetAsync($"Users/{username}"); var getUserResponse = await response.Content.ReadAsStringAsync(); var defaultResponseObject = JsonConvert.DeserializeObject <SingleUserResponse>(getUserResponse); if (!response.IsSuccessStatusCode) { failedResponse = new SingleUserResponse(); failedResponse.Message = "Error connecting to server"; Debug.WriteLine($"Error connecting to server"); return(failedResponse); } else { return(defaultResponseObject); } } catch (Exception ex) { failedResponse.Message = "Retrieving user by username operation failed. Exception occured"; Debug.WriteLine($"User retrieval error : {ex.Message}"); return(failedResponse); } }
public void TC_02_01_SubjectTest_GET_SINGLE_USER() { //arrange+act IRestResponse response = GetResponse(client, "/api/users/2", Method.GET, HttpStatusCode.OK); SingleUserResponse userResponse = JsonConvert.DeserializeObject <SingleUserResponse>(response.Content); // assert Assert.That(userResponse.Data.FirstaName, Is.EqualTo("Janet")); }
public void TC_05_01_SubjectTest_GET_SINGLE_RESOURCE() { //arrange+act IRestResponse response = GetResponse(client, "/api/unknown/2", Method.GET, HttpStatusCode.OK); SingleUserResponse userResponse = JsonConvert.DeserializeObject <SingleUserResponse>(response.Content); // assert Assert.That(userResponse.Data.Name, Is.EqualTo("fuchsia rose")); }
public void check_efficient(Route route) { int st = get_intersection_s(route); int en = get_intersection_e(route); if (st != -1 && en != -1) { SingleUserResponse rsp = new SingleUserResponse(user_start, route.coords[st], route.coords[0], route.coords[en], user_end, route); resps.Add(rsp); } }
public async Task <SingleUserResponse> Login([FromBody] User user) { SingleUserResponse response = new SingleUserResponse(); User checkuser = await _context.User.SingleOrDefaultAsync(x => x.Email == user.Email); if (checkuser == null) { response.Success = false; response.Message = "This email has not been registered. Please sign up!"; return(response); } if (checkuser.Password != user.Password) { response.Success = false; response.Message = "Incorrect password. Please try again."; } response.Success = true; response.Message = "Login successful."; checkuser.Password = null; response.User = checkuser; return(response); }
public async Task <SingleUserResponse> Get([FromRoute] int id) { SingleUserResponse response = new SingleUserResponse(); if (!ModelState.IsValid) { response.Success = false; response.Message = "Bad Request."; return(response); } var user = await _context.User.SingleOrDefaultAsync(x => x.UserID == id); if (user == null) { response.Success = false; response.Message = "User not found."; return(response); } response.Success = true; response.Message = "User found."; response.User = user; return(response); }