示例#1
0
        //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"));
        }
示例#2
0
        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));
            }
        }
示例#4
0
        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));
        }
示例#5
0
        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);
 }               
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#12
0
 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");
     }
 }
示例#13
0
        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));
        }
示例#14
0
        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());
        }
示例#15
0
        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"));
        }
示例#16
0
        // 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));
        }
示例#17
0
        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)));
        }
示例#18
0
 //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));
        }
示例#20
0
 //Add new item in Database
 public void CreateItemOnServer(ShopItemViewModel context, string modelPath)
 {
     createItem(context, modelPath);
 }
示例#21
0
        public ActionResult ViewShopItems(int id)
        {
            ShopItemViewModel model = new ShopItemViewModel();

            return(RedirectToAction("ViewItemsByShop", "Item", new { shopId = id }));
        }