コード例 #1
0
        public async Task <IActionResult> Update(UserStaffDTO userStaffDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(userStaffDTO));
                }

                LocationModel     locationModel     = (LocationModel)Enum.Parse(typeof(LocationModel), userStaffDTO.Location);
                AvailabilityModel availabilityModel = (AvailabilityModel)Enum.Parse(typeof(AvailabilityModel), userStaffDTO.IsActive);

                var userStaff = new UserStaff()
                {
                    Id          = userStaffDTO.Id,
                    DisplayName = userStaffDTO.DisplayName,
                    Department  = userStaffDTO.Department,
                    Location    = locationModel.ToString(),
                    IsActive    = availabilityModel.ToString(),
                    DateCreated = userStaffDTO.DateCreated
                };

                var result = await _userStaffInterface.EditUserStaff(userStaff, Request.Cookies["AssetReference"].ToString());

                return(View(userStaffDTO));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserStaffsController||Update ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> ViewUserStaff(string UserStaffId)
        {
            try
            {
                if (Request.Cookies["AssetReference"] == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var result = await _userStaffInterface.GetUserStaff(UserStaffId, Request.Cookies["AssetReference"].ToString());

                if (result == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var userLicense = await _userLicenseInterface.GetUserOfLicense(UserStaffId, Request.Cookies["AssetReference"].ToString());

                if (userLicense == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var userAssets = await _userAssetsInterface.GetUserOfAssets(UserStaffId, Request.Cookies["AssetReference"].ToString());

                if (userAssets == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                //Map the objects results to corresponding DTO's
                UserStaffDTO       userStaffDTO     = _mapper.Map <UserStaffDTO>(result);
                List <UserAssets>  listUserAssets   = _mapper.Map <List <UserAssets> >(userAssets);
                List <UserLicense> listUserLicenses = _mapper.Map <List <UserLicense> >(userLicense);

                //Instantiate UserAssetsLicenseViewModel
                var userAssetsLicenseViewModel = new UserAssetsLicenseViewModel()
                {
                    UserStaffDTO = userStaffDTO,
                    UserLicense  = listUserLicenses,
                    UserAssets   = listUserAssets
                };

                return(View(userAssetsLicenseViewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserStaffsController||ViewUserStaff ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }