Esempio n. 1
0
        public async Task <IActionResult> Details(NextOfKinDetailViewModel formData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _nextOfKinServices.UpdateNextOfKinAsync(new NextOfKin
                    {
                        DateTimeModified = DateTimeOffset.Now,

                        RelationshipId = formData.RelationshipId,
                        Name           = formData.Name,
                        //Address = formData.Address,
                        //Residence = formData.Residence,
                        ContactInfo = formData.ContactInfo,
                        EmployeeId  = formData.EmployeeId,
                        Id          = formData.Id,
                        UserAccount = User.Identity.Name
                    });

                    TempData["Message"] = "Changes saved successfully";
                    _logger.LogInformation($"SUCCESS: successfully updated employee {formData.EmployeeId} nextofkin 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.EmployeeId} nextofkin. Internal Application Error.; user={@User.Identity.Name.Substring(4)}");
                ModelState.AddModelError("NextofKin", $"Failed to update record {formData.EmployeeId}. Contact IT ServiceDesk for support thank you.");
            }

            await LoadSelectListsAsync();

            return(View(formData));
        }
Esempio n. 2
0
        public async Task <IActionResult> Details(Guid id)
        {
            var nextofkinQuery = await _nextOfKinServices.GetNextOfKinById(id);

            if (nextofkinQuery == null)
            {
                return(NotFound());
            }

            var model = new NextOfKinDetailViewModel
            {
                Name = nextofkinQuery.Name,
                // Address = nextofkinQuery.Address,
                //Residence = nextofkinQuery.Residence,
                ContactInfo    = nextofkinQuery.ContactInfo,
                RelationshipId = nextofkinQuery.RelationshipId,
                Id             = nextofkinQuery.Id,
                EmployeeId     = nextofkinQuery.EmployeeId ?? Guid.Empty
            };

            await LoadSelectListsAsync();

            return(View(model));
        }