Example #1
0
        private static void SeedInquiries(CompanyDbContext companyDb, out IEnumerable <Inquiry> inquiries)
        {
            var company = companyDb.Companies.Skip(1).FirstOrDefault();

            if (company == null)
            {
                throw new ArgumentNullException(
                          "company",
                          "Accounting module must be seeded first. Make sure the even CompaniesCreated is triggered and at least two companies are seeded.");
            }

            if (employees == null || employees.Count() < 2)
            {
                throw new ArgumentNullException(
                          "employees",
                          "Run SeedCompanyEmployees() first and make sure at least two Employees are seeded.");
            }

            var ivan    = employees.First();
            var maria   = employees.Skip(1).First();
            var inquiry = Inquiry.Create("Offer for part Electrical - Apartment Complex", ivan.Id, company.Id);

            inquiry.AddAssignee(maria.Id);
            inquiry.AddInfoRequest("We need the electrical plans to make offer.", maria.Id);

            inquiries = new List <Inquiry>()
            {
                inquiry
            };

            companyDb.Inquiries.AddRange(inquiries);
        }
Example #2
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(await CreateViewModel.ReBuildAsync(model, this.CompanyWorkData, this.Mapper)));
            }

            // The current Inquiry is received by the current user.
            var currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var currentUser   = await this.CompanyWorkData.Users.FindAsync(x => x.Id == currentUserId);

            if (currentUser.FirstOrDefault().Employee.Id == null)
            {
                ModelState.AddModelError(string.Empty, $"Only company employees can create Inquiries!");
                return(View(await CreateViewModel.ReBuildAsync(model, this.CompanyWorkData, this.Mapper)));
            }

            var inquiry = Inquiry.Create(model.Description, currentUser.FirstOrDefault().Employee.Id, model.CustomerId);

            inquiry.AddAssignees(model.AssigneesIds);
            inquiry.AddAttachments(model.Attachments);

            this.CompanyWorkData.Inquiries.Add(inquiry);
            await this.CompanyWorkData.CompleteAsync();

            return(RedirectToAction(nameof(Filter)));
        }
        public async Task <Guid> CreateInquiry(Guid productId)
        {
            var product = await _productRepository.GetProduct(productId).ConfigureAwait(false);

            var inquiry = Inquiry.Create(product);
            await _inquiryRepository.Save(inquiry).ConfigureAwait(false);

            return(inquiry.Id);
        }
Example #4
0
        public void ShouldAddNewOrderLine_WhenItemDoesNotExist()
        {
            // arrange
            var product = Product.Create("Test Name", 100);

            // act
            var sut = Inquiry.Create(product);

            // assert
            Assert.AreEqual(expected: 1, sut.OrderLines.Count);
            Assert.AreEqual(expected: product.Id, sut.OrderLines[0].Item.Id);
        }
Example #5
0
        public void ShouldDesignateCustomer()
        {
            // arrange
            var product  = Product.Create("Test Name", 100);
            var sut      = Inquiry.Create(product);
            var customer = Customer.Create("*****@*****.**");

            // act
            sut.DesignateCustomer(customer);

            // assert
            Assert.IsNotNull(sut);
            Assert.AreEqual(expected: "*****@*****.**", actual: sut.Customer.Email);
        }
Example #6
0
        public void ShouldReplaceOrderLine_WhenItemDoesExist_IncrementByOne()
        {
            // arrange
            var product = Product.Create("Test Name", 100);
            var sut     = Inquiry.Create(product);

            // act
            sut.AddProduct(product);

            // assert
            Assert.AreEqual(expected: 1, sut.OrderLines.Count);
            Assert.AreEqual(expected: product.Id, sut.OrderLines[0].Item.Id);
            Assert.AreEqual(expected: 2, sut.OrderLines[0].Amount);
        }
Example #7
0
        public void ShouldReturnTheTotalOfTheOrder()
        {
            // arrange
            var product = Product.Create("Product One", 100);
            var sut     = Inquiry.Create(product);

            sut.AddProduct(product, 7);

            var productExpensive = Product.Create("My expensive product!", 200000);

            sut.AddProduct(productExpensive);

            // act
            var result = sut.GetTotal();

            // assert
            Assert.AreEqual(expected: 200800, actual: result);
        }