public void Test_GetAll_ProductFormat() { var repository = new ProductFormatRepository(); var product = repository.GetAll(); Assert.IsTrue(product.Count() == 0); }
public void ProductFormat_Create() { var repository = new ProductFormatRepository(); //ProductFormat productFormat = new ProductFormat() //{ // ProductID = 1, // Color = "紅色", // Size = "L", // StockQuantity = 50 //}; //repository.Create(productFormat); //ProductFormat productFormat1 = new ProductFormat() //{ // ProductID = 1, // Color = "藍色", // Size = "M", // StockQuantity = 30 //}; //repository.Create(productFormat1); //ProductFormat productFormat2 = new ProductFormat() //{ // ProductID = 2, // Color = "黑色", // Size = "S", // StockQuantity = 45 //}; //repository.Create(productFormat2); var productFormats = repository.GetAll(); Assert.IsTrue(productFormats.Count() > 0); }
public JsonResult CreateProductFormat(int ProductID, string Size, string Color, string StockQuantity, string Image) { if (string.IsNullOrWhiteSpace(Size) || string.IsNullOrWhiteSpace(Color) || string.IsNullOrWhiteSpace(StockQuantity) || string.IsNullOrWhiteSpace(Image)) { return(Json("填空區不可為空白")); } else { if (Regex.Match(StockQuantity, @"^\+?[1-9][0-9]*$").Success) { ProductFormatRepository repository = new ProductFormatRepository(); ProductFormat productFormat = new ProductFormat() { ProductID = ProductID, Size = Size, Color = Color, StockQuantity = int.Parse(StockQuantity), Image = Image }; repository.Create(productFormat); return(Json("")); } else { return(Json("庫存填寫無效")); } } }
public void Test_FindByID_ProductFormat() { var repository = new ProductFormatRepository(); var product = repository.FindById(1); Assert.IsNotNull(product); }
public ActionResult Order() { OrderDetailsRepository orderDetailsRepository = new OrderDetailsRepository(); ProductFormatRepository productFormatRepository = new ProductFormatRepository(); ProductRepository productRepository = new ProductRepository(); List <Detail> details = new List <Detail>(); var orderDetails = orderDetailsRepository.GetAll(); foreach (var item in orderDetails) { var productFormat = productFormatRepository.FindById(item.ProductFormatID); var product = productRepository.FindById(productFormat.ProductID); Detail detail = new Detail() { OrderID = item.OrderID, ProductID = productFormat.ProductID, ProductFormatID = item.ProductFormatID, ProductName = product.ProductName, Color = productFormat.Color, Size = productFormat.Size, Quantity = item.Quantity, UnitPrice = item.UnitPrice }; details.Add(detail); } ViewBag.Detail = details; return(View()); }
public JsonResult ShoppingCart(int ProductFormatID) { ProductFormatRepository repository = new ProductFormatRepository(); var result = repository.FindById(ProductFormatID); return(Json(result)); }
public ActionResult ProductFormatEdit(int ProductID) { ProductFormatRepository repository = new ProductFormatRepository(); ViewBag.ProductFormat = repository.FindByProductID(ProductID); ViewBag.NowProductID = ProductID; return(View()); }
public ActionResult ShoppingCart() { var cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie == null) { ViewBag.IsAuthenticated = false; return(View()); } var ticket = FormsAuthentication.Decrypt(cookie.Value); ViewBag.IsAuthenticated = true; ViewBag.UserName = ticket.UserData; ShoppingCartRepository repository = new ShoppingCartRepository(); var Data = repository.FindByMemberID(ticket.UserData); List <ShoppingCartInformation> shoppingCarts = new List <ShoppingCartInformation>(); decimal TotalPrice = 0; foreach (var item in Data) { ProductRepository productRepository = new ProductRepository(); var productInformation = productRepository.FindById(item.ProductID); ProductFormatRepository productFormatRepository = new ProductFormatRepository(); var productFormatInformation = productFormatRepository.FindById(item.ProductFormatID); ShoppingCartInformation shoppingCart = new ShoppingCartInformation() { ShoppingCartID = item.ShoppingCartID, ProductFormatID = item.ProductFormatID, ProductName = productInformation.ProductName, UnitPrice = productInformation.UnitPrice, Color = productFormatInformation.Color, Image = productFormatInformation.Image, Size = productFormatInformation.Size, Quantity = item.Quantity }; TotalPrice += productInformation.UnitPrice * item.Quantity; shoppingCarts.Add(shoppingCart); } ViewBag.ShoppingCart = shoppingCarts; ViewBag.TotalPrice = TotalPrice; return(View()); }
public void ProductFormat_Update() { var repository = new ProductFormatRepository(); ProductFormat productFormat = new ProductFormat() { ProductFormatID = 1, ProductID = 1, Color = "紅色", Size = "2L", StockQuantity = 40 }; repository.Update(productFormat); var productFormats = repository.FindById(1); Assert.IsTrue(productFormats.Size == "2L"); }
public JsonResult Order(string name, string phone, string address, string memberID, decimal totalPrice) { if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(phone) || string.IsNullOrWhiteSpace(address)) { return(Json("填空區不可有空白")); } else { if (Regex.Match(name, @"[\u3000-\u9FA5\x20]{2,4}").Success) { if (Regex.Match(phone, @"(\(?\d{3,4}\)?)?[\s-]?\d{7,8}[\s-]?\d{0,4}").Success) { ShoppingCartRepository shoppingCartRepository = new ShoppingCartRepository(); OrdersRepository ordersRepository = new OrdersRepository(); EmployeesRepository employeesRepository = new EmployeesRepository(); ProductFormatRepository productFormatRepository = new ProductFormatRepository(); OrderDetailsRepository orderDetailsRepository = new OrderDetailsRepository(); ProductRepository productRepository = new ProductRepository(); var employees = employeesRepository.GetAll(); var randomNumber = new Random().Next(0, employees.Count()); Orders orders = new Orders() { EmployeeID = employees.ElementAt(randomNumber).EmployeeID, MemberID = memberID, ShipName = name, ShipAddress = address, ShipPhone = phone, OrderDate = DateTime.Now, Status = "未送貨", TotalPrice = totalPrice }; ordersRepository.Create(orders); Procedure.Procedure procedure = new Procedure.Procedure(); var orderTempID = procedure.FindOrderID(memberID); var shoppingCart = shoppingCartRepository.FindByMemberID(memberID); Stack <OrderDetails> orderData = new Stack <OrderDetails>(); orderData.Clear(); foreach (var item in shoppingCart) { if (productFormatRepository.FindById(item.ProductFormatID).StockQuantity - item.Quantity >= 0) { OrderDetails orderDetails = new OrderDetails() { OrderID = orderTempID.OrderID, ProductFormatID = item.ProductFormatID, Quantity = item.Quantity, UnitPrice = productRepository.FindById(item.ProductID).UnitPrice }; orderData.Push(orderDetails); } else { var productFormatTemp = productFormatRepository.FindById(item.ProductFormatID); var productTemp = productRepository.FindById(productFormatTemp.ProductID); return(Json("產品:" + productTemp.ProductName + Environment.NewLine + "顏色:" + productFormatTemp.Color + Environment.NewLine + "尺寸:" + productFormatTemp.Size + Environment.NewLine + "剩餘數量:" + productFormatTemp.StockQuantity + Environment.NewLine + "請重新下訂!")); } } foreach (var orderItem in orderData) { orderDetailsRepository.Create(orderItem); } shoppingCartRepository.DeleteByMemberId(memberID); return(Json("下訂成功")); } else { return(Json("電話格式有誤")); } } else { return(Json("姓名不符合格式")); } } }