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 ProduceBase AddProduce(ProduceAdd newItem)
        {
            int newId = (producers.Count > 0) ? newId = producers.Max(id => id.Id) + 1 : 1;

            // Create a new item; notice the property mapping
            var addedItem = new Produce
            {
                Id       = newId,
                Name     = newItem.Name,
                Location = newItem.Location,
                Price    = newItem.Price
            };

            producers.Add(addedItem);

            return(Mapper.Map <ProduceBase>(addedItem));
        }