private void OrderDeliveredBtn_Click(object sender, EventArgs e) { Entities ent = new Entities(); ORDER o = ent.ORDERS.Where(x => x.ORDER_ID == ordID).FirstOrDefault(); o.STATUS = "d"; DELIVERY_PARTNER dp = ent.DELIVERY_PARTNER.Where(p => p.USERNAME == Helper.currentUserName).FirstOrDefault(); TRIP t = ent.TRIPs.Where(tr => tr.ORDER_ID == o.ORDER_ID).FirstOrDefault(); decimal mealcost = o.FOOD_PRICE, applicationfees = 5, totalcost; decimal deliverycost = t.DISTANCE_OF_TRIP * Math.Max(dp.RATING, 1); if (dp.VEHICLE.ToLower() == "car") { deliverycost *= 8; } else if (dp.VEHICLE.ToLower() == "bike" || dp.VEHICLE.ToLower() == "scooter") { deliverycost *= 5; } else { deliverycost *= 3; } t.DELIVERYFEES = deliverycost; dp.RATING = Math.Max(5, dp.RATING + (decimal)(0.01)); totalcost = deliverycost + applicationfees + mealcost; CustomMsgBox.Show("Delivery Fees = " + deliverycost.ToString() + "\nMeal Cost = " + mealcost.ToString() + "\nTotal Cost = " + totalcost.ToString()); ent.SaveChanges(); this.Close(); }
private void CancelDeliveryBtn_Click(object sender, EventArgs e) { DialogResult dialogResult = CustomMsgBox.Show("Are you sure you want to cancel the order\n if you cancel the order your " + "rating will decrease by 0.2", 2); if (dialogResult == DialogResult.Yes) { Entities ent = new Entities(); var l = (from fo in ent.ORDER_FOOD where fo.ORDER_ID == ordID select fo); foreach (var i in l) { i.BOUGHT = "n"; } var ord = (from o in ent.ORDERS where o.ORDER_ID == ordID select o).First(); ord.STATUS = "pp"; DELIVERY_PARTNER dp = (from p in ent.DELIVERY_PARTNER where p.USERNAME == Helper.currentUserName select p).FirstOrDefault(); dp.RATING = Math.Min(0, dp.RATING - (decimal)(0.2)); ent.TRIPs.Remove(ent.TRIPs.Where(te => te.ORDER_ID == ordID).First()); ent.SaveChanges(); this.Close(); } }