public ActionResult Details(int id) { var rent = _rentsRep.GetById(id); var car = _carRep.GetById(rent.Car_ID); var client = _clientRep.GetById((int)rent.Client_ID); var rentDetails = new RetnsViewModels() { Brand = car.Brand, Model = car.Model, Engine = car.Engine, Color = car.Color, StartData = rent.StartData, EndData = rent.EndData, Price = rent.Price, Driver = rent.Driver, Name = client.Name, Surname = client.Surname, Phone = client.Phone, Email = client.Email, District = client.Addres.District.Name, City = client.Addres.City.Name, Street = client.Addres.Street, Flat = client.Addres.Flat }; return(View(rentDetails)); }
public ActionResult Create(RetnsViewModels rentV, int cityDropDown) { try { // Insert addres for client and return last ID int addressId = InsertAddresReturnID(rentV, cityDropDown); // Insert client and return last ID int clinetId = InsertClientReturnID(rentV, addressId); // Get price for selected car double price = _carRep.GetAll().Where(i => i.Car_ID == rentV.Car_ID) .Select(p => p.Price).FirstOrDefault(); var rent = new Rents(); rent.Car_ID = rentV.Car_ID; rent.Client_ID = clinetId; rent.Driver = rentV.Driver; rent.StartData = rentV.StartData; rent.EndData = rentV.EndData; rent.Price = TotalPriceRent(rentV.StartData, rentV.EndData, price); //if (Request.IsAuthenticated) { rent.Operator_ID = User.Identity.GetUserId().AsInt(); } _rentsRep.Create(rent); _rentsRep.Save(); SaveInSession(rentV.Car_ID, rent); return(RedirectToAction("Index", "Home")); } catch (Exception e) { return(View(e)); } }
private int InsertAddresReturnID(RetnsViewModels rentV, int cityDropDown) { var address = new Addres() { City_ID = cityDropDown, District_ID = rentV.District_ID, Flat = rentV.Flat, Street = rentV.Street }; _addressRep.Create(address); _addressRep.Save(); return(address.Addres_ID);; }
// Insert client and return ID private int InsertClientReturnID(RetnsViewModels rentV, int addressId) { var client = new Client() { Name = rentV.Name, Surname = rentV.Surname, Email = rentV.Email, Idnp = rentV.Idnp, Phone = rentV.Phone, Addres_ID = addressId }; _clientRep.Create(client); _clientRep.Save(); return(client.Client_ID); }