public void GetOrderCustomerDetails() { // given var resources = new Resources(); const int orderId = 123; var responsemodel = new OrderCustomerDetailModel { CustomerName = "Test Costumer", CustomerDetails = "This is some long customer description", CustomerContactNo = "0214472215", CustomerAccountNo = "DC1122", CustomerMobileNo = "0728543333", CustomerEmailAddress = "*****@*****.**", ContactAdded = true, ContactName = "Contraption", ContactNo = "0214472215", ContactEmailAddress = "*****@*****.**", CustomerId = 1, ContactId = 1, OrderId = 245, OrderNo = "MOQ001", OrderCreateDate = DateTime.Now }; var requestmodel = new GetOrderCustomerDetailRequestModel { OrderId = orderId }; resources.MockApiCaller.AddMockResponse("WebApi:Orders:GetOrderCustomerDetails", requestmodel, responsemodel); // when var result = resources.Controller.GetOrderCustomerDetails(orderId) as JsonResult; // then Assert.IsNotNull(result); var model = (OrderCustomerDetailModel)result.Value; Assert.AreEqual(responsemodel.OrderId, model.OrderId); Assert.AreEqual(responsemodel.OrderNo, model.OrderNo); Assert.AreEqual(responsemodel.OrderCreateDate, model.OrderCreateDate); Assert.AreEqual(responsemodel.CustomerName, model.CustomerName); Assert.AreEqual(responsemodel.CustomerId, model.CustomerId); Assert.AreEqual(responsemodel.CustomerMobileNo, model.CustomerMobileNo); Assert.AreEqual(responsemodel.CustomerEmailAddress, model.CustomerEmailAddress); Assert.AreEqual(responsemodel.CustomerDetails, model.CustomerDetails); Assert.AreEqual(responsemodel.CustomerContactNo, model.CustomerContactNo); Assert.AreEqual(responsemodel.CustomerAccountNo, model.CustomerAccountNo); Assert.AreEqual(responsemodel.ContactId, model.ContactId); Assert.AreEqual(responsemodel.ContactName, model.ContactName); Assert.AreEqual(responsemodel.ContactNo, model.ContactNo); Assert.AreEqual(responsemodel.ContactEmailAddress, model.ContactEmailAddress); Assert.AreEqual(responsemodel.ContactAdded, model.ContactAdded); }
public void ConfirmOrderCustomer_Load() { // given var resources = new Resources(); var orderId = 1234; var requestModel = new GetOrderCustomerDetailRequestModel { OrderId = orderId }; var responseModel = new OrderCustomerDetailModel { OrderId = orderId, CustomerName = "Test Costume", CustomerDetails = "This is some long customer description", CustomerContactNo = "0214472215", CustomerAccountNo = "DC1122", CustomerMobileNo = "0728543333", CustomerEmailAddress = "*****@*****.**", ContactAdded = false, ContactName = "Contraption", ContactNo = "0214472215", ContactEmailAddress = "*****@*****.**", }; resources.MockApiCaller.AddMockResponse("WebApi:Orders:GetOrderCustomerDetails", requestModel, responseModel); // when var result = resources.Controller.ConfirmOrderCustomer(new AddCustomerOrderModel { OrderId = orderId }) as ViewResult; // then Assert.IsNotNull(result); Assert.AreEqual("ConfirmOrderCustomer", result.ViewName); var model = (OrderCustomerDetailModel)result.Model; Assert.AreEqual(responseModel.CustomerName, model.CustomerName); Assert.AreEqual(responseModel.CustomerDetails, model.CustomerDetails); Assert.AreEqual(responseModel.CustomerContactNo, model.CustomerContactNo); Assert.AreEqual(responseModel.CustomerAccountNo, model.CustomerAccountNo); Assert.AreEqual(responseModel.CustomerMobileNo, model.CustomerMobileNo); Assert.AreEqual(responseModel.CustomerEmailAddress, model.CustomerEmailAddress); Assert.AreEqual(responseModel.ContactAdded, model.ContactAdded); Assert.AreEqual(responseModel.ContactName, model.ContactName); Assert.AreEqual(responseModel.ContactNo, model.ContactNo); Assert.AreEqual(responseModel.ContactEmailAddress, model.ContactEmailAddress); }
public OrderQuotationViewModel GetOrderQuote([FromBody] GetOrderQuoteRequestModel requestModel) { var companyProfile = new CompanyProfileModel(); var customerDetails = new OrderCustomerDetailModel(); var orderDetails = new OrderDetailModel(); var addressDetails = new AddressDetailsModel(); var existingCompany = Context.CompanyProfiles.Include(cp => cp.BankingDetails).Include(cp => cp.Addresses).FirstOrDefault(cp => cp.CompanyProfileId == requestModel.CompanyProfileId); if (existingCompany != null) { companyProfile.DisplayName = existingCompany.DisplayName; companyProfile.RegistrationNo = existingCompany.RegistrationNo; companyProfile.TaxReferenceNo = existingCompany.TaxReferenceNo; companyProfile.TelephoneNo = existingCompany.TelephoneNo; companyProfile.EmailAddress = existingCompany.EmailAddress; if (existingCompany.Addresses.Count > 0) { companyProfile.AddressLine1 = existingCompany.Addresses[0].AddressLine1; companyProfile.AddressLine2 = existingCompany.Addresses[0].AddressLine2; companyProfile.City = existingCompany.Addresses[0].City; companyProfile.Country = existingCompany.Addresses[0].Country; companyProfile.PostalCode = existingCompany.Addresses[0].PostalCode; } if (existingCompany.BankingDetails.Count > 0) { companyProfile.BankingDetails = new BankingDetailsModel { AccountHolder = existingCompany.BankingDetails[0].AccountHolder, AccountNo = existingCompany.BankingDetails[0].AccountNo, BankName = existingCompany.BankingDetails[0].BankName, AccountType = existingCompany.BankingDetails[0].AccountType, BranchCode = existingCompany.BankingDetails[0].BranchCode, }; } } var order = Context.Orders.Include(o => o.OrderDetails).First(o => o.OrderId == requestModel.OrderId); var existingCustomer = Context.Customers.Include(c => c.Addresses).Include(c => c.ContactPeople).FirstOrDefault(c => c.CustomerId == order.CustomerId); var existingContact = existingCustomer != null?existingCustomer.ContactPeople.FirstOrDefault(cp => cp.ContactId == order.ContactId) : null; var existingAddresss = existingCustomer != null?existingCustomer.Addresses.FirstOrDefault(cp => cp.AddressDetailId == order.AddressDetailId) : null; if (existingCustomer != null) { customerDetails.OrderId = order.OrderId; customerDetails.CustomerName = existingCustomer.CustomerName; customerDetails.CustomerContactNo = existingCustomer.ContactNo; customerDetails.CustomerAccountNo = existingCustomer.AccountNo; customerDetails.CustomerDetails = existingCustomer.CustomerDetails; customerDetails.CustomerEmailAddress = existingCustomer.EmailAddress; if (existingContact != null) { customerDetails.ContactName = existingContact.ContactName; customerDetails.ContactNo = existingContact.ContactNo; customerDetails.ContactEmailAddress = existingContact.EmailAddress; } else { customerDetails.ContactName = existingCustomer.CustomerName; } if (existingAddresss != null) { addressDetails.AddressLine1 = existingAddresss.AddressLine1; addressDetails.AddressLine2 = existingAddresss.AddressLine2; addressDetails.City = existingAddresss.City; addressDetails.Country = existingAddresss.Country; addressDetails.PostalCode = existingAddresss.PostalCode; } } orderDetails.Discount = order.DiscountTotal; orderDetails.OrderNo = order.OrderNo; orderDetails.OrderId = order.OrderId; orderDetails.CreateDate = order.CreateDate; orderDetails.SubTotal = order.SubTotal; orderDetails.VatTotal = order.VatTotal; orderDetails.Total = order.OrderTotal; var salesPerson = SecurityContext.Users.FirstOrDefault(u => u.Username == order.CreateUser); if (salesPerson != null) { orderDetails.CreateUser = (salesPerson.FirstName + " " + salesPerson.LastName).Trim() != string.Empty ? (salesPerson.FirstName + " " + salesPerson.LastName) : order.CreateUser; // replace with first and last name of user } else { orderDetails.CreateUser = order.CreateUser; } var maxLineNo = order.OrderDetails.Max(o => o.LineNo); foreach (var linedetail in order.OrderDetails.Where(o => o.LineNo == maxLineNo)) { var newLineDetail = new OrderLineDetailModel { Discount = linedetail.Discount, ItemDescription = linedetail.ItemDescription, Quantity = linedetail.Quantity, UnitPrice = linedetail.UnitPrice, LineTotal = linedetail.LineTotal }; orderDetails.OrderLineDetails.Add(newLineDetail); } return(new OrderQuotationViewModel { CompanyProfile = companyProfile, CustomerDetail = customerDetails, DeliveryAddress = addressDetails, OrderTotals = orderDetails }); }