public IActionResult Search(string Keyword) { string scrubbedKeyword = _textFormatter.CapitaliseFirstLetters( _textFormatter.RemoveDoubleSpaces(Keyword), false); Category foundCat = _catService.GetSingle(x => x.CategoryName == scrubbedKeyword); if (foundCat != null) { IEnumerable <Hamper> foundHampers = _hamperService.Query(x => x.CategoryId == foundCat.CategoryId); HomeSearchViewModel VM = new HomeSearchViewModel { Keyword = scrubbedKeyword, Hampers = foundHampers }; ViewBag.CategoryExist = true; return(View(VM)); } else { ViewBag.CategoryExist = false; return(View()); } }
public IActionResult AddCustomer(AddressCustomerAddViewModel VM) { if (ModelState.IsValid) { string UserName = User.Identity.Name; ApplicationUser user = _userManager.Users.FirstOrDefault(x => x.UserName == UserName); // If this address has been selected as the preferred, set all others from this user to false. if (VM.PreferredShippingAddress) { if (_addressService.Query(x => x.ApplicationUserId == user.Id) != null) { IEnumerable <Address> userAddresses = _addressService.Query(x => x.ApplicationUserId == user.Id).ToList(); foreach (var address in userAddresses) { address.PreferredShippingAddress = false; _addressService.Update(address); } } } Address newAddress = new Address { AddressId = new Guid(), StreetAddress = VM.StreetAddress == null ? "" : _textFormatter.RemoveDoubleSpaces (_textFormatter.CapitaliseFirstLetters(VM.StreetAddress, false)), Suburb = VM.Suburb == null ? "" : _textFormatter.RemoveDoubleSpaces (_textFormatter.CapitaliseFirstLetters(VM.Suburb, false)), State = VM.State == null ? "" : _textFormatter.RemoveDoubleSpaces (_textFormatter.CapitaliseFirstLetters(VM.State, false)), Postcode = VM.Postcode, AddressType = VM.AddressType, PreferredShippingAddress = VM.PreferredShippingAddress, ApplicationUserId = user.Id }; // Add address to the database: _addressService.Create(newAddress); return(RedirectToAction("AddressAddedSuccessfully", "Address")); } return(View(VM)); }
public IActionResult Add(CategoryAddViewModel VM, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string categoryName = _textFormatter. RemoveDoubleSpaces(_textFormatter. CapitaliseFirstLetters(VM.CategoryName, false)); string description = VM.Description != null && VM.Description != "" ? _textFormatter. RemoveDoubleSpaces(VM.Description) : ""; Category newCategory = new Category() { CategoryName = categoryName, Description = description, ImageUrl = VM.ImageUrl, InUse = true }; _catService.Create(newCategory); return(RedirectToAction("SuccessfullyAdded", "Category")); } else { return(View(VM)); } }