//add shoe to the database public static int AddShoe(addShoe sh) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { Sho s = converters.ShoeConverter.ShoeToDAL(sh.shoe); int x; for (int i = 0; i < sh.colors.Length; i++) { x = sh.colors[i]; Color c = db.Colors.Where(c1 => c1.id_color == x).First(); s.Colors.Add(c); } db.Shoes.Add(s); db.SaveChanges(); int id = db.Shoes.Select(s1 => s1.id_shoe).Max(); return(id); } catch (Exception e) { return(0); } } }
public static int GetNumInQueue(int id_branch) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { return(db.OrdersFromStocks.Count(o => o.id_branch == id_branch && o.status == 0)); } }
public static bool AddOrderFromBranch(OrderDetails order) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { int id_cust = AddCustomerToOrder(order.email, order.phone, order.name_customer); int from_b = db.Stocks.First(s => s.id_shoe == order.id_shoe && s.size == order.size && s.color == order.color).id_branch; db.OrdersFromBranches.Add( new OrdersFromBranch { id_shoe = order.id_shoe, to_branch = order.to_branch, from_branch = from_b, id_cust = id_cust, size = order.size, color = order.color, order_date = DateTime.Today, status = false } ); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public static int AddOrderToStock(int id_shoe, int id_branch, int size, string color, string name) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { db.OrdersFromStocks.Add( new OrdersFromStock { id_shoe = id_shoe, id_branch = id_branch, size = size, color = color, customer_name = name, status = 0 } ); Stock stock = db.Stocks.First(s => s.id_branch == id_branch && s.id_shoe == id_shoe && s.size == size && s.color == color); try { stock.available_amount--; db.SaveChanges(); return(stock.id_stock); } catch (Exception e) { stock.available_amount++; return(0); } } }
public static OrderDetails GetOrderfromBranch(int id_branch) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { OrderDetails order = new OrderDetails(); OrdersFromBranch order_from = db.OrdersFromBranches.First(o => o.from_branch == id_branch && o.status == false); CustomersToOrder cust = db.CustomersToOrders.First(c => c.id_customer == order_from.id_cust); order.id_shoe = order_from.id_shoe; order.color = order_from.color; order.size = (Int32)order_from.size; order.name_customer = cust.name_customer; order.picture = db.Shoes.First(s => s.id_shoe == order_from.id_shoe).picture; order_from.status = true; order.phone = cust.phone; order.email = cust.email; order.order_id = order_from.id_order; order.order_date = order_from.order_date.ToString(); db.SaveChanges(); return(order); } catch (Exception e) { return(null); } } }
//get shoe image name by id's shoe public static string GetImageById(int id) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { string img = db.Shoes.First(s => s.id_shoe == id).picture; return(img); } }
//function to get a branches's id by name public static int GetIdBranchByName(string name) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { int id = db.Branches.First(b => b.name_branch == name).id_branch; return(id); } }
public static string GetBranchNameById(int id) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { string x = db.Branches.First(b => b.id_branch == id).name_branch; return(x); } }
public static List <string> GetColorsById(int id) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { Sho s = db.Shoes.First(sh => sh.id_shoe == id); return(s.Colors.Select(sh => sh.color1).ToList()); } }
//check if shoe exist in stock that meets constraints by the parameters public static bool IsFoundInStock(int id_shoe, int id_branch, int size, string color) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { return(db.Stocks.Any(s => s.id_branch == id_branch && s.id_shoe == id_shoe && s.size == size && s.color == color && s.available_amount > 0)); } }
public static List <string> GetTypes() { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { List <string> types = new List <string>(); types = db.ShoeDescriptions.Select(s => s.name_description).ToList(); return(types); } }
//function to get all the branches's name public static string[] GetAllBranches() { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { int cnt = db.Branches.Count(); string[] branches = new string[cnt]; branches = db.Branches.Select(s => s.name_branch).ToArray(); return(branches); } }
public static int AddCustomerToOrder(string mail, string phone, string name) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { CustomersToOrder cust = new CustomersToOrder(); cust.email = mail; cust.phone = phone; cust.name_customer = name; db.CustomersToOrders.Add(cust); db.SaveChanges(); int x = cust.id_customer; return(x); } }
public static List <ColorBL> GetColors() { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { List <ColorBL> colors = new List <ColorBL>(); return(db.Colors.ToList().Select(c => { ColorBL color = new ColorBL(); color.color = c.color1; color.id_color = c.id_color; return color; }).ToList()); } }
public static int[] GetSizes() { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { Sho sh = new Sho(); int fromsize = 34; int tosize = 42; int[] size = new int[tosize - fromsize + 1]; for (int i = 0; i < size.Length; i++) { size[i] = fromsize++; } return(size); } }
public static List <branchDetails> GetBranchByShoe(int idshoe, int size, string color) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { var list = db.Stocks.Where(s => s.id_shoe == idshoe && s.size == size && s.color == color && s.available_amount > 0).Select(s => s.id_branch).ToList(); List <Branch> branches = new List <Branch>(); foreach (var item in list) { Branch b = db.Branches.First(a => a.id_branch == item); branches.Add(b); } return(branches.Select(b => converters.branchConverter.ConvertToBranchDTO(b)).ToList()); } }
//get sizes of specific shoe by id public static int[] GetSizesById(int id) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { Sho s = db.Shoes.First(sh => sh.id_shoe == id); int from_size = s.from_size.Value; int to_size = s.to_size.Value; int[] sizes = new int[to_size - from_size + 1]; for (int i = 0; i < sizes.Length; i++) { sizes[i] = from_size++; } return(sizes); } }
//get al the details of specific shoe by id public static shoeDetails GetDetailsById(int id) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { int idBranch = 1; Sho s = db.Shoes.First(sh => sh.id_shoe == id); shoeDetails shoe = new shoeDetails(); //set img shoe.img = s.picture; //set sizes int from_size = s.from_size.Value; int to_size = s.to_size.Value; int[] sizes = new int[to_size - from_size + 1]; for (int i = 0; i < sizes.Length; i++) { sizes[i] = from_size++; } shoe.sizes = sizes; //set coloers shoe.colors = s.Colors.Select(sh => sh.color1).ToList().ToArray(); //set price shoe.price = Int32.Parse(s.price.ToString()); //find sale try { List <Sale> l = db.Stocks.First(s1 => s1.id_shoe == id && s1.id_branch == idBranch).Sales.ToList(); Sale minSale = l.OrderBy(s2 => s2.precent_sale).First(s3 => s3.start_date <= DateTime.Now && s3.end_date >= DateTime.Now); shoe.salePrice = (double)(shoe.price * (1 - minSale.precent_sale)); shoe.saleName = minSale.description_sale; } catch (Exception e) { shoe.salePrice = shoe.price; shoe.saleName = "no sale now"; } return(shoe); } catch (Exception e) { return(null); } } }
public static bool AddMoadonCustomer(MoadonCustomerDTO customer) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { MoadonCustomer m = converters.MoadonCustomerConverter.ConvertMoadonCustomerToDAL(customer); // db.MoadonCustomers.Add(m); // db.SaveChanges(); var fromAddress = new MailAddress("*****@*****.**", "Shoes-Time"); var toAddress = new MailAddress(customer.email, "To Name"); const string fromPassword = "******"; const string subject = "Welcome to Shoes Time"; string body = $" Hi { customer.f_name} { customer.l_name} You have successfully joined our club card. \n " + $"We hope meet you again soon \n Thanks "; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) smtp.Send(message); return(true); } catch (Exception e) { return(false); } } }
public static int IsEmployee(string id_emp, string pass) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { if (db.Employees.Any(e => e.password == pass && e.id_employee == id_emp)) { if (db.Employees.First(e => e.password == pass && e.id_employee == id_emp).is_manager == true) { int id = db.Employees.First(e => e.password == pass).employee_num; return(db.Branches.First(b => b.manager_id == id).id_branch); } else { return(0); } } return(-1); } }
//get shoes that meets constraints by the parameters public static ShoeDTO[] GetShoesByCategory(int size, int color, int kind, string desc, int max_price) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { List <Sho> list = new List <Sho>(); List <Sho> FinalList = new List <Sho>(); list = db.Shoes.Where(s => s.from_size <= size && s.to_size >= size && s.kind == kind && s.price <= max_price).ToList(); foreach (var shoe in list) { if (shoe.Colors.Any(s => s.id_color == color) && shoe.ShoeDescriptions.Any(s => s.name_description == desc)) { FinalList.Add(shoe); } } return(converters.ShoeConverter.ShoeListToDTO(FinalList).ToArray()); } }
public static branchDetails[] GetBranchesByShoe(int id_shoe, int size, string color) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { List <Stock> stock_list = new List <Stock>(); List <Branch> branch_list = new List <Branch>(); List <Stock> stock = new List <Stock>(); stock = db.Stocks.Where(s => s.id_shoe == id_shoe).ToList(); stock_list = db.Stocks.Where(s => s.id_shoe == id_shoe && s.size == size && s.color == color).ToList(); stock_list = stock_list.Distinct().ToList(); foreach (var stock_item in stock_list) { branch_list.Add( db.Branches.First(b => b.id_branch == stock_item.id_branch)); } return(converters.branchConverter.BranchListToDTO(branch_list).ToArray()); } }
public static OrderDetails GetOrderFromStock(int id_branch) { using (DB_shoesEntities5 db = new DB_shoesEntities5()) { try { OrderDetails order = new OrderDetails(); OrdersFromStock order_from = db.OrdersFromStocks.First(o => o.id_branch == id_branch && o.status == 0); order.id_shoe = order_from.id_shoe; order.color = order_from.color; order.size = (Int32)order_from.size; order.name_customer = order_from.customer_name; order.picture = db.Shoes.First(s => s.id_shoe == order_from.id_shoe).picture; order_from.status = 1; db.SaveChanges(); return(order); } catch (Exception e) { return(null); } } }