public bool Addshoppingcart() { OrderBL obl1 = new OrderBL(); var listorders = obl1.GetAllOrderByIDUser(id); Orders order = new Orders(); order.user = new User(); order.shoesList = new List <Shoes>(); int b = listorders.FindIndex(x => x.Order_status == 0); if (b != -1) { var shoes = sbl.GetShoesById(sh_id); int amount = 0; int amountshp = 0; foreach (var or in listorders) { if (or.Order_status == 0) { var detail2 = obl1.GetOrderDetailsByID(or.Order_id); foreach (var shoess in detail2.shoesList) { if (shoess.Shoes_id == sh_id) { amountshp = shoess.Amount; } } } } while (true) { Console.Write("Input amount : "); try{ amount = Convert.ToInt32(Console.ReadLine()); if ((amount > shoes.Amount && shoes.Amount - amountshp == 0) || (amount == shoes.Amount - amountshp && shoes.Amount - amountshp == 0)) { Console.WriteLine("Quantity no longer please put another product .. !"); Console.ReadLine(); break; } else if (amount < 0) { throw new valueexception("Please enter a valid ,"); } else if (amount > shoes.Amount - amountshp) { throw new valueexception("Not enough quantity , please re-enter ,"); } else if (0 < amount && amount < shoes.Amount - amountshp) { break; } } catch (valueexception e) { Console.Write(e.Message); continue; }catch { Console.Write("Please enter a valid ,"); continue; } } int dem = 0; foreach (var or in listorders) { if (or.Order_status == 0) { var detail = obl1.GetOrderDetailsByID(or.Order_id); foreach (var shoess in detail.shoesList) { if (shoess.Shoes_id == sh_id) { obl1.updateAmount(amount, shoess.Shoes_id); dem = 1; } else if (shoes.Shoes_id != sh_id) { dem = 0; } } } } if (dem == 0) { Console.WriteLine("Add in shopping cart: " + (obl1.InsertShoppingCarrt(listorders[b].Order_id, sh_id, amount, shoes.Price, 0) ? "completed!" : "not complete!")); Console.ReadLine(); Displaylistshoes(); } Console.WriteLine("Add in shopping cart completed !"); Console.ReadLine(); Displaylistshoes(); } else if (b == -1) { order.user.User_id = id; order.Order_status = 0; order.shoesList.Add(sbl.GetShoesById(sh_id)); var shoes = sbl.GetShoesById(sh_id); int amount; while (true) { Console.Write("Input amount : "); try{ amount = Convert.ToInt32(Console.ReadLine()); if ((amount > shoes.Amount && shoes.Amount == 0) || (amount == shoes.Amount && shoes.Amount == 0)) { Console.WriteLine("Quantity no longer please put another product .. !"); Console.ReadLine(); break; } else if (amount < 0) { throw new valueexception("Please enter a valid,"); } else if (amount > shoes.Amount) { throw new valueexception("Not enough quantity , please re-enter,"); } else if (0 < amount && amount < shoes.Amount) { break; } } catch (valueexception e) { Console.Write(e.Message); continue; }catch { Console.Write("Please enter a valid :"); continue; } } order.shoesList[0].Amount = amount; var userdt = ubl.GetUserByid(id); order.Address = userdt.Address; order.phone = userdt.Phone; Console.WriteLine("Add in shopping cart: " + (obl1.AddShppingCart(order) ? "completed!" : "not complete!")); Console.ReadLine(); Displaylistshoes(); } return(true); }
public bool CreateOrder() { OrderBL obl = new OrderBL(); UserBl ubl = new UserBl(); Orders orders = new Orders(); orders.shoesList = new List <Shoes>(); orders.Order_status = 1; orders.user = new User(); orders.user.User_id = id; orders.shoesList.Add(sbl.GetShoesById(sh_id)); var getshoes = sbl.GetShoesById(sh_id); while (true) { try { Console.Write("Input Amount: "); int amount1 = Convert.ToInt32(Console.ReadLine()); if ((amount1 > getshoes.Amount && getshoes.Amount == 0) || (amount1 == getshoes.Amount && getshoes.Amount == 0)) { Console.WriteLine("Quantity no longer please put another product .. !"); Console.ReadLine(); Displaylistshoes(); } if (amount1 > getshoes.Amount && getshoes.Amount > 0) { Console.WriteLine("Quantity in stock : {0}", getshoes.Amount); throw (new valueexception("Not enough quantity , please re-enter: ")); } else if (0 < amount1 || amount1 <= getshoes.Amount) { orders.shoesList[0].Amount = amount1; break; } } catch (valueexception e) { Console.Write(e.Message); continue; } catch { Console.Write("Please enter a valid :"); continue; } break; } Console.Write("Do you want to use the number of phone and current address to get unsigned ? :"); string chon = Console.ReadLine(); if (chon == "n") { Console.WriteLine("Please enter phone number and address! "); while (true) { Console.Write("-Enter recipient address :"); orders.Address = Console.ReadLine(); if (orders.Address != " ") { break; } } Console.Write("-Enter the recipient's phone number :"); while (true) { orders.phone = Console.ReadLine(); if (IsValidString(orders.phone) == true) { break; } else { Console.Write("Please re-enter the recipient's phone number correctly : "); } } } else { var userdt = ubl.GetUserByid(id); orders.Address = userdt.Address; orders.phone = userdt.Phone; } Console.WriteLine("Create Order: " + (obl.CreateOrder(orders) ? "completed!" : "not complete!")); Console.ReadLine(); Displaylistshoes(); return(true); }