Exemplo n.º 1
0
        public ActionResult Create(ProduceAdd newItem)
        {
            ProduceBase addedItem = null;

            if (ModelState.IsValid)
            {
                addedItem = m.AddProduce(newItem);
            }
            else
            {
                return(View(newItem));
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 2
0
        public ActionResult AddToCart(ProduceBase newItem)
        {
            OrderBase addedItem = null;

            // Check that the incoming data is valid
            if (ModelState.IsValid)
            {
                addedItem = m.AddToCart(newItem);
                m.AddOrder(addedItem);
            }
            else
            {
                // Return the object so the user can edit it correctly
                return(View(newItem));
            }

            // If the incoming data is valid and the new data was added, redirect
            return(RedirectToAction("Index", "Produce"));
        }
Exemplo n.º 3
0
        public OrderBase AddToCart(ProduceBase newItem)
        {
            int newId = (orders.Count > 0) ? newId = orders.Max(id => id.Id) + 1 : 1;


            // Create a new item; notice the property mapping

            var addedItem = new ProduceOrderModel
            {
                Id    = newId,
                Price = newItem.Price,
            };

            addedItem.Id        = newId;
            addedItem.Price     = newItem.Price;
            addedItem.Quantity += 1;


            // Return the new item
            return(Mapper.Map <OrderBase>(addedItem));
        }