//Wher user add's new item use this action public ActionResult AddToCart(int id, string sizes) { StoreClassHelper helper = new StoreClassHelper(shopItemService); ShopItemViewModel model = helper.ConvertFromDTOToViewModel(id); if (Session["cart"] == null) { List <Order> cart = new List <Order>(); cart.Add(new Order { shopItemViewModel = model, size = sizes }); Session["cart"] = cart; } else { List <Order> cart = (List <Order>)Session["cart"]; cart.Add(new Order { shopItemViewModel = model, size = sizes }); Session["cart"] = cart; } return(RedirectToAction("ShopCart")); }
public async Task <ActionResult <ApiResultViewModel <ShopItemViewModel> > > GetById([FromRoute] string id, CancellationToken cancellationToken) { var shopItem = await _shopItemManager.GetByIdAsyncThrowNotFoundIfNotExists(id, cancellationToken); return(OkData(ShopItemViewModel.Map(shopItem))); }
public ActionResult Index(string sort) { ShopItemViewModel newItem = new ShopItemViewModel(); switch (sort) { case "Sort by Name": comics = orderbyname(comics); return(View(comics)); case "Sort by Price": comics = orderbyprice(comics); return(View(comics)); case "Sort by Quantity Available ": comics = orderbyQuantity(comics); return(View(comics)); // case "How many items are in the list?": // c = comics.Count; // ViewBag.Message = c.ToString(); // return View(); default: return(View(comics)); } }
public async Task <ActionResult <ApiResultViewModel <ShopItemViewModel> > > GetAll([FromQuery] QueryInputModel <ShopItemFilterInputModel> query, CancellationToken cancellationToken) { var result = await _shopItemManager.GetAllAsync(query, cancellationToken); return(OkData(ShopItemViewModel.MapAll(result.Data), result.TotalCount)); }
public ActionResult AddItem(string fName, string fDescription, double fPrice, int fQuantityAvailable) { ShopItemViewModel newItem = new ShopItemViewModel(fName, fDescription, fPrice, fQuantityAvailable); Items.Add(newItem); return(View("Index", Items)); }
public ActionResult AddItem(string iName, string iDesciption, double iPrice, int iQuantityAvailable) { ShopItemViewModel newItem = new ShopItemViewModel(iName, iDesciption, iPrice, iQuantityAvailable, comics); comics.Add(newItem); return(View("Index", comics)); }
public ActionResult Shop() { var viewModel = new ShopItemViewModel() { Products = _context.Products.Include(c => c.Pictures).ToList() }; return View(viewModel); }
private void editItem(ShopItemViewModel context, string modelPath) { DTOShopItem model = new DTOShopItem { Id = context.Id, Name = context.Name, Description = context.Description, Price = context.Price, PhotoPath = modelPath }; itemService.Edit(model); }
private ShopItemViewModel convertDTOtoVM(int id) { var context = shopItemService.Get(id); ShopItemViewModel model = new ShopItemViewModel { Id = context.Id, Name = context.Name, Description = context.Description, Price = context.Price, PhotoPath = context.PhotoPath }; return(model); }
public async Task <ServiceResult> Edit(Guid id, [FromBody] ShopItemEditModel apiEntity) { var entity = ShopItemEditModel.Map(apiEntity, id); var result = await _shopItemService.UpdateAsync(entity); if (result.TryCastModel(out ShopItem shopItem)) { result.ViewModel = ShopItemViewModel.Map(shopItem); } return(result); }
public async Task <ServiceResult> Add([FromBody] ShopItemAddModel apiEntity) { var entity = ShopItemAddModel.Map(apiEntity); var result = await _shopItemService.AddAsync(entity); if (result.TryCastModel(out ShopItem shopItem)) { result.ViewModel = ShopItemViewModel.Map(shopItem); } return(result); }
private void createItem(ShopItemViewModel context, string modelPath) { try { DTOShopItem model = new DTOShopItem { Name = context.Name, Description = context.Description, Price = context.Price, PhotoPath = modelPath }; itemService.Create(model); } catch (Exception) { throw new Exception("Failed to create item on server"); } }
public ActionResult ViewItemsByShop(int shopId) { ShopItemViewModel model = new ShopItemViewModel(); using (DataContext dbx = new DataContext()) { model = new ShopItemViewModel { Items = db.Items.Where(i => i.Shop.Id == shopId).ToList(), ShopId = shopId, ShopName = db.Shops.Where(s => s.Id == shopId).FirstOrDefault().Name, Shop = db.Shops.Find(shopId) }; } return(View(model)); }
public ActionResult Create(ShopItemViewModel context, HttpPostedFileBase image) { if (ModelState.IsValid) { AdminUIHelper helper = new AdminUIHelper(itemService); string serverImgPath = Path.Combine(Server.MapPath("~/Images"), helper.GetFullImageName(image)); image.SaveAs(serverImgPath); string modelPath = "~/Images/" + helper.GetFullImageName(image); helper.CreateItemOnServer(context, modelPath); return(RedirectToAction("AdminPanel")); } return(View()); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,Price,PhotoPath")] ShopItemViewModel context, HttpPostedFileBase image) { AdminUIHelper helper = new AdminUIHelper(itemService); string modelPath = context.PhotoPath; if (image != null) { string serverImgPath = Path.Combine(Server.MapPath("~/Images"), helper.GetFullImageName(image)); image.SaveAs(serverImgPath); string deletePath = Request.MapPath(helper.GetFullserverPath(context.Id)); helper.DeleteImageOnServer(deletePath); modelPath = "~/Images/" + helper.GetFullImageName(image); } helper.EditItemOnServer(context, modelPath); return(RedirectToAction("AdminPanel")); }
// GET: Shop public ActionResult Index(string name, string description, string price, string quantity) { try { //convert parameters to correct format Price = Convert.ToDouble(price); Quantity = Convert.ToInt32(quantity); //check for empty submits and add to object and list if input is provided if (name != null && description != null && price != null && quantity != null) { //create new object and add to the list ShopItemViewModel newItem = new ShopItemViewModel(name, description, Price, Quantity); Items.Add(newItem); } } catch (FormatException) { ViewBag.FormatException = "Price and Quantity needs to be a numeric value."; return(View("addItem")); } finally { if (price != null && quantity != null) { //Error check if price is a value higher than 0 if (Price <= 0 || Quantity <= 0) { ViewBag.Error = "Price and Quantity needs to be a value greater than zero."; } } } //create variable to count and store number of items in list int numberItems = Items.Count; //transfer number of items through viewbag ViewBag.Number = numberItems.ToString(); return(View(Items)); }
public async Task <IActionResult> GetShopItems(long accountId, CancellationToken cancellationToken) { var account = await _accountManager.GetAsync(accountId, cancellationToken); if (account == null) { return(NotFound()); } var payments = await _dataContext.Payments.Include(x => x.ShopItem) .Where(x => x.IsArchived == false && x.AccountId == accountId).ToListAsync(cancellationToken); List <ShopItem> shopItems = new List <ShopItem>(); foreach (var item in payments) { shopItems.Add(item.ShopItem); } return(Ok(ShopItemViewModel.MapAll(shopItems))); }
//Change item properties in Database public void EditItemOnServer(ShopItemViewModel context, string modelPath) { editItem(context, modelPath); }
public async Task <ShopItemViewModel> GetOne(Guid id) { var entity = await _shopItemService.FindByAsync(x => x.Id == id); return(ShopItemViewModel.Map(entity)); }
//Add new item in Database public void CreateItemOnServer(ShopItemViewModel context, string modelPath) { createItem(context, modelPath); }
public ActionResult ViewShopItems(int id) { ShopItemViewModel model = new ShopItemViewModel(); return(RedirectToAction("ViewItemsByShop", "Item", new { shopId = id })); }