Пример #1
0
        public async Task <IActionResult> Details(DistrictDetailViewModel formdata)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _districtServices.UpdateDistrictAsync(new District
                    {
                        Id               = formdata.Id,
                        Name             = formdata.Name,
                        DateTimeModified = DateTimeOffset.Now,
                        UserAccount      = User.Identity.Name
                    });

                    TempData["Message"] = "Changes saved successfully";
                    _logger.LogInformation($"Success: successfully updated district {formdata.Name} record by user={@User.Identity.Name.Substring(4)}");
                    return(RedirectToAction("details", new { id = formdata.Id }));
                }
            }
            catch (ApplicationException error)
            {
                _logger.LogError(
                    error,
                    $"FAIL: failed to update {formdata.Name} district. Internal Application Error.; user={@User.Identity.Name.Substring(4)}");
                ModelState.AddModelError("District", $"Failed to update {formdata.Name} district record. Contact IT ServiceDesk for support thank you.");
            }
            return(View(formdata));
        }
Пример #2
0
        public async Task <IActionResult> Details(Guid id)
        {
            var districtQuery = await _districtServices.GetDistrictById(id);

            if (districtQuery == null)
            {
                return(NotFound());
            }
            var model = new DistrictDetailViewModel
            {
                Id   = districtQuery.Id,
                Name = districtQuery.Name
            };

            return(View(model));
        }