public void AddNewOrderWithCustomerId_AffectedRowsNumberReturned() { //Arrange IOrderRepository repository = new OrderRepository(connectionString, sqlConnection); int expected = 1; //Act var actual = repository.AddNewOrder("CHOPS"); //Assert NUnit.Framework.Assert.AreEqual(actual, expected); }
public void DeleteOrder_AffectedRowsNumberReturned() { //Arrange IOrderRepository repository = new OrderRepository(connectionString, sqlConnection); repository.AddNewOrder("LILAS"); repository = new OrderRepository(connectionString, sqlConnection); int lastOrderId = repository.GetLastOrderId(); int expected = 1; //Act repository = new OrderRepository(connectionString, sqlConnection); var actual = repository.DeleteOrder(lastOrderId); //Assert NUnit.Framework.Assert.AreEqual(actual, expected); }
public IActionResult CreateOrder(AddOrderDTO newAddOrderDTO) { var newOrder = new Order { Id = newAddOrderDTO.Id, CustomerId = newAddOrderDTO.CustomerId, IsComplete = newAddOrderDTO.IsComplete, OrderTotal = newAddOrderDTO.OrderTotal, BillingAddressId = newAddOrderDTO.BillingAddressId, ShippingAddressId = newAddOrderDTO.ShippingAddressId, PaymentId = newAddOrderDTO.PaymentId }; var repo = new OrderRepository(); var orderThatGotCreated = repo.AddNewOrder(newAddOrderDTO); return(Created($"api/orders/{orderThatGotCreated.Id}", orderThatGotCreated)); }
public IHttpActionResult AddNewOrder(Order order) { var orderId = _orderRepository.AddNewOrder(order); if (order.Type == Type.Incoming) { if (order.SupplierId == null) { return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden))); } var supplierMail = _supplierRepository.GetSupplierDetails(order.SupplierId.Value, order.CompanyId).Email; if (supplierMail == null) { return(Ok(true)); } var mail = new MailMessage(); var smtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(supplierMail); mail.Subject = "Nova narudžba od tvrtke " + _companyRepository.GetCompanyById(order.CompanyId).Name; mail.Body = "Molimo Vas da kliknete na link kako bi potvrdili da ćete započeti s narudžbom: " + "<form method=\"post\" action=\"https://waremaster.azurewebsites.net/api/orders/confirmincoming\" " + "class=\"inline\">\r\n <input type=\"hidden\" name=\"orderId\" value=\"" + orderId + "\">\r\n " + "<button type=\"submit\" name=\"submit_param\" value=\"submit_value\" " + "class=\"link-button\">\r\nPotvrdi narudžbu\r\n </button>\r\n</form>"; mail.IsBodyHtml = true; smtpServer.Port = 587; smtpServer.Credentials = new NetworkCredential("*****@*****.**", "Skladospodar00"); smtpServer.EnableSsl = true; smtpServer.Send(mail); } return(Ok(true)); }
protected void btnAddNewOrder_Click(object sender, EventArgs e) { string sqlConnection = section["SqlProvider"]; IOrderRepository repository = new OrderRepository(connectionString, sqlConnection); int result = repository.AddNewOrder("TOMSP", DateTime.Now, DateTime.Now); }
public static void PlaceOrder(CustomerRepository customers, OrderRepository orders, StoreRepository stores, ProductRepository products) { Console.WriteLine("Enter Your First Name:"); String firstName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(firstName)) { Console.WriteLine("\nInvalid input, please provide a real first name"); Console.WriteLine("Enter Your First Name:"); firstName = Console.ReadLine(); } Console.WriteLine("\nEnter Your Last Name:"); String lastName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(lastName)) { Console.WriteLine("\nInvalid input, please provide a real last name"); Console.WriteLine("Enter Your Last Name:"); lastName = Console.ReadLine(); } Customer customer = customers.GetCustomerByFirstAndLastName(firstName, lastName); if (customer != null) { List <Store> allStores = stores.GetAllStores(); if (allStores.Any()) { Console.WriteLine("\nStores available:"); for (int i = 0; i < allStores.Count(); i++) { Console.WriteLine($"{i}) {allStores[i].StoreName}"); } Console.WriteLine("\nType number corresponding to store you want to place order at:"); int storeChoice = (int)char.GetNumericValue(Console.ReadKey().KeyChar); while (storeChoice < 0 || storeChoice > allStores.Count() - 1) { Console.WriteLine("\nInvalid option, please try again"); Console.WriteLine("\nType number corresponding to store you want to place order at:"); storeChoice = (int)char.GetNumericValue(Console.ReadKey().KeyChar); } Console.WriteLine("\n"); Store store = allStores[storeChoice]; Console.WriteLine("\nAvailable Products:"); if (store.StoreInventory.Any()) { foreach (var item in store.StoreInventory) { IProduct product = products.GetProductById(item.Key); Console.WriteLine(" {0,-30}{1,-30}", $"Name:{product.ProductName}", $"Available:{item.Value}"); } Console.WriteLine("\n"); } else { Console.WriteLine("\nNo products available for purchase. Returning to main menu...\n"); return; } Console.WriteLine("Enter name of Product you want to add to cart or type 'Done' if done ordering: "); String productName = Console.ReadLine(); IProduct product1 = null; Dictionary <int, int> cart = new Dictionary <int, int>(); decimal total = 0.0M; while (productName != "Done") { while (string.IsNullOrWhiteSpace(productName)) { Console.WriteLine("\nInvalid input. Product does not exist, please provide product name from the list exactly as it appears"); Console.WriteLine("Enter name of Product you want to add to cart or type 'Done' if done ordering: "); productName = Console.ReadLine(); if (productName == "Done") { break; } } if (productName == "Done") { break; } product1 = products.GetProductByName(productName); if (product1 == null || !store.StoreInventory.ContainsKey(product1.ProductId)) { Console.WriteLine("\nInvalid input. Product does not exist, please provide product name from the list exactly as it appears"); Console.WriteLine("Enter name of Product you want to add to cart or type 'Done' if done ordering: "); productName = Console.ReadLine(); continue; } int amount = 0; Console.WriteLine("\nHow many would you like to add to cart? "); try { amount = Int32.Parse(Console.ReadLine()); } catch (FormatException) { amount = -1; } catch (ArgumentNullException) { amount = -1; } catch (OverflowException) { amount = -1; } while (amount < 0 || amount > store.StoreInventory[product1.ProductId]) { Console.WriteLine($"\nInvalid amount. Make sure amount is a valid positive integer, inlcudes no white spaces and its not higher than current available stock ({store.StoreInventory[product1.ProductId]})"); Console.WriteLine("\nHow many would you like to add to cart? "); try { amount = Int32.Parse(Console.ReadLine()); } catch (FormatException) { amount = -1; } catch (ArgumentNullException) { amount = -1; } catch (OverflowException) { amount = -1; } } cart.Add(product1.ProductId, amount); total += product1.Price * amount; Console.WriteLine("\nItem added to cart succesfully\n"); Console.WriteLine("Enter name of Product you want to add to cart or type 'Done' if done ordering: "); productName = Console.ReadLine(); product1 = null; } if (cart.Any()) { Console.WriteLine("\nDo you wish to place order Y/N?"); char YesOrNo = Console.ReadKey().KeyChar; Console.WriteLine("\n"); while (YesOrNo != 'Y' && YesOrNo != 'N') { Console.WriteLine("\nInvalid input please type 'Y' for Yes and 'N' for No"); YesOrNo = Console.ReadKey().KeyChar; Console.WriteLine("\n"); } if (YesOrNo == 'Y') { Order order = new Order(store.StoreId, customer.CustomerId, DateTime.Now, total, cart); stores.PlaceOrder(store.StoreId, cart); orders.AddNewOrder(order); Console.WriteLine("\nOrder placed succesfully\n"); } else { Console.WriteLine("\nOrder Canceled. Returning to main menu...\n"); } } else { Console.WriteLine("\nYour cart is empty. Returning to main menu...\n"); } } else { Console.WriteLine("\nNo Stores in database yet, sorry :(\n"); } } else { Console.WriteLine("\nCustomer not found. Please register first to place an order. Returning to main menu...\n"); } }