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)); }
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("/")); }
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)); }