Пример #1
0
        /// <summary>Adds a product.</summary>
        /// <param name="product">The product to add.</param>
        /// <returns>The added product.</returns>
        public Product Add(Product product)
        {
            Verify.ArgumentIsValidAndNotNull(nameof(product), product);

            //Emulate database by storing copy
            return(AddCore(product));
        }
Пример #2
0
        /// <summary>Updates a product.</summary>
        /// <param name="product">The product to update.</param>
        /// <returns>The updated product.</returns>
        public Product Update(Product product)
        {
            Verify.ArgumentIsValidAndNotNull(nameof(product), product);

            //Get existing product
            var existing = GetCore(product.Id);

            if (existing == null)
            {
                throw new InvalidOperationException("Product not found.");
            }

            return(UpdateCore(existing, product));
        }
Пример #3
0
        public ScheduledEvent Add(ScheduledEvent evt)
        {
            Verify.ArgumentIsValidAndNotNull(nameof(evt), evt);

            var existing = FindByName(evt.Name);

            if (existing != null)
            {
                throw new Exception("Event already exists.");
            }

            var newEvt = CloneEvent(evt);

            evt.Id = newEvt.Id = _id++;

            _items.Add(newEvt);

            return(evt);
        }
Пример #4
0
        public ActionResult Create(ScheduledEventModel evntModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Verify.ArgumentIsValidAndNotNull(evntModel.Name, evntModel);

                    ScheduledEvent evnt = evntModel.ToDomain();

                    DatabaseFactory.Database.Add(evnt);

                    return(RedirectToAction((evnt.IsPublic) ? "All" : "My"));
                }catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }

            return(View(evntModel));
        }