public PartialViewResult UpdateProf(ProfileModel profmodel) { ModelState.Remove("Id"); if (ModelState.IsValid) { var countryId = cabinetservice.GetIdByCountryName(profmodel.Country); var bllprof = Maper.ToBllProfile(profmodel); bllprof.CountryId = countryId; if (!cabinetservice.UserHasProfile(Identiti.Identity.Name)) { var id = cabinetservice.FindIdByName(Identiti.Identity.Name); bllprof.Id = id; cabinetservice.CreateProfile(bllprof); profmodel.Id = id; } else { bllprof.Id = cabinetservice.GetUserIdByName(Identiti.Identity.Name); cabinetservice.UpdateProfile(bllprof); } } else ModelState.AddModelError("", "Профиль некорректен"); ViewBag.countries = cabinetservice.GetAllCountries(); return PartialView("UpdateProfile", profmodel); }
internal static BllProfile ToBllProfile(ProfileModel modelprofile) { if(modelprofile!=null) return new BllProfile() { Id = modelprofile.Id, Receiver = modelprofile.Receiver, City = modelprofile.City, Address = modelprofile.Address, Phone = modelprofile.Phone }; return null; }