Exemple #1
0
        public IHttpResponse DoAddCake(DoAddCakesInputModel model)
        {
            // TODO: VALIDATE INPUT

            //CREATE PRODUCT
            //with object mapper
            var product = model.To <Product>();

            //without object mapper
            //var product = new Product
            //{
            //    Name = model.Name,
            //    Price = model.Price.ToDecimalOrDefault(),
            //    ImageUrl = model.ImageUrl
            //};

            this.Db.Products.Add(product);
            try
            {
                this.Db.SaveChanges();
            }
            catch (Exception e)
            {
                //TODO: log error
                return(this.ServerError(e.Message));
            }


            //REDIRECT TO PRODUCT DETAILS PAGE
            return(this.Redirect("/cakes/details?id=" + product.Id));
        }
Exemple #2
0
        public IHttpResponse DoAddCakes(DoAddCakesInputModel model)
        {
            var name    = model.Name.Trim();
            var price   = decimal.Parse(model.Price);
            var picture = model.Picture;

            // TODO: Validation

            var product = new Product
            {
                Name     = name,
                Price    = price,
                ImageUrl = picture
            };

            this.db.Products.Add(product);

            try
            {
                this.db.SaveChanges();
            }
            catch (Exception e)
            {
                // TODO: Log error
                return(this.ServerError(e.Message));
            }

            // Redirect
            return(this.Redirect("/"));
        }
Exemple #3
0
        public IHttpResponse Add(DoAddCakesInputModel model)
        {
            // TODO: Validation
            var product = model.To <Product>();

            this.Db.Products.Add(product);

            try
            {
                this.Db.SaveChanges();
            }
            catch (Exception e)
            {
                // TODO: Log error
                return(this.ServerError(e.Message));
            }

            // Redirect
            return(this.Redirect("/cakes/view?id=" + product.Id));
        }