Beispiel #1
0
        public Item CreateItem([FromBody] NewItemForm form)
        {
            form.Price = form.Price.Replace("$", "");
            using (var context = new DbContext())
            {
                var seller = _accountService.ValidateSellerSession(Request.Cookies, context);
                if (seller == null)
                {
                    Response.StatusCode = 403;
                    return(null);
                }

                var item = context.Items.Add(new Item
                {
                    Description = form.Description,
                    Name        = form.Name,
                    Price       = decimal.Parse(form.Price),
                    SellerId    = seller.Id,
                    ImageURL    = form.ImageURL,
                    Hidden      = false,
                    Purchases   = 0
                });
                context.SaveChanges();

                return(item.Entity);
            }
        }
Beispiel #2
0
        public ActionResult New(NewItemForm form)
        {
            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            _context.Items.Add(new Item
            {
                ItemName = form.ItemName,
                ItemCode = form.ItemCode,
                Price    = form.Price,
            });

            _context.SaveChanges();

            return(RedirectToAction <ItemController>(c => c.Index())
                   .WithSuccess("Item created!"));
        }
Beispiel #3
0
        public ActionResult New()
        {
            var form = new NewItemForm();

            return(View(form));
        }