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"));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var userAssets = await _userAssetsInterface.GetUserAssets(Request.Cookies["AssetReference"].ToString());

                var resultAsset = await _userAssetsInterface.GetUserOfAssets("2e02d462-6e82-4146-affa-08d89be9abb5", Request.Cookies["AssetReference"].ToString());

                var resultUser = await _userAssetsInterface.GetAssetsOfUser("6d0b63c2-b12d-40d1-4f40-08d8959ebd0b", Request.Cookies["AssetReference"].ToString());

                return(View());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserAssetsController||Index ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }
        public async Task <IActionResult> AssignAssetsUsers(AssetsUserVIewModel assetsUserVIewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(assetsUserVIewModel));
                }

                var userAssetsUpdate = new UserAssets()
                {
                    AssetsId = assetsUserVIewModel.AssetId,
                    IsActive = "No"
                };

                //Check if the user is already assigned in target asset
                var checkUser = await _userAssetsInterface.GetUserOfAssets(assetsUserVIewModel.UserStaffId.ToString(), Request.Cookies["AssetReference"].ToString());

                if (checkUser != null)
                {
                }

                //Update all existing user of specific assets to IsActive = No
                var userAssets = await _userAssetsInterface.EditUserAssets(userAssetsUpdate, Request.Cookies["AssetReference"].ToString());

                if (userAssets.ResponseCode != HttpStatusCode.OK.ToString())
                {
                    ViewBag.ErrorResponse = userAssets.ResponseMessage;
                    return(View());
                }

                var userAsset = new UserAssets()
                {
                    AssetsId    = assetsUserVIewModel.AssetId,
                    UserStaffId = assetsUserVIewModel.UserStaffId,
                    IssuedOn    = DateTime.Now,
                    ReturnedOn  = assetsUserVIewModel.ReturedOn,
                    IsActive    = "Yes",
                };

                var result = await _userAssetsInterface.CreateUserAssets(userAsset, Request.Cookies["AssetReference"].ToString());

                if (result.ResponseCode != HttpStatusCode.OK.ToString())
                {
                    ViewBag.ErrorResponse = result.ResponseMessage;
                    return(View());
                }

                var asset = new Asset()
                {
                    Id         = assetsUserVIewModel.AssetId,
                    IsAssinged = "Yes"
                };

                var response = await _assetInterface.EditAsset(asset, Request.Cookies["AssetReference"].ToString());

                if (response.ResponseCode != HttpStatusCode.OK.ToString())
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var user = await _userStaffInterface.GetUserStaffs(Request.Cookies["AssetReference"].ToString());

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

                //Map the objects results to corresponding DTO's
                List <UserStaffDTO> userStaffDTO = _mapper.Map <List <UserStaffDTO> >(user);

                //Instantiate AssetsUserVIewModel
                var model = new AssetsUserVIewModel()
                {
                    UserStaffDTOs = userStaffDTO
                };

                ViewBag.AssetId = userAsset.AssetsId;

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