public ActionResult CancelReciveFirst(int?id, DateTime Start_Recive_Date) { var Cars_Recived = db.Cars.FirstOrDefault(car => car.Car_Id == id); if (Cars_Recived != null) { string client_id = User.Identity.GetUserId(); Client CLIENT = db.Client.FirstOrDefault(client_ => client_.Client_ID == client_id); ReciveDate reciveDate = db.ReciveDates.Where(ReciveDate => ReciveDate.Start_Recive_Date == Start_Recive_Date && ReciveDate.client.Client_ID == CLIENT.Client_ID).FirstOrDefault(); if (reciveDate != null) { ViewBag.ReciveDate = reciveDate; return(View("CancelRecive", Cars_Recived));// display View of recive } else { return(View("Recive_Not_Done_Yet", Cars_Recived));//display Cars is not recirved yet } } else { return(View("Car_Not_Found")); // dispaly Cars is Not Fount } }
public ActionResult Recive(int?Car_Id, DateTime Start_Recive_Date, DateTime End_Recive_Date) { /*check by Cars number*/ var Cars_Recived = db.Cars.FirstOrDefault(car => car.Car_Id == Car_Id); ReciveDate reciveDate = new ReciveDate(); reciveDate.Start_Recive_Date = Start_Recive_Date; reciveDate.End_Recive_Date = End_Recive_Date; reciveDate.cars = Cars_Recived; Dates_For_Car Date = new Dates_For_Car(); Date.Start_Recive = (from Dates in db.ReciveDates where (Dates.cars.Car_Id == Cars_Recived.Car_Id) select ( Dates.Start_Recive_Date )).ToList(); Date.End_Recive = (from Dates in db.ReciveDates where (Dates.cars.Car_Id == Cars_Recived.Car_Id) select ( Dates.End_Recive_Date )).ToList(); foreach (var start in Date.Start_Recive) { foreach (var end in Date.End_Recive) { if ((Start_Recive_Date >= start) && (End_Recive_Date <= end)) { return(View("Recive_Alredy_Done", Cars_Recived)); //display Cars is Elredy recirved} } else { continue; } } } string client_id = User.Identity.GetUserId(); Client CLIENT = db.Client.FirstOrDefault(client_ => client_.Client_ID == client_id); reciveDate.client = CLIENT; Calc_price(reciveDate); Cars_Recived.reciveDates.Add(reciveDate); CLIENT.Booked_Car.Add(reciveDate); db.SaveChanges(); ViewBag.startDate = Start_Recive_Date; ViewBag.endDate = End_Recive_Date; ViewBag.client = CLIENT.Name; return(View("Displa_Reciving", Cars_Recived)); // display confirm for client recived done }
public ActionResult CancelRecive(ReciveDate reciveDate) { try { reciveDate = TempData["ReciveDate"] as ReciveDate; ReciveDate Rea_reciveDate = (from reciveDate_ in db.ReciveDates where (reciveDate_.id == reciveDate.id) select( reciveDate_ )).FirstOrDefault(); Car Cars_Recived = (from reciveDate_ in db.ReciveDates where (reciveDate_.id == reciveDate.id) select( reciveDate_.cars )).FirstOrDefault(); //Car Cars_Recived = db.Cars.FirstOrDefault(car => car.Car_Id == reciveDate.cars.Car_Id); if (Rea_reciveDate != null) { if (Rea_reciveDate.Start_Recive_Date <= DateTime.Now) { Rea_reciveDate.End_Recive_Date = DateTime.Now; Calc_price(Rea_reciveDate); db.SaveChanges(); return(View("bill", Cars_Recived)); } else { Rea_reciveDate.Start_Recive_Date = DateTime.Now; Rea_reciveDate.End_Recive_Date = DateTime.Now; db.SaveChanges(); return(RedirectToAction("List_of_all")); //display Cancel is Done with no cost } } else { return(View("Recive_Not_Done_Yet", Cars_Recived)); //display Cars is not recirved yet } } catch { return(View("Car_Not_Found")); // dispaly Cars is Not Fount } }
public void Calc_price(ReciveDate reciveDate) { int days_is_recived = reciveDate.End_Recive_Date.Subtract(reciveDate.Start_Recive_Date).Days; reciveDate.Total_Cost = days_is_recived * reciveDate.cars.price_in_day; }