public ActionResult UpdateProduct(int Id) { //Declare DonateVM RentVM model; using (ApplicationDbContext db = new ApplicationDbContext()) { //Get the product Rent_Product product = db.Rent_Product.Find(Id); //make sure product exists if (product == null) { return(Content("That product does not exist")); } //init model model = new RentVM(product); //make a select list model.Categories = new SelectList(db.Rent_Category.ToList(), "Id", "Name"); //get all gallery images model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + Id + "/Gallery/Thumbs")) .Select(fn => Path.GetFileName(fn)); } return(View(model)); }
public async Task <IActionResult> Order(RentVM model) { var USER = await _userManager.FindByNameAsync(model.UserName); Rent rent = new Rent(); rent.UserId = USER.Id; rent.Note = model.Note; rent.IsInvoice = model.IsInvoice; rent.Price = (model.RentEnd.DayOfYear - model.RentStart.DayOfYear) * 100; rent.Description = model.Description; rent.RentAddress = model.RentAddress; rent.RentStart = DateTime.Today; rent.RentEnd = model.RentEnd; if (model.SelectedCar == null) { ModelState.AddModelError("", "Auto musi być wybrane"); return(RedirectToAction("Error", "Home")); } rent.CarId = int.Parse(model.SelectedCar.Last()); rent.RentStatus = "Oczekujące"; if (model.SelectedEquipment == null) { //rent.AdditionalEquipmentId = 1; } else { rent.AdditionalEquipmentId = model.SelectedEquipment.Last(); } _rentRepository.AddRent(rent); return(RedirectToAction("Index", "Home")); }
public ActionResult CarSelect(int ID) { RentVM rent = new RentVM(); rent.CarId = ID; rent.CustomerId = (int)Session["LoginId"]; rent.StartDate = Convert.ToDateTime(Session["StartDate"]); rent.EndDate = Convert.ToDateTime(Session["EndDate"]); return(RedirectToAction("Index", "Rent", rent)); }
public ActionResult Add_Rent_Product() { //Intial Model RentVM model = new RentVM(); //add selet list to categorey models using (ApplicationDbContext db = new ApplicationDbContext()) { model.Categories = new SelectList(db.Rent_Category.ToList(), "Id", "Name"); } return(View(model)); }
private GenricApartment <ListsVM, RentVM, SaleVM, ApartmentVM> PopulateLists(string lists, Action <Rent, Sale, Apartment> action) { ListsVM listsVm = new ListsVM() { Bedrooms = lists.GetSelectListAsync("bedrooms", "bedroomsCount"), Countries = lists.GetSelectListAsync("countries", "country").OrderBy(o => o.Text), Furnishings = lists.GetSelectListAsync("furnishings", "furnitureType"), Owners = lists.GetSelectListAsync("owners", "fullName").OrderBy(o => o.Text) }; RentVM rent = new RentVM() { Periods = lists.GetSelectListAsync("periods", "period") }; SaleVM sale = new SaleVM(); ApartmentVM apartment = new ApartmentVM(); action.Invoke(rent.Rent, sale.Sale, apartment.Apartment); return(new GenricApartment <ListsVM, RentVM, SaleVM, ApartmentVM>(listsVm, rent, sale, apartment)); }
// GET: Rent public ActionResult Index(RentVM rentInfo) { Car car = new Car(); try { car = _carBusiness.Get(rentInfo.CarId); } catch (Exception ex) { } double rentDays = (rentInfo.EndDate - rentInfo.StartDate).TotalDays; decimal totalPrice = car.RentPrice * Convert.ToDecimal(rentDays); rentInfo.RentDayCount = rentDays; rentInfo.TotalPrice = totalPrice; return(View(rentInfo)); }
public async Task <IActionResult> Order(string username) { var User = await _userManager.FindByNameAsync(username); DatabaseContext context = this.DatabaseInitialization(); List <SelectListItem> listSelectListItemCars = new List <SelectListItem>(); foreach (Car car in context.Cars) { SelectListItem selectListItemC = new SelectListItem() { Text = car.Mark + " " + car.Model, Value = car.CarId.ToString(), Selected = car.IsSelected }; listSelectListItemCars.Add(selectListItemC); } List <SelectListItem> listSelectListItemEquipment = new List <SelectListItem>(); foreach (AdditionalEquipment item in context.AdditionalEquipments) { SelectListItem selectListItemE = new SelectListItem() { Text = item.Type, Value = item.AdditionalEquipmentId.ToString(), Selected = item.IsSelected }; listSelectListItemEquipment.Add(selectListItemE); } RentVM model = new RentVM(); model.Cars = listSelectListItemCars; model.Equipments = listSelectListItemEquipment; model.RentStart = DateTime.Now; model.RentEnd = DateTime.Now.AddDays(1); model.Price = 100 * model.RentEnd.Day; model.UserName = User.UserName; return(View("Order", model)); }
public ActionResult Add_Rent_Product(RentVM model, HttpPostedFileBase file) { //check model state if (!ModelState.IsValid) { using (ApplicationDbContext db = new ApplicationDbContext()) { model.Categories = new SelectList(db.Rent_Category.ToList(), "Id", "Name"); return(View(model)); } } //declare product id int id; using (ApplicationDbContext db = new ApplicationDbContext()) { Rent_Product product = new Rent_Product(); product.Name = model.Name; product.Price = model.Price; product.Description = model.Description; product.CategoryId = model.CategoryId; product.Rent_Started = DateTime.Now; product.Renting_Period = model.Renting_Period; product.AdminId = User.Identity.GetUserId(); db.Rent_Product.Add(product); db.SaveChanges(); //get id id = product.Id; } TempData["SM"] = "You have addedd a product sussecfully"; #region //Create necessary directiories var OriginalDirectorey = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\"))); var PathString1 = Path.Combine(OriginalDirectorey.ToString(), "Products"); var PathString2 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString()); var PathString3 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString() + "\\Thumbs"); var PathString4 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString() + "\\Gallery"); var PathString5 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString() + "\\Gallery\\Thumbs"); if (!Directory.Exists(PathString1)) { Directory.CreateDirectory(PathString1); } if (!Directory.Exists(PathString2)) { Directory.CreateDirectory(PathString2); } if (!Directory.Exists(PathString3)) { Directory.CreateDirectory(PathString3); } if (!Directory.Exists(PathString4)) { Directory.CreateDirectory(PathString4); } if (!Directory.Exists(PathString5)) { Directory.CreateDirectory(PathString5); } //Create if a file was upload if (file != null && file.ContentLength > 0) { //Get file Extention string ext = file.ContentType.ToLower(); if (ext != "image/jpg" && ext != "image/jpeg" && ext != "image/pjpeg" && ext != "image/gif" && ext != "image/x-png" && ext != "image/png") { using (ApplicationDbContext db = new ApplicationDbContext()) { model.Categories = new SelectList(db.Donate_Category.ToList(), "Id", "Name"); ModelState.AddModelError("", "The Image was not uplaoded - wrong image extintion"); return(View(model)); } } string ImageName = file.FileName; using (ApplicationDbContext db = new ApplicationDbContext()) { Rent_Product prod = db.Rent_Product.Find(id); prod.ImageName = ImageName; db.SaveChanges(); } //set original and thumb image pathss var path = string.Format("{0}\\{1}", PathString2, ImageName); var path2 = string.Format("{0}\\{1}", PathString3, ImageName); //save original file.SaveAs(path); //create and save thumbs WebImage image = new WebImage(file.InputStream); image.Resize(400, 400); image.Save(path2); } #endregion //redirect return(RedirectToAction("Add_Rent_Product")); }
public ActionResult UpdateProduct(RentVM model, HttpPostedFileBase file) { //get product id int id = model.Id; //populate categories selectlist and gallery images using (ApplicationDbContext db = new ApplicationDbContext()) { model.Categories = new SelectList(db.Rent_Category.ToList(), "Id", "Name"); } model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + id + "/Gallery/Thumbs")) .Select(fn => Path.GetFileName(fn)); //check model state if (!ModelState.IsValid) { return(View(model)); } //make sure product name isunique using (ApplicationDbContext db = new ApplicationDbContext()) { if (db.Rent_Product.Where(x => x.Id != id).Any(x => x.Name == model.Name)) { ModelState.AddModelError("", "That product name is tacken!"); return(View(model)); } } using (ApplicationDbContext db = new ApplicationDbContext()) { Rent_Product product = db.Rent_Product.Find(id); product.Name = model.Name; product.Description = model.Description; product.Price = model.Price; product.Renting_Period = model.Renting_Period; product.CategoryId = model.CategoryId; if (model.ImageName != null) { product.ImageName = model.ImageName; } db.SaveChanges(); } //set tempdata message TempData["SM"] = "You have Updated a product sussecfully"; #region Image Upload //Create if a file was upload if (file != null && file.ContentLength > 0) { //Get file Extention string ext = file.ContentType.ToLower(); if (ext != "image/jpg" && ext != "image/jpeg" && ext != "image/pjpeg" && ext != "image/gif" && ext != "image/x-png" && ext != "image/png") { using (ApplicationDbContext db = new ApplicationDbContext()) { model.Categories = new SelectList(db.Donate_Category.ToList(), "Id", "Name"); ModelState.AddModelError("", "The Image was not uplaoded - wrong image extintion"); return(View(model)); } } var OriginalDirectorey = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\"))); var PathString1 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString()); var PathString2 = Path.Combine(OriginalDirectorey.ToString(), "Products\\" + id.ToString() + "\\Thumbs"); //Delete files from directories DirectoryInfo di1 = new DirectoryInfo(PathString1); DirectoryInfo di2 = new DirectoryInfo(PathString2); foreach (FileInfo file1 in di1.GetFiles()) { file1.Delete(); } foreach (FileInfo file2 in di2.GetFiles()) { file2.Delete(); } //save images name string imageName = file.FileName; using (ApplicationDbContext db = new ApplicationDbContext()) { Rent_Product product = db.Rent_Product.Find(id); product.ImageName = imageName; db.SaveChanges(); } //save original and thumb images var path = string.Format("{0}\\{1}", PathString1, imageName); var path2 = string.Format("{0}\\{1}", PathString2, imageName); //save original file.SaveAs(path); //create and save thumbs WebImage image = new WebImage(file.InputStream); image.Resize(400, 400); image.Save(path2); } #endregion //Redirect return(RedirectToAction(nameof(UpdateProduct))); }