public IActionResult Update(HamperUpdateViewModel vm) { string uniqueFileName = null; if (vm.Image != null) { string uploadFolder = Path.Combine(_hostingEnvironmentServices.WebRootPath + "\\images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + vm.Image.FileName; string FilePath = Path.Combine(uploadFolder, uniqueFileName); vm.Image.CopyTo(new FileStream(FilePath, FileMode.Create)); } //map Hamper updatedHamper = new Hamper { HamperId = vm.HamperId, CategoryId = vm.CategoryId, Name = vm.Name, Details = vm.Details, Price = vm.Price, Image = uniqueFileName }; //call service _hamperService.Update(updatedHamper); //go to return(RedirectToAction("Details", "Category", new { id = vm.CategoryId })); }
public async Task <IActionResult> Update(HamperUpdateViewModel vm) { Hamper h = _hamperManager.Read(vm.HamperId); if (h == null) { return(NotFound()); } if (vm.File != null) { var uploadPath = Path.Combine(environment.WebRootPath, "uploads/hampers/"); string extension = Path.GetExtension(vm.File.FileName); string fileName = StringFormatHelper.ToTitleCase(h.HamperName) + "-1" + extension; using (var fileStream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create)) { await vm.File.CopyToAsync(fileStream); } h.Picture = fileName; } h.HamperDescription = vm.HamperDescription; h.HamperName = vm.HamperName; h.HamperPrice = vm.HamperPrice; h.CategoryId = vm.CategoryId; h.Active = !vm.Retired; _hamperManager.Update(h); return(Redirect(vm.ReturnUrl)); }
public IActionResult Add(HamperAddViewModel VM) { if (ModelState.IsValid) { string hamperName = _textFormatter. RemoveDoubleSpaces(_textFormatter. CapitaliseFirstLetters(VM.HamperName, false)); string description = VM.Description != null && VM.Description != "" ? _textFormatter. RemoveDoubleSpaces(VM.Description) : ""; Hamper newHamper = new Hamper() { HamperName = hamperName, Description = description, Price = VM.Price, Products = VM.Products, ImageUrl = VM.ImageUrl, Supplier = VM.Supplier, InUse = true, CategoryId = VM.CategoryId }; _hamperService.Create(newHamper); return(RedirectToAction("Edit", "Category", new { CategoryId = newHamper.CategoryId })); } else { return(View(VM)); } }
public IActionResult ViewHamper(string id, string rating) { HamperViewModel vm = new ViewModels.HamperViewModel(); int hamperId = 0; int.TryParse(id, out hamperId); Hamper hamper = _hamperDataService.GetSingle(h => h.HamperId == hamperId); if (hamper != null) { vm.HamperId = hamperId; vm.Name = hamper.Name; vm.Image = hamper.Image; vm.Price = hamper.Price; vm.Quantity = 1; vm.CategoryId = hamper.CategoryId; vm.Details = hamper.Details; vm.Discontinue = hamper.Discontinue; vm.Rating = hamper.Rate; } if (!string.IsNullOrEmpty(rating)) { int rate = Convert.ToInt32(rating); hamper.Rate = (int)Math.Ceiling((Convert.ToDouble(rate) + Convert.ToDouble(hamper.Rate)) / 2); _hamperDataService.Update(hamper); vm.Rating = hamper.Rate; } return(View(vm)); }
public async Task <IActionResult> Edit(int id, [Bind("HamperId,HamperName,TotalPrice")] Hamper hamper) { if (id != hamper.HamperId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(hamper); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HamperExists(hamper.HamperId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(hamper)); }
public IActionResult GiftList(int id, Hamper hamper) { IEnumerable <Gift> gifts = _giftRepo.GetAll(); IEnumerable <HamperGift> hamperGifts = _hamperGiftRepo.Query(hg => hg.HamperId == hamper.HamperId); Hamper _hamper = new Hamper(); if (hamper.HamperId == 0) { _hamper = _hamperRepo.GetSingle(h => h.HamperId == id); } else { _hamper = hamper; } if (gifts.Count() == 0) { return(RedirectToAction("Create", "Gift")); } GiftListViewModel vm = new GiftListViewModel(); if (hamperGifts.Count() == 0) { vm.HamperGifts = new List <HamperGift>(); } vm.Gifts = gifts; vm.HamperGifts = hamperGifts; vm.Hamper = _hamper; return(View(vm)); }
public async Task <IActionResult> Create(HamperCreateViewModel vm, IFormFile file) { if (ModelState.IsValid) { var user = await _UserManager.FindByNameAsync(User.Identity.Name); Hamper h = new Hamper { Active = true, CategoryId = vm.CategoryId, HamperDescription = vm.HamperDescription, HamperName = vm.HamperName, HamperPrice = vm.HamperPrice, }; if (file != null) { var uploadPath = Path.Combine(environment.WebRootPath, "uploads/hampers/"); string extension = Path.GetExtension(file.FileName); string fileName = StringFormatHelper.ToTitleCase(h.HamperName) + "-1" + extension; using (var fileStream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } h.Picture = fileName; } _hamperManager.Add(h); return(RedirectToAction("Index")); } IEnumerable <Category> categories = _categoryManager.GetAll(); vm.Categories = categories; return(View(vm)); }
public IActionResult Edit(HamperEditViewModel VM) { if (ModelState.IsValid) { Hamper updatedHamper = new Hamper { HamperId = VM.HamperId, HamperName = VM.HamperName, Description = VM.Description, Products = VM.Products, Supplier = VM.Supplier, Price = VM.Price, ImageUrl = VM.ImageUrl, CategoryId = VM.CategoryId, InUse = true }; _hamperService.Update(updatedHamper); return(RedirectToAction("Edit", "Category", new { CategoryId = VM.CategoryId })); } else { return(View(VM)); } }
public IActionResult ViewDetails(int HamperId) { ViewBag.HamperFound = true; if (_hamperService.GetSingle(x => x.HamperId == HamperId) != null) { Hamper hamper = _hamperService.GetSingle(x => x.HamperId == HamperId); string categoryName = _catService.GetSingle(x => x.CategoryId == hamper.CategoryId).CategoryName; string price = "$" + hamper.Price.ToString(); HamperViewDetailsViewModel VM = new HamperViewDetailsViewModel { HamperName = hamper.HamperName, HamperId = hamper.HamperId, CategoryName = categoryName, Description = hamper.Description, Price = price, Products = hamper.Products, Supplier = hamper.Supplier, ImageUrl = hamper.ImageUrl }; return(View(VM)); } else { ViewBag.HamperFound = false; return(View()); } }
public async Task <IActionResult> Edit(HamperEditViewModel vm, IFormFile upload) { if (ModelState.IsValid) { Hamper hamper = _context.TblHamper.Where(h => h.HamperId == vm.HamperId).FirstOrDefault(); if (upload == null) { hamper.HamperName = vm.HamperName; hamper.Details = vm.Details; hamper.Price = vm.Price; } else { // Create a binary read to read the data from the upload file BinaryReader binaryReader = new BinaryReader(upload.OpenReadStream()); // Read the bytes, specifying the length of the content byte[] fileData = binaryReader.ReadBytes((int)upload.Length); // Extract the file name; we don't want the whole path var fileName = Path.GetFileName(upload.FileName); hamper.HamperName = vm.HamperName; hamper.Details = vm.Details; hamper.Price = vm.Price; hamper.FileName = fileName; hamper.FileContent = fileData; hamper.ContentSize = upload.Length; hamper.ContentType = upload.ContentType; } await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Hamper", new { Id = hamper.CategoryId })); } return(View(vm)); }
public IActionResult AddHamper(string hamperId) { HamperAddViewModel vm = new HamperAddViewModel(); IEnumerable <Category> categoryList = _categoryDataService.GetAll(); vm.Categories = categoryList.Select(c => new HamperCategoryViewModel { CategoryId = c.CategoryId, CategoryName = c.CategoryName }).ToList(); int hId; if (int.TryParse(hamperId, out hId)) { Hamper hamper = _hamperDataService.GetSingle(h => h.HamperId == hId); if (hamper != null) { vm.HamperId = hamper.HamperId; vm.CategoryId = hamper.CategoryId; vm.Image = hamper.Image; vm.Name = hamper.Name; vm.Price = hamper.Price; vm.Details = hamper.Details; vm.Discontinue = hamper.Discontinue; } } return(View(vm)); }
public IActionResult Read(string id) { Hamper hamper = _hamperManager.GetAll() .Include(h => h.HamperOrders) .Include(h => h.Category) .FirstOrDefault(h => h.HamperId == id); HamperReadViewModel vm = new HamperReadViewModel { Active = hamper.Active, Category = hamper.Category, OrderCount = hamper.HamperOrders.Count(), HamperDescription = hamper.HamperDescription, HamperId = hamper.HamperId, HamperName = hamper.HamperName, HamperPrice = hamper.HamperPrice, Picture = hamper.Picture, }; if (vm.Picture == null) { vm.Picture = "DefaultHamper.png"; } return(View(vm)); }
public IActionResult Restore(int id) { Hamper hamp = _hamperService.GetSingle(c => c.HamperId == id); hamp.IsDeleted = false; _hamperService.Update(hamp); return(RedirectToAction("Details", "Category", new { id = hamp.CategoryId })); }
public IActionResult Delete(HamperDeleteViewModel VM) { Hamper hamperToDelete = _hamperService.GetSingle(x => x.HamperId == VM.HamperId); _hamperService.Delete(hamperToDelete); return(RedirectToAction("Edit", "Category", new { CategoryId = hamperToDelete.CategoryId })); }
public IActionResult Delete(int id) { Hamper hamper = _dataService.GetSingle(c => c.HamperId == id); _dataService.Delete(hamper); return(RedirectToAction("Details", "Category")); }
public IActionResult ReActivate(string id) { Hamper h = _hamperManager.Read(id); h.Active = true; _hamperManager.Update(h); return(RedirectToAction("Index")); }
public IActionResult EditHamper(int id) { Hamper hamper = _hamperService.GetSingle(h => h.HamperId == id); if (hamper == null) { return(NotFound()); } var product = _productService.GetAll().ToList(); var productChecks = product.Select(p => new ProductCheckList { ProductName = p.ProductName, Checked = false, ProductId = p.ProductId }).ToList(); var hp = _HPService.Query(hps => hps.HamperId == hamper.HamperId); productChecks.ForEach(x => { foreach (HamperProduct hpr in hp) { if (hpr.ProductId == x.ProductId) { x.Checked = true; } } }); var cats = _categoryService.GetAll().ToList(); var filenames = _imageService.GetAll().ToList(); var catSelect = cats.Select(x => new SelectListItem { Value = x.CategoryId.ToString(), Text = x.CategoryName }); var fileSelect = filenames.Select(x => new SelectListItem { Value = x.ImageId.ToString(), Text = x.FileName }); AdminEditHamperViewModel vm = new AdminEditHamperViewModel { CategoryId = hamper.CategoryId.ToString(), Cost = hamper.Cost, ImageId = _imageService.GetSingle(img => img.ImageId == hamper.ImageId).ImageId.ToString(), HamperId = hamper.HamperId, HamperName = hamper.HamperName, FileNames = fileSelect.ToList(), CategoryNamesList = catSelect.ToList(), ProductNamesList = productChecks.ToArray(), IsDiscontinued = hamper.isDiscontinued }; return(View(vm)); }
public IActionResult Discontinue(int id) { Hamper hamper = _hamperRepo.GetSingle(h => h.HamperId == id); hamper.Active = false; _hamperRepo.Update(hamper); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("HamperId,HamperName,TotalPrice")] Hamper hamper) { if (ModelState.IsValid) { _context.Add(hamper); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hamper)); }
public IActionResult Delete(int HamperId) { Hamper hamperToDelete = _hamperService.GetSingle(x => x.HamperId == HamperId); HamperDeleteViewModel VM = new HamperDeleteViewModel { HamperId = HamperId, HamperName = hamperToDelete.HamperName }; return(View(VM)); }
public IActionResult Update(UpdateHamperViewModel vm, int id) { Hamper hamper = _hamperRepo.GetSingle(h => h.HamperId == id); hamper.Name = vm.Name; hamper.Price = vm.Price; hamper.CategoryId = vm.SelectedCategoryId; hamper.Category = _categoryRepo.GetSingle(c => c.CategoryId == vm.SelectedCategoryId); _hamperRepo.Update(hamper); return(RedirectToAction("Index")); }
public override bool Test(Sim a, Hamper target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { if (!target.HasClothingPiles() || target.LotCurrent == null) { return(false); } if (Sims3.Gameplay.Queries.CountObjects <WashingMachine>(target.LotCurrent) == 0U || target.LotCurrent.GetObjects <WashingMachine>(new Predicate <WashingMachine>(Hamper.DoLaundry.IsWashingMachineUsable)).Count == 0) { greyedOutTooltipCallback = new GreyedOutTooltipCallback(Hamper.DoLaundry.Definition.NoWashingMachinesTooltip); return(false); } return(true); }
public IActionResult Update(int id) { Hamper hamper = _hamperRepo.GetSingle(h => h.HamperId == id); IEnumerable <Category> categories = _categoryRepo.Query(c => c.Active == true); UpdateHamperViewModel vm = new UpdateHamperViewModel() { Name = hamper.Name, Price = hamper.Price, Categories = categories }; return(View(vm)); }
public IActionResult EditHamper(int id) { Hamper hamper = _hamperService.GetSingle(h => h.HamperId == id); EditHamperViewModel vm = new EditHamperViewModel { HamperId = hamper.HamperId, Name = hamper.Name, Category = hamper.Category, Details = hamper.Details, Price = hamper.Price }; return(View(vm)); }
public async Task <IActionResult> AddHamper(HamperAddViewModel vm, IFormFile file) { if (ModelState.IsValid) { Hamper hamper = new Hamper { HamperId = vm.HamperId, CategoryId = vm.CategoryId, Name = vm.Name, Price = vm.Price, Details = vm.Details, Discontinue = vm.Discontinue, Image = vm.Image, Rate = 0 }; if (hamper.HamperId == 0) { _hamperDataService.Create(hamper); } if (file != null) { var uploadPath = Path.Combine(_environmet.WebRootPath, "uploads"); string extention = Path.GetExtension(file.FileName); string fileName = hamper.HamperId + extention; using (var fileStream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } hamper.Image = fileName; } _hamperDataService.Update(hamper); } IEnumerable <Category> categoryList = _categoryDataService.GetAll(); vm.Categories = categoryList.Select(c => new HamperCategoryViewModel { CategoryId = c.CategoryId, CategoryName = c.CategoryName }).ToList(); return(View(vm)); }
//[ValidateAntiForgeryToken] public IActionResult AddToCart(int HamperId) { ViewBag.CartHasItems = true; Hamper chosenHamper = _hamperService.GetSingle(x => x.HamperId == HamperId); List <ShoppingCartItem> shoppingCart = retrieveCartFromSession(); ShoppingCartItem newShoppingCartItem; // Check whether or not there's anything in session: if (string.IsNullOrEmpty(HttpContext.Session.GetString(cartKey))) { newShoppingCartItem = new ShoppingCartItem { Hamper = chosenHamper, Quantity = 1 }; shoppingCart.Add(newShoppingCartItem); } else { // If this hamper has already been added to the shopping cart, // this will extract it, increase the qty by 1, and put it back into session: if (shoppingCart.Where(x => x.Hamper.HamperId == HamperId).FirstOrDefault() != null) { newShoppingCartItem = shoppingCart.Where(x => x.Hamper.HamperId == HamperId).FirstOrDefault(); // Removing newShoppingCartItem before re-adding it // (I wasn't able to find a LINQ equivalent to 'update shoppingCart.Remove(newShoppingCartItem); newShoppingCartItem.Quantity++; shoppingCart.Add(newShoppingCartItem); } else { newShoppingCartItem = new ShoppingCartItem { Hamper = chosenHamper, Quantity = 1 }; shoppingCart.Add(newShoppingCartItem); } } updateShoppingCart(shoppingCart); return(RedirectToAction("Index", "Home")); }
public IActionResult Edit(int id) { Hamper hamper = _dataService.GetSingle(c => c.HamperId == id); HamperEditViewModel vm = new HamperEditViewModel { HamperId = hamper.HamperId, HamperName = hamper.HamperName, Details = hamper.Details, Price = hamper.Price, CategoryId = hamper.CategoryId, }; return(View(vm)); }
public IActionResult Details(int id) { Hamper hamper = _hamperRepo.GetSingle(h => h.HamperId == id); IEnumerable <Hamper> otherHampers = _hamperRepo.Query(h => h.HamperId != id && h.Active == true); IEnumerable <HamperGift> hamperGifts = _hamperGiftRepo.Query(hg => hg.HamperId == id); HamperDetailsViewModel vm = new HamperDetailsViewModel() { Hamper = hamper, OtherHampers = otherHampers, HamperGifts = hamperGifts }; return(View(vm)); }
public IActionResult Update(int id) { //call service Hamper hamper = _hamperService.GetSingle(p => p.HamperId == id); HamperUpdateViewModel vm = new HamperUpdateViewModel { HamperId = id, Name = hamper.Name, Details = hamper.Details, Price = hamper.Price, CategoryId = hamper.CategoryId }; return(View(vm)); }
public IActionResult Create(int id) { Hamper hamper = new Hamper(); if (id != 0) { hamper = _hamperRepo.GetSingle(h => h.HamperId == id); } CreateHamperViewModel vm = new CreateHamperViewModel(); vm.HamperGifts = _hamperGiftRepo.Query(hg => hg.HamperId == hamper.HamperId); vm.Categories = _categoryRepo.Query(c => c.Active == true); vm.Hamper = hamper; return(View(vm)); }