public async Task Update_NotFound() { //Setup var id = Guid.NewGuid(); var input = new ProfileUpdateViewModel() { FirstName = "Upd", LastName = "Upd", Gender = "Upd", DateOfBirth = DateTimeOffset.Now.AddDays(1), City = "Ct" }; var serviceMock = new Mock <IProfileService>(); serviceMock .Setup(x => x.UpdateAsync(id, input.FirstName, input.LastName, input.Gender, input.DateOfBirth, input.City, string.Empty)) .ReturnsAsync(DomainResult.Error("NotFound")); var client = TestServerHelper.New(collection => { collection.AddScoped(_ => serviceMock.Object); }); //Act var response = await client.PutAsync($"profiles/{id}", input.AsJsonContent()); //Assert Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public IActionResult UpdateProfile(int id) { Profile pro = _profileDataService.GetSingle(p => p.ProfileId == id); IEnumerable <Branch> branchList = _branchrDataService.GetAll(); IEnumerable <Puesto> puestoList = _puestoDataService.GetAll(); ProfileUpdateViewModel vm = new ProfileUpdateViewModel { ProfileId = pro.ProfileId, UserName = pro.UserName, FirstName = pro.FirstName, LastName = pro.LastName, Role = pro.Role, BranchId = pro.BranchId, Legajo = pro.Legajo, FechaIngreso = pro.FechaIngreso, Preocupacional = pro.Preocupacional, VtoLibreta = pro.VtoLibreta, Activo = pro.Activo, Birthday = pro.Birthday, CUIL = pro.CUIL, Nacionalidad = pro.Nacionalidad, Direccion = pro.Direccion, Localidad = pro.Localidad, CP = pro.CP, TelMobil = pro.TelMobil, LandLine = pro.LandLine, EstadoCivil = pro.EstadoCivil, Hijos = pro.Hijos, Branches = branchList, Puestos = puestoList }; return(View(vm)); }
public async Task <ActionResult> UpdateAsync([FromRoute] string id, [FromBody] ProfileUpdateViewModel updateModel) { var result = await profileService.UpdateAsync(id, updateModel.FirstName, updateModel.LastName, updateModel.Gender, updateModel.DateOfBirth, updateModel.City); if (result.Successed) { return(NoContent()); } return(BadRequest(result.ToProblemDetails())); }
public async Task <DomainResult> UpdateAsync(User user) { var profile = await profilesApi.GetByIdAsync(user.Id); var updateCommand = new ProfileUpdateViewModel( profile.FirstName, profile.LastName, user.Gender, user.DateOfBirth, profile.City); try { await profilesApi.UpdateAsync(user.Id, updateCommand); return(DomainResult.Success()); } catch (Profiles.Client.ApiException ex) when(ex.ErrorCode == (int)HttpStatusCode.BadRequest) { return(DomainResult.Error("ERROR!!!!")); } }
public ActionResult AddImage(ProfileUpdateViewModel model, HttpPostedFileBase file) { var db = new ApplicationDbContext(); var currentUser = User.Identity.GetUserId(); var currentProfile = db.Profil.FirstOrDefault(x => x.UserID == currentUser); if (file.ContentLength > 0) { string _FileName = Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/images"), _FileName); file.SaveAs(_path); var imgNameToSave = "/images/" + _FileName; db.Profil.FirstOrDefault(p => p.UserID == currentUser).ProfileURL = imgNameToSave; } else { currentProfile.ProfileURL = model.ImageName; } db.SaveChanges(); return(View("~/Views/Profils/AddImage.cshtml")); //return RedirectToAction("ShowProfile", "Profils"); }
public IActionResult UpdateProfile(ProfileUpdateViewModel vm) { if (ModelState.IsValid) { Profile p = new Profile { UserName = User.Identity.Name, ProfileId = vm.ProfileId, FirstName = vm.FirstName, LastName = vm.LastName, Role = vm.Role, BranchId = vm.BranchId, Legajo = vm.Legajo, FechaIngreso = vm.FechaIngreso, Preocupacional = vm.Preocupacional, VtoLibreta = vm.VtoLibreta, Activo = vm.Activo, Birthday = vm.Birthday, CUIL = vm.CUIL, Nacionalidad = vm.Nacionalidad, Direccion = vm.Direccion, Localidad = vm.Localidad, CP = vm.CP, TelMobil = vm.TelMobil, LandLine = vm.LandLine, EstadoCivil = vm.EstadoCivil, Hijos = vm.Hijos, }; _profileDataService.Update(p); ////update Identity email //IdentityUser user = await _userManagerService.FindByNameAsync(User.Identity.Name); //user.Email = vm.Email; //await _userManagerService.UpdateAsync(user); //return RedirectToAction("Index", "Home"); return(RedirectToAction("List", "Profile")); } return(View(vm)); }
public async Task <IActionResult> Profile(ProfileUpdateViewModel viewModel) { var user = _userService.GetCurrent(); if (viewModel.Avatar != null) { var path = _pathHelper.GetPathToAvatarByUser(user.Id); using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) { await viewModel.Avatar.CopyToAsync(fileStream); } user.AvatarUrl = _pathHelper.GetAvatarUrlByUser(user.Id); _logger.LogInformation($"User {user.Id} change avatar"); } user.Email = viewModel.Email; _userRepository.Save(user); return(RedirectToAction("Profile")); }
public ActionResult ChangeUserProfile(ProfileUpdateViewModel User) { if (!ModelState.IsValid) { return(RedirectToAction("UserProfile")); } var profile = new ProfileUpdateViewModel { Id = User.Id, FirstName = User.FirstName, LastName = User.LastName, DisplayName = User.DisplayName, Avatar = User.Avatar, Email = User.Email, UserName = User.Email }; UserRolesHelper.UpdateUserData(profile); return(RedirectToAction("UserProfile")); }
//Used to update data in the user profile. //Would like to add return for success or failure public void UpdateUserData(ProfileUpdateViewModel user) { var thisUser = db.Users.Find(user.Id); thisUser.Id = user.Id; thisUser.FirstName = user.FirstName; thisUser.LastName = user.LastName; thisUser.DisplayName = user.DisplayName; thisUser.Avatar = user.Avatar; thisUser.Email = user.Email; thisUser.UserName = user.Email; db.Users.Attach(thisUser); db.Entry(thisUser).Property(x => x.FirstName).IsModified = true; db.Entry(thisUser).Property(x => x.LastName).IsModified = true; db.Entry(thisUser).Property(x => x.DisplayName).IsModified = true; db.Entry(thisUser).Property(x => x.Avatar).IsModified = true; db.Entry(thisUser).Property(x => x.Email).IsModified = true; db.Entry(thisUser).Property(x => x.UserName).IsModified = true; db.SaveChanges(); }
public async Task <IActionResult> Settings() { ViewBag.SubsectionPages = _subsectionPages; ViewBag.ActiveSubpage = _subsectionPages[1]; if (!_signInManager.IsSignedIn(User)) { ModelState.AddModelError(string.Empty, "You have to be logged in to change your settings!"); return(Redirect("/Profile/Settings")); } NeobooruUser usr = await _userManager.GetUserAsync(User); ProfileUpdateViewModel puvm = new ProfileUpdateViewModel() { Gender = usr.Gender, Username = usr.UserName, ProfileDescription = usr.ProfileDescription, }; return(View(puvm)); }
public async Task <IActionResult> Update(ProfileUpdateViewModel puvm) { if (!ModelState.IsValid) { return(Redirect("/Profile/Settings")); } if (!_signInManager.IsSignedIn(User)) { ModelState.AddModelError(string.Empty, "You have to be logged in to change your settings!"); return(Redirect("/Profile/Settings")); } NeobooruUser usr = await _userManager.GetUserAsync(User); usr.Gender = puvm.Gender; usr.UserName = puvm.Username; usr.ProfileDescription = puvm.ProfileDescription; if (puvm.PfpImage != null) { Guid id = Guid.NewGuid(); ImageFileManager ifmPfp = null; try { ifmPfp = new ImageFileManager("wwwroot/img/profiles/pfps/", puvm.PfpImage.OpenReadStream(), ImageUtils.ImgExtensionFromContentType(puvm.PfpImage.ContentType)); } catch (InvalidArtDimensionsException e) { ModelState.AddModelError(string.Empty, "Invalid profile picture or background size! " + "Profile picture must be at least 400px by 400px"); return(Redirect("/Profile/Settings")); } usr.PfpUrl = await ifmPfp.SavePfp(id); usr.PfpUrl = usr.PfpUrl.Remove(0, 7); } if (puvm.BgImage != null) { Guid id = Guid.NewGuid(); ImageFileManager ifmPfp = null; try { ifmPfp = new ImageFileManager("wwwroot/img/profiles/bgs/", puvm.BgImage.OpenReadStream(), ImageUtils.ImgExtensionFromContentType(puvm.BgImage.ContentType)); } catch (InvalidArtDimensionsException e) { ModelState.AddModelError(string.Empty, "Invalid profile picture or background size! " + "Background must be at least 1590px by 540px"); return(Redirect("/Profile/Settings")); } usr.BgUrl = await ifmPfp.SaveBg(id); usr.BgUrl = usr.BgUrl.Remove(0, 7); } await _db.SaveChangesAsync(); return(Redirect("/Profile/Profile")); }