Example #1
0
        public async Task <IActionResult> Edit(int id, SaleManagementDTO sale)
        {
            if (id != sale.Id)

            {
                _logger.LogError($"Id did not match for to {nameof(Edit)}.  Expected:{id}, Actual{sale.Id}");
                return(RedirectToAction(nameof(Index)));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    //todo set the sale date.
                    //todo change the status of the property that has been sold or moved to under contract.
                    UpdateListing(sale);
                    _repositoryWrapper.Sale.UpdateSale(_mapper.Map <Sale>(sale));
                    await _repositoryWrapper.SaveAsync();
                } catch (Exception ex)
                {
                    _logger.LogError($"Error creating Sale: {ex}");
                }

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Addresses"] = await GetAddresses(null);

            return(View(nameof(Edit), sale));
        }
Example #2
0
        private void UpdateListing(SaleManagementDTO sale)
        {
            Listing listing = _repositoryWrapper.Listing.GetListingsIdByAddressID(sale.PropertyId);

            listing.Status = sale.Status;
            _repositoryWrapper.Listing.UpdateListing(listing);
        }
Example #3
0
        public async void CallCreateSaleInRepository()
        {
            fixture.repositoryWrapper.Setup(x => x.Sale.CreateSale(It.IsAny <Sale>()));
            SaleManagementDTO saleManagementDTO = new SaleManagementDTO()
            {
                Id = 1, PropertyId = 2
            };



            var result = await sut.Create(saleManagementDTO);

            var vr = Assert.IsType <RedirectToActionResult>(result);

            fixture.repositoryWrapper.Verify(x => x.Sale.CreateSale(It.IsAny <Sale>()), Times.Once);

            fixture.repositoryWrapper.Verify(x => x.Listing.GetListingsIdByAddressID(It.IsAny <int>()), Times.Once);

            fixture.repositoryWrapper.Verify(x => x.Listing.UpdateListing(It.IsAny <Listing>()), Times.Once);
            fixture.repositoryWrapper.Verify(y => y.SaveAsync(), Times.Once);
            Assert.Equal("Index", vr.ActionName);
        }
Example #4
0
        public async Task <IActionResult> Create(SaleManagementDTO sale)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    sale.AgentId = await _repositoryWrapper.Employee.GetUserId(User);

                    UpdateListing(sale);
                    _repositoryWrapper.Sale.CreateSale(_mapper.Map <Sale>(sale));
                    await _repositoryWrapper.SaveAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Error creating Sale: {ex}");
                }

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Addresses"] = await GetAddresses(null);

            return(View(nameof(Create), sale));
        }