public async Task <bool?> UpdateHidrogenianAvatar(HidroProfileVM profile) { _logger.LogInformation("HidroProfileService.UpdateHidrogenianAvatar - Service starts."); HidroProfile dbProfile; if (profile.Id != 0) { dbProfile = await _dbContext.HidroProfile.FindAsync(profile.Id); } else { dbProfile = await _dbContext.HidroProfile.FirstOrDefaultAsync(p => p.HidrogenianId == profile.HidrogenianId); } if (dbProfile == null) { return(null); } dbProfile.AvatarInformation = JsonConvert.SerializeObject(profile.Avatar); _dbContext.HidroProfile.Update(dbProfile); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroProfileService.UpdateHidrogenianAvatar - Error: " + e); return(false); } return(true); }
public async Task <bool?> UpdatePrivateProfile(HidroProfileVM profile) { _logger.LogInformation("HidroProfileService.UpdatePrivateProfile - Service starts."); var dbProfile = await _dbContext.HidroProfile.FindAsync(profile.Id); if (dbProfile == null) { return(null); } dbProfile.FamilyName = profile.FamilyName; dbProfile.GivenName = profile.GivenName; dbProfile.Gender = profile.Gender == 0 ? (bool?)null : (profile.Gender == 1); dbProfile.DateOfBirth = profile.Birthday.Birth; dbProfile.Ethnicity = profile.Ethnicity; dbProfile.Company = profile.Company; dbProfile.JobTitle = profile.JobTitle; dbProfile.PersonalWebsite = profile.Website; dbProfile.SelfIntroduction = profile.SelfIntroduction; _dbContext.HidroProfile.Update(dbProfile); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroProfileService.UpdatePrivateProfile - Error: " + e); return(false); } return(true); }
private async Task <JsonResult> UpdateHidrogenianAvatarInternally(int hidrogenianId, string apiKey, ResultVM avatarResult) { _logger.LogInformation("ProfileController.UpdateHidrogenianAvatarInternally - Service runs internally."); var avatar = (AvatarVM)avatarResult; var profile = new HidroProfileVM { HidrogenianId = hidrogenianId, Avatar = avatar }; var result = await _profileService.UpdateHidrogenianAvatar(profile); if (!result.HasValue || !result.Value) { var deleted = await _waterService.SendDeleteAvatarRequestToWater(apiKey, avatar.Name); if (deleted == null) { return(new JsonResult(new { Result = RESULTS.INTERRUPTED, Message = "Your avatar was uploaded, however, an error occurred while we update your profile. Please reload page and try again." })); } return(!deleted.Error ? new JsonResult(new { Result = RESULTS.INTERRUPTED, Message = "Your avatar was uploaded, however, an error occurred while we update your profile. Changes have been reverted. Please try again." }) : new JsonResult(new { Result = RESULTS.INTERRUPTED, Message = "Your avatar was uploaded, however, an error occurred while we update your profile. Please try again" })); } return(new JsonResult(new { Result = RESULTS.SUCCESS, Message = avatar.Name })); }
private List <int> VerifyProfileData(HidroProfileVM profile) { _logger.LogInformation("ProfileController.VerifyProfileData - Verification starts."); var errors = profile.VerifyFamilyName(); errors.AddRange(profile.VerifyGivenName()); errors.AddRange(profile.VerifyBirthday()); errors.AddRange(profile.VerifyCompany()); errors.AddRange(profile.VerifyEthnicity()); errors.AddRange(profile.VerifyJobTitle()); errors.AddRange(profile.VerifyWebsite()); errors.AddRange(profile.VerifyIntroduction()); return(errors); }
public async Task <JsonResult> UpdatePrivateProfile(HidroProfileVM profile) { _logger.LogInformation("ProfileController.UpdatePrivateProfile - Service starts."); var verification = VerifyProfileData(profile); if (verification.Count != 0) { var messages = profile.GenerateProfileDataErrorMessages(verification); return(new JsonResult(new { Result = RESULTS.FAILED, Message = messages })); } var result = await _profileService.UpdatePrivateProfile(profile); return(!result.HasValue ? new JsonResult(new { Result = RESULTS.FAILED, Message = "No profile found with the given data. Unable to update." }) : ( result.Value ? new JsonResult(new { Result = RESULTS.SUCCESS }) : new JsonResult(new { Result = RESULTS.FAILED, Message = "Error happened while updating your profile. Please try again." }) )); }
public async Task <bool> InsertProfileForNewlyCreatedHidrogenian(HidroProfileVM profile) { _logger.LogInformation("HidroProfileService.InsertProfileForNewlyCreatedHidrogenian - Service starts."); var dbProfile = new HidroProfile { HidrogenianId = profile.HidrogenianId, FamilyName = profile.FamilyName, GivenName = profile.GivenName }; _dbContext.Add(dbProfile); try { await _dbContext.SaveChangesAsync(); } catch (Exception e) { _logger.LogError("HidroProfileService.InsertProfileForNewlyCreatedHidrogenian - Error: " + e); return(false); } return(true); }