public IActionResult EditPicture(ProfileEditVM obj) { Profile profile = _db.profiles.Find(obj.ProfileId); ProfileEditVM edit = new ProfileEditVM { ProfileId = profile.Id, ExistingProfileImagePath = profile.ProfilePicture }; if (profile != null) { if (edit.ExistingProfileImagePath != null) { if (!obj.ProfileImage.ContentType.Contains("image")) { ModelState.AddModelError("", "You can only upload image."); } else { profile.ProfilePicture = UploadedPicture(obj); } } _db.Update(profile); _db.SaveChanges(); } return(Redirect("/Profile/EditProfile?ProfileId=" + profile.Id)); }
public IActionResult EditProfile(string ProfileId) { Profile p = _db.profiles.Find(ProfileId); ProfileEditVM pe = new ProfileEditVM(); if (p.UserID != null) { User u = _db.users.Where(x => x.Id == p.UserID).FirstOrDefault(); pe.Country = ReturnCountry(u.CityId); pe.CountryId = u.City.CountryId; pe.FirstName = u.FirstName; pe.LastName = u.LastName; pe.HighSchoolName = u.HighSchoolName; pe.Adress = u.Address; pe.CollegeName = u.CollegeName; pe.GenderId = u.GenderId; pe.CityName = u.City.Name; pe.BirthDate = u.BirthDate; } else { Company c = _db.companies.Where(x => x.Id == p.CompanyID).FirstOrDefault(); pe.FirstName = c.CompanyRepresenterFirstName; pe.LastName = c.CompanyRepresenterLastName; pe.Country = ReturnCountry(c.CityId); pe.CountryId = c.City.CountryId; pe.Adress = c.Adress; pe.CompanyName = c.Name; pe.CityName = c.City.Name; } pe.ProfileId = p.Id; pe.Email = p.Email; pe.ProfilePicture = p.ProfilePicture; pe.PhoneNumber = p.PhoneNumber; List <SelectListItem> cities = _db.cities.Where(s => s.CountryId == pe.CountryId).Select(s => new SelectListItem { Text = s.Name, Value = s.Id.ToString() }).ToList(); List <SelectListItem> countries = _db.countries.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); List <SelectListItem> genders = _db.genders.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); pe.cities = cities; pe.countries = countries; pe.genders = genders; return(View(pe)); }
public async Task UpdateAccount(ProfileEditVM profileVM) { var owner = new Owner() { ID = profileVM.ID, Name = profileVM.Name, Surname = profileVM.Surname, BornDate = profileVM.BornDate, DrivingExperience = profileVM.DrivingExperience, Password = profileVM.Password, Login = profileVM.Login }; await _ownerRepository.UpdateOwner(owner); }
public async Task <IActionResult> Edit(int id) { var owner = await _accountService.GetOwner(id); var vm = new ProfileEditVM() { ID = owner.ID, Surname = owner.Surname, Name = owner.Name, BornDate = owner.BornDate, Login = owner.Login, Password = owner.Password, DrivingExperience = owner.DrivingExperience }; return(View(vm)); }
public async Task <IActionResult> Edit(int id, ProfileEditVM profileVM) { if (id != profileVM.ID) { return(NotFound()); } if (ModelState.IsValid) { await _accountService.UpdateAccount(profileVM); } var vm = new ProfileDetailsVm() { IsValidForEditing = (Convert.ToInt32(User.Identity.Name) == id), Owner = await _accountService.GetOwnerWithCars(Convert.ToInt32(User.Identity.Name)) }; return(View("../Account/Details", vm)); }
public IActionResult SaveChanges(ProfileEditVM vm) { Profile p = _db.profiles.Find(vm.ProfileId); User user = _db.users.Where(x => x.Id == p.UserID).FirstOrDefault(); Company company = _db.companies.Where(s => s.Id == p.CompanyID).FirstOrDefault(); if (p != null && user != null) { user.FirstName = vm.FirstName; user.LastName = vm.LastName; user.Email = vm.Email; user.Address = vm.Adress; user.CollegeName = vm.CollegeName; user.BirthDate = vm.BirthDate; user.PhoneNumber = vm.PhoneNumber; user.CityId = vm.CityId; user.HighSchoolName = vm.HighSchoolName; user.GenderId = vm.GenderId; } else if (p != null && company != null) { company.CompanyRepresenterFirstName = vm.FirstName; company.CompanyRepresenterLastName = vm.LastName; company.Adress = vm.Adress; //company.PhoneNumber = vm.PhoneNumber; company.CityId = vm.CityId; if (vm.CompanyName != null) { company.Name = vm.CompanyName; } else { company.Name = "Company name can not be empty. You are registered as company. Set your company name!"; } } _db.SaveChanges(); return(Redirect("/Profile/Details?id=" + vm.ProfileId)); }