public IActionResult RecordForm(RecordFormViewModel viewModel) { var citizen = citizenRepository.Get(viewModel.CitizenId); var recordForm = mapper.Map <RecordForm>(viewModel); recordForm.Citizen = citizen; recordFormRepository.Save(recordForm); return(RedirectToAction("HealthDepartment")); }
public IActionResult Index(int profileId) { var profile = mapper.Map <ProfileViewModel>(cuRepo.Get(profileId)); var userItems = pmRepo.GetNotPolicemanUsers(); var users = mapper.Map <ProfileViewModel[]>(userItems); var item = new PolicemanViewModel() { CitizenUserProfiles = users, ProfileVM = profile }; return(View(item)); }
public CitizenUser GetCurrentUser() { var idStr = httpContextAccessor.HttpContext. User.Claims.SingleOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(idStr)) { return(null); } var id = int.Parse(idStr); var user = citizenUserRepository.Get(id); return(user); }
public IActionResult Profile(long id) { var citizen = citizenUserRepository.Get(id); var viewModel = mapper.Map <ProfileViewModel>(citizen); return(View(viewModel)); }
public IActionResult AddEditVictim(AccidentVictimViewModel accidentVictimViewModel) { accidentVictimViewModel.CitizenList = lifeService.GetSelectListOfCitizensFromDb(); accidentVictimViewModel.BodilyHarmList = lifeService.GetSelectListFromEnum <BodilyHarmEnum>(); // CitizenId is not valid if (ModelState[nameof(accidentVictimViewModel.CitizenId)].ValidationState == ModelValidationState.Invalid) { // remove all ModelStateEntries with key name different from "CitizenId" -> // we demonstrate only CitizenId error here ModelState.Keys.Where(key => key != nameof(accidentVictimViewModel.CitizenId)). ToList().Select(key => ModelState.Remove(key)).ToList(); return(View("~/Views/Life/AddEditVictim.cshtml", accidentVictimViewModel)); } // EconomicLoss numeric format is not valid (though the user attempted to enter something) if (!ModelState.IsValid && ModelState[nameof(accidentVictimViewModel.EconomicLoss)].AttemptedValue != String.Empty) { return(View("~/Views/Life/AddEditVictim.cshtml", accidentVictimViewModel)); } // validation for combination of properties if ((accidentVictimViewModel.EconomicLoss == null || accidentVictimViewModel.EconomicLoss == 0) && (accidentVictimViewModel.BodilyHarm == BodilyHarmEnum.None || accidentVictimViewModel.BodilyHarm == BodilyHarmEnum.NotAvailable)) { ModelState.Clear(); ModelState.AddModelError(String.Empty, "Чтобы человек считался потерпевшим, у него должны быть телесные повреждения или экономический ущерб");; return(View("~/Views/Life/AddEditVictim.cshtml", accidentVictimViewModel)); } var accidentVictim = mapper.Map <AccidentVictim>(accidentVictimViewModel); var citizenUser = citizenUserRepository.Get((long)accidentVictimViewModel.CitizenId); accidentVictim.Victim = citizenUser; var accident = accidentRepository.Get(accidentVictimViewModel.AccidentId); accidentVictim.Accident = accident; victimRepository.Save(accidentVictim); return(RedirectToAction(nameof(EditFire), new { id = accidentVictimViewModel.AccidentId })); }
public IActionResult Profile(long id) { var citizen = citizenUserRepository.Get(id); //var viewModel = new ProfileViewModel() //{ // Login = dbModel.Login, // AvatarUrl = dbModel.AvatarUrl //}; var viewModel = mapper.Map <ProfileViewModel>(citizen); return(View(viewModel)); }