public JObject PutDelivringComplete([FromBody] OrderFullInfo ofi) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == ofi.id_order); if (torder.order_code == ofi.order_code) { torder.order_state = OrderStates.order_has_been_delivered; torder.delivery_state = 100; torder.received_datetime = DateTime.Now; db.SaveChanges(); jRes.Add(new JProperty("Error", false)); jRes.Add(new JProperty("MessageTitele", "Success")); jRes.Add(new JProperty("Message", "The delivery was successful.")); } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("MessageTitele", "Failed")); jRes.Add(new JProperty("Message", "The order code is incorrect (You will get the order code from the clients when you give them the orders).")); } return(jRes); }
public JObject PutChangeClientPassword([FromBody] Client client) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); CLIENT C1 = db.CLIENTs.FirstOrDefault(c => c.id_client == client.id_client); if (Crypto.VerifyHashedPassword(C1.password, client.password)) { try { jRes.Add(new JProperty("Error", false)); C1.password = Crypto.HashPassword(client.confirmation_code); db.SaveChanges(); } catch (Exception e) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "Connection failed.")); } } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "The password is incorrect.")); } return(jRes); }
public JObject PutDeliveryManCancelDeliverinAnOrder([FromBody] OrderFullInfo ofi) { JObject jRes = new JObject(); try { FastFoodEntities db = new FastFoodEntities(); TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == ofi.id_order); if (torder != null) { torder.id_delivery_man = null; torder.order_state = OrderStates.order_to_deliver; db.SaveChanges(); jRes.Add(new JProperty("Error", false)); jRes.Add(new JProperty("MessageTitele", "Canceled")); jRes.Add(new JProperty("Message", "Canceled.")); } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("MessageTitele", "Failed")); jRes.Add(new JProperty("Message", "Failed, try again.")); } } catch (Exception e) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("MessageTitele", "Failed")); jRes.Add(new JProperty("Message", "Failed, try again.")); } return(jRes); }
public JObject DeleteOrderContent(int id_order, int id_product) { // khasni n nsift JWT o n checkeh JObject jRes = new JObject(); try { FastFoodEntities db = new FastFoodEntities(); ORDER_CONTENT OrderC = db.ORDER_CONTENT.FirstOrDefault(oc => oc.id_order == id_order && oc.id_product == id_product); if (OrderC != null) { db.ORDER_CONTENT.Remove(OrderC); db.SaveChanges(); } jRes.Add(new JProperty("message", true)); } catch (Exception e) { jRes.Add(new JProperty("message", false)); } return(jRes); }
public JObject PutChangeDeliveryManPassword([FromBody] Delivery_man dm) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man); if (Crypto.VerifyHashedPassword(D1.password, dm.password)) { try { D1.password = Crypto.HashPassword(dm.confirmation_code); db.SaveChanges(); jRes.Add(new JProperty("Error", false)); } catch (Exception e) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "Connection failed.")); } } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "The password is incorrect.")); } return(jRes); }
public JObject PostOrderContent([FromBody] Order_content oc) { // khasni n nsift JWT o n checkeh JObject jRes = new JObject(); try { ORDER_CONTENT OC = new ORDER_CONTENT(); OC.id_order = oc.id_order; OC.id_product = oc.id_product; OC.quantity = oc.quantity; OC.price = oc.price; FastFoodEntities db = new FastFoodEntities(); db.ORDER_CONTENT.Add(OC); db.SaveChanges(); jRes.Add(new JProperty("message", true)); } catch (Exception e) { jRes.Add(new JProperty("message", false)); } return(jRes); }
public JObject PutOrderContent([FromBody] Order_content oc) { // khasni n nsift JWT o n checkeh JObject jRes = new JObject(); try { FastFoodEntities db = new FastFoodEntities(); ORDER_CONTENT OrderC = db.ORDER_CONTENT.FirstOrDefault(OC => OC.id_order == oc.id_order && OC.id_product == oc.id_product); OrderC.quantity = oc.quantity; OrderC.price = oc.price; db.SaveChanges(); jRes.Add(new JProperty("message", true)); } catch (Exception e) { jRes.Add(new JProperty("message", false)); } return(jRes); }
public bool DeleteOrder(int id_order) { // khassni nzidt JWT checking bach ghir mol l'order howa lli i9der imse7ha FastFoodEntities db = new FastFoodEntities(); TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == id_order && o.order_state == OrderStates.choosing_food); if (torder != null) { //bach n7yed lmochkil d Delete cascade List <ORDER_CONTENT> listOC = db.ORDER_CONTENT.Where(oc => oc.id_order == id_order).ToList(); listOC.ForEach(oc => db.ORDER_CONTENT.Remove(oc)); db.SaveChanges(); List <GEOLOCATION> listGeo = db.GEOLOCATIONs.Where(oc => oc.id_order == id_order).ToList(); listGeo.ForEach(g => db.GEOLOCATIONs.Remove(g)); db.SaveChanges(); db.TORDERs.Remove(torder); db.SaveChanges(); return(true); } else { return(false); } }
public JObject ClientCheckEmail([FromBody] CLIENT c) { FastFoodEntities db = new FastFoodEntities(); JObject j; try { CLIENT c1 = db.CLIENTs.FirstOrDefault(b => b.email == c.email); if (c1 == null) { j = new JObject(); j.Add(new JProperty("email_already_used", false)); j.Add(new JProperty("Error", false)); return(j); } else { j = new JObject(); j.Add(new JProperty("email_already_used", true)); j.Add(new JProperty("Error", false)); return(j); } } catch (Exception e) { j = new JObject(); j.Add(new JProperty("Error", true)); return(j); } }
public OrderFullInfo NewOrder([FromBody] Client c) { // khassni nzidt JWT checking FastFoodEntities db = new FastFoodEntities(); TORDER torder = new TORDER(); torder.order_state = OrderStates.choosing_food; torder.id_client = c.id_client; db.TORDERs.Add(torder); db.SaveChanges(); OrderFullInfo order = new OrderFullInfo(); order.id_order = torder.id_order; order.order_state = torder.order_state; order.latitude = torder.latitude; order.longitude = torder.longitude; order.order_datetime = torder.order_datetime; order.order_code = torder.order_code; order.delivery_state = torder.delivery_state; order.received_datetime = torder.received_datetime; order.id_delivery_man = torder.id_delivery_man; order.id_client = torder.id_client; order.delivery_man = new Delivery_man(); order.client = ClientDAO.GetClient(torder.id_client); return(order); }
public JObject ClientSignUp([FromBody] CLIENT c) { FastFoodEntities db = new FastFoodEntities(); JObject j; try { c.password = Crypto.HashPassword(c.password); c.photo = "client.png"; db.CLIENTs.Add(c); db.SaveChanges(); j = new JObject(); j.Add(new JProperty("Error", false)); return(j); } catch (Exception e) { j = new JObject(); j.Add(new JProperty("Error", true)); return(j); } }
public OrderFullInfo GetClientOrderFullInfoById(int id_order) { FastFoodEntities db = new FastFoodEntities(); // khasni n nsift JWT o n checkeh TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == id_order); OrderFullInfo orderFullInfo = new OrderFullInfo(); if (torder != null) { orderFullInfo.id_order = torder.id_order; orderFullInfo.order_state = torder.order_state; orderFullInfo.latitude = torder.latitude; orderFullInfo.longitude = torder.longitude; orderFullInfo.order_datetime = torder.order_datetime; orderFullInfo.order_code = torder.order_code; orderFullInfo.delivery_state = torder.delivery_state; orderFullInfo.received_datetime = torder.received_datetime; orderFullInfo.id_delivery_man = torder.id_delivery_man; orderFullInfo.id_client = torder.id_client; orderFullInfo.client = new Client() { id_client = torder.CLIENT.id_client, firstname = torder.CLIENT.firstname, lastname = torder.CLIENT.lastname, gender = torder.CLIENT.gender, email = torder.CLIENT.email, password = "", phone = torder.CLIENT.phone, photo = torder.CLIENT.photo, confirmation_code = torder.CLIENT.confirmation_code }; } if (orderFullInfo.id_delivery_man != null) { orderFullInfo.delivery_man = DeliveryManDAO.GetDeliveryMan((int)orderFullInfo.id_delivery_man); } List <Geolocation> geolocations = GeolocationDAO.GetOrderGeolocations(orderFullInfo.id_order); if (geolocations != null) { orderFullInfo.geolocations = geolocations; } List <Order_content> orderContents = OrderContentDAO.GetOrderContents(orderFullInfo.id_order); if (orderContents != null) { orderFullInfo.order_contents = orderContents; } return(orderFullInfo); }
public static List <TORDER> GetORDERsByState(string state) { FastFoodEntities db = new FastFoodEntities(); return(db.TORDERs.Where(o => o.order_state == state) .OrderBy(o => o.order_datetime) .ThenBy(o => o.CLIENT.firstname) .ThenBy(o => o.CLIENT.lastname).ToList()); }
public static List <TORDER> GetORDERsByStateAndSearch(string state, string search) { FastFoodEntities db = new FastFoodEntities(); return(db.TORDERs.Where(o => o.order_state == state) .Where(o => o.CLIENT.firstname.Contains(search) || o.CLIENT.lastname.Contains(search)) .OrderBy(o => o.order_datetime) .ThenBy(o => o.CLIENT.firstname) .ThenBy(o => o.CLIENT.lastname).ToList()); }
public static List <Order_content> GetOrderContents(int id_order) { FastFoodEntities db = new FastFoodEntities(); return(db.ORDER_CONTENT.Select(o => new Order_content() { id_order = o.id_order, id_product = o.id_product, productTitle = o.PRODUCT.title, quantity = o.quantity, price = o.price }).Where(oc => oc.id_order == id_order).OrderBy(oc => oc.productTitle).ToList()); }
public static Order_content GetOrderContent(int id_order, int id_product) { FastFoodEntities db = new FastFoodEntities(); return(db.ORDER_CONTENT.Select(o => new Order_content() { id_order = o.id_order, id_product = o.id_product, productTitle = o.PRODUCT.title, quantity = o.quantity, price = o.price }).FirstOrDefault(oc => oc.id_order == id_order && oc.id_product == id_product)); }
public static List <TORDER> GetORDERsByStateAndDate(string state, string date) { FastFoodEntities db = new FastFoodEntities(); DateTime minD = Convert.ToDateTime(date); DateTime maxD = Convert.ToDateTime(date); maxD = maxD.AddDays(1); return(db.TORDERs.Where(o => o.order_state == state && o.order_datetime >= minD && o.order_datetime < maxD) .OrderBy(o => o.order_datetime) .ThenBy(o => o.CLIENT.firstname) .ThenBy(o => o.CLIENT.lastname).ToList()); }
public static List <Geolocation> GetOrderGeolocations(int id_order) { FastFoodEntities db = new FastFoodEntities(); List <GEOLOCATION> list = db.GEOLOCATIONs.Where(g => g.id_order == id_order).ToList(); return(list.Select(g => new Geolocation() { id_geolocation = g.id_geolocation, latitude = g.latitude, longitude = g.longitude, datetime = g.datetime, id_order = g.id_order }).Where(g => g.id_order == id_order).ToList()); }
public Client GetClientById(int id_client) { FastFoodEntities db = new FastFoodEntities(); return(db.CLIENTs.Select(c => new Client() { id_client = c.id_client, firstname = c.firstname, lastname = c.lastname, gender = c.gender, email = c.email, password = "", phone = c.phone, photo = c.photo, confirmation_code = c.confirmation_code }).FirstOrDefault(c => c.id_client == id_client)); }
public List <Product> GetProductsByCategory(string categoryP) { FastFoodEntities db = new FastFoodEntities(); return(db.PRODUCTs.Select(p => new Product() { id_product = p.id_product, title = p.title, description = p.description, category = p.category, price = p.price, available = p.available, picture = p.picture, id_admin = p.id_admin }) .Where(p => p.available == true && p.category == categoryP).OrderBy(p => p.title).ToList()); }
public Product GetProductById(int id_product) { FastFoodEntities db = new FastFoodEntities(); return(db.PRODUCTs.Select(p => new Product() { id_product = p.id_product, title = p.title, description = p.description, category = p.category, price = p.price, available = p.available, picture = p.picture, id_admin = p.id_admin }) .FirstOrDefault(p => p.available == true && p.id_product == id_product)); }
public List <TOrder> GetClientOrdersByState(int id_client, string state) { FastFoodEntities db = new FastFoodEntities(); // khasni n nsift JWT o n checkeh List <TORDER> listT = db.TORDERs.Where(o => o.id_client == id_client && o.order_state == state).OrderByDescending(o => o.order_datetime).ThenByDescending(o => o.id_order).ToList(); return(listT.Select(o => new TOrder() { id_order = o.id_order, order_state = o.order_state, latitude = o.latitude, longitude = o.longitude, order_datetime = o.order_datetime, order_code = o.order_code, delivery_state = o.delivery_state, received_datetime = o.received_datetime, id_delivery_man = o.id_delivery_man, id_client = o.id_client }).ToList()); }
public TOrder GetOrderById(int id_order) { FastFoodEntities db = new FastFoodEntities(); // khasni n nsift JWT o n checkeh TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == id_order); TOrder order = new TOrder(); order.id_order = torder.id_order; order.order_state = torder.order_state; order.latitude = torder.latitude; order.longitude = torder.longitude; order.order_datetime = torder.order_datetime; order.order_code = torder.order_code; order.delivery_state = torder.delivery_state; order.received_datetime = torder.received_datetime; order.id_delivery_man = torder.id_delivery_man; order.id_client = torder.id_client; return(order); }
public Delivery_man GetDeliveryManById(int id_delivery_man) { FastFoodEntities db = new FastFoodEntities(); return(db.DELIVERY_MAN.Select(d => new Delivery_man() { id_delivery_man = d.id_delivery_man, firstname = d.firstname, lastname = d.lastname, gender = d.gender, email = d.email, password = d.password, phone = d.phone, photo = d.photo, transport = d.transport, matricule = d.matricule, latitude = d.latitude, longitude = d.latitude, authorized = d.authorized, state = d.state, id_admin = d.id_admin }).FirstOrDefault(d => d.id_delivery_man == id_delivery_man)); }
public JObject PutDeliveryManWillDeliverAnOrder([FromBody] OrderFullInfo ofi) { JObject jRes = new JObject(); try { FastFoodEntities db = new FastFoodEntities(); TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_delivery_man == ofi.id_delivery_man && o.order_state == OrderStates.order_on_the_way); if (torder != null) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("MessageTitele", "Failed")); jRes.Add(new JProperty("Message", "You have already an order to deliver it first.")); } else { torder = db.TORDERs.FirstOrDefault(o => o.id_order == ofi.id_order); torder.id_delivery_man = ofi.id_delivery_man; torder.order_state = OrderStates.order_on_the_way; db.SaveChanges(); jRes.Add(new JProperty("Error", false)); jRes.Add(new JProperty("MessageTitele", "Success")); jRes.Add(new JProperty("Message", "Go deliver it.")); } } catch (Exception e) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("MessageTitele", "Failed")); jRes.Add(new JProperty("Message", "Failed, try again.")); } return(jRes); }
public JObject PutChangeDeliveryManTransport([FromBody] Delivery_man dm) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man); try { D1.transport = dm.transport; D1.matricule = dm.matricule; db.SaveChanges(); jRes.Add(new JProperty("Error", false)); } catch (Exception e) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "Connection failed.")); } return(jRes); }
public JObject ConfirmOrder([FromBody] OrderFullInfo ofi) { // khasni n nsift JWT o n checkeh JObject jRes = new JObject(); try { FastFoodEntities db = new FastFoodEntities(); TORDER torder = db.TORDERs.FirstOrDefault(o => o.id_order == ofi.id_order); if (torder != null) { torder.latitude = ofi.latitude; torder.longitude = ofi.longitude; torder.order_state = OrderStates.order_to_deliver; torder.order_code = MyHelper.GenerateRandomNumber(111111, 999999).ToString(); torder.order_datetime = DateTime.Now; db.SaveChanges(); jRes.Add(new JProperty("message", true)); } else { jRes.Add(new JProperty("message", false)); } } catch (Exception e) { jRes.Add(new JProperty("message", false)); } return(jRes); }
public JObject PutChangeDeliveryManInfo([FromBody] Delivery_man dm) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man); DELIVERY_MAN D2 = db.DELIVERY_MAN.FirstOrDefault(d => d.email == dm.email && d.id_delivery_man != dm.id_delivery_man); if (D2 != null && D2.email == dm.email) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Change the email address")); jRes.Add(new JProperty("Message", "This email address is in use by another account.")); } else if (Crypto.VerifyHashedPassword(D1.password, dm.password)) { jRes.Add(new JProperty("Error", false)); D1.firstname = dm.firstname; D1.lastname = dm.lastname; D1.gender = dm.gender; D1.email = dm.email; D1.phone = dm.phone; db.SaveChanges(); Delivery_man d1 = db.DELIVERY_MAN.Select(d => new Delivery_man() { id_delivery_man = d.id_delivery_man, firstname = d.firstname, lastname = d.lastname, gender = d.gender, email = d.email, password = d.password, phone = d.phone, photo = d.photo, transport = d.transport, matricule = d.matricule, latitude = d.latitude, longitude = d.latitude, authorized = d.authorized, state = d.state, id_admin = d.id_admin }).FirstOrDefault(d => d.id_delivery_man == D1.id_delivery_man); // add JWT List <Claim> listClaims = new List <Claim>(); listClaims.Add(new Claim("user_type", "Delivery man")); listClaims.Add(new Claim("id_delivery_man", d1.id_delivery_man.ToString())); jRes.Add(new JProperty("JWT", MyJWT.GenerateJWT(listClaims))); // add id_user jRes.Add(new JProperty("id_delivery_man", d1.id_delivery_man.ToString())); // add user info d1.password = ""; jRes.Add("user_info", d1.toJObject()); } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "The password is incorrect.")); } return(jRes); }
public JObject PutChangeClientInfo([FromBody] Client client) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); CLIENT C1 = db.CLIENTs.FirstOrDefault(c => c.id_client == client.id_client); CLIENT C2 = db.CLIENTs.FirstOrDefault(c => c.email == client.email && c.id_client != client.id_client); if (C2 != null && C2.email == client.email) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Change the email address")); jRes.Add(new JProperty("Message", "This email address is in use by another account.")); } else if (Crypto.VerifyHashedPassword(C1.password, client.password)) { jRes.Add(new JProperty("Error", false)); C1.firstname = client.firstname; C1.lastname = client.lastname; C1.gender = client.gender; C1.email = client.email; C1.phone = client.phone; db.SaveChanges(); Client c1 = db.CLIENTs.Select(c => new Client() { id_client = c.id_client, firstname = c.firstname, lastname = c.lastname, gender = c.gender, email = c.email, password = c.password, phone = c.phone, photo = c.photo, confirmation_code = c.confirmation_code }).FirstOrDefault(c => c.id_client == C1.id_client); //add JWT List <Claim> listClaims = new List <Claim>(); listClaims.Add(new Claim("user_type", "Client")); listClaims.Add(new Claim("id_client", c1.id_client.ToString())); jRes.Add(new JProperty("JWT", MyJWT.GenerateJWT(listClaims))); // add id_user jRes.Add(new JProperty("id_client", c1.id_client.ToString())); // add user info c1.password = ""; jRes.Add("user_info", c1.toJObject()); } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "The password is incorrect.")); } return(jRes); }
// GET: api/Accounts/5 public CLIENT Get(int id) { FastFoodEntities db = new FastFoodEntities(); return(db.CLIENTs.FirstOrDefault(c => c.id_client == id)); }