Exemple #1
0
        public async Task <ResponseModel> EditUserAssets(UserAssets userAssets, string token)
        {
            try
            {
                var responseClient = _httpClientFactory.CreateClient("AssetAPI");

                responseClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var result = await responseClient.PutAsJsonAsync <UserAssets>("api/UserAssets/" + userAssets.AssetsId, userAssets);

                if (result.StatusCode != HttpStatusCode.OK)
                {
                    var faliedResponse = await result.Content.ReadAsJsonAsync <RestException>();

                    return(new ResponseModel()
                    {
                        ResponseMessage = faliedResponse.Errors.ToString(),
                        ResponseCode = result.StatusCode.ToString()
                    });
                }

                return(new ResponseModel()
                {
                    ResponseCode = result.StatusCode.ToString()
                });
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserAssetsService||EditUserAssets ErrorMessage: {ex.Message}");
                throw ex;
            }
        }
Exemple #2
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                //logic goes here
                var userAssets = await _context.UserAssets.Where(x => x.AssetsId == request.AssetsId).AsNoTracking().ToListAsync();

                foreach (var item in userAssets)
                {
                    item.IsActive = "No";
                }

                var userAsset = new UserAssets()
                {
                    Id          = Guid.NewGuid(),
                    AssetsId    = request.AssetsId,
                    UserStaffId = request.UserStaffId,
                    IssuedOn    = request.IssuedOn,
                    ReturnedOn  = request.ReturnedOn,
                    IsActive    = request.IsActive
                };

                _context.UserAssets.Add(userAsset);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                else
                {
                    throw new Exception("Problem saving changes");
                }
            }
Exemple #3
0
	public UserContainer()
	{
		if (userStats == null)
			userStats = new UserStats();
		if (userAssets == null)
			userAssets = new UserAssets();
		if (gridBlocksContainer == null)
			gridBlocksContainer = new GridBlockValuesContainer();
	}
        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"));
            }
        }