public async Task<tbUser> UpdateUser(dtoUserProfile profile) { tbUser user = null; try { user = await _db.tbUsers.FirstOrDefaultAsync(x => x.UserId == profile.UserId && (x.IsActive ?? true) && !(x.IsDeleted ?? false)); if (user != null) { // the user exist user.Username = profile.Username; user.IPAddress = profile.IPAddress; user.StreetNo = profile.StreetNo; user.Street = profile.Street; user.City = profile.City; user.State = profile.State; user.Country = profile.Country; user.UpdatedDate = DateTime.UtcNow; await _db.SaveChangesAsync(); } } catch (DataException dex) { throw new ApplicationException("Data error!", dex); } return user; }
public async Task<IHttpActionResult> Login(dtoUser user) { dtoUserProfile userProfile = new dtoUserProfile(); try { user.IPAddress = GetClientIp(); userProfile = await _yuyanSvc.LoginUser(user); if (userProfile == null) return Content(HttpStatusCode.NotFound, "User not found."); if (userProfile.UserId == Guid.Empty) return Content(HttpStatusCode.Unauthorized, "Username and Password not match."); } catch (ApplicationException aex) { return BadRequest(aex.Message); } catch (Exception ex) { return InternalServerError(ex); } return Ok(userProfile); }
public async Task<IHttpActionResult> Register(dtoUser user) { dtoUserProfile userProfile = new dtoUserProfile(); try { user.IPAddress = GetClientIp(); userProfile = await _yuyanSvc.RegisterNewUser(user); } catch (ApplicationException aex) { return BadRequest(aex.Message); } catch (Exception ex) { return InternalServerError(ex); } return Ok(userProfile); }
public static dtoUserProfile ConvertToDtoUserProfile(this tbUser source, dtoUserProfile data = null) { if (data == null) data = new dtoUserProfile(); if (source == null) return null; data.UserId = source.UserId; data.Email = source.Email; data.Username = source.Username; data.UserRole = source.UserRole; data.StreetNo = source.StreetNo; data.Street = source.Street; data.City = source.City; data.State = source.State; data.Country = source.Country; data.IsDeleted = source.IsDeleted; data.IsActive = source.IsActive; return data; }
public async Task<IHttpActionResult> UpdateUserProfile(dtoUserProfile userProfile) { dtoUserProfile profile = null; try { userProfile.IPAddress = GetClientIp(); profile = await _yuyanSvc.UpdateUserProfile(userProfile); if (profile == null) return Content(HttpStatusCode.NotFound, "User not found."); } catch (ApplicationException aex) { return BadRequest(aex.Message); } catch (Exception ex) { return InternalServerError(ex); } return Ok(profile); }