public void AddProduct(ProductsAddInputModel input) { var product = new Product { Name = input.Name, Description = input.Description, ImageUrl = input.ImageUrl, Category = Enum.Parse <Category>(input.Category), Gender = Enum.Parse <Gender>(input.Gender), Price = input.Price, }; this.db.Products.Add(product); this.db.SaveChanges(); }
public HttpResponse Add(ProductsAddInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (input.Name.Length <= 4 || input.Name.Length >= 20 || input.Name == null || input.Description.Length >= 10 || input.Description == null || input.Price < 0 || input.Category == null || input.Gender == null) { return(this.Redirect("/Products/Add")); } this.productsService.AddProduct(input); return(this.Redirect("/")); }
public int Add(ProductsAddInputModel productAddInputModel) { var genderAsEnum = Enum.Parse <Gender>(productAddInputModel.Gender); var categoryAsEnum = Enum.Parse <Category>(productAddInputModel.Category); var product = new Product() { Name = productAddInputModel.Name, Description = productAddInputModel.Description, ImageUrl = productAddInputModel.ImageUrl, Price = productAddInputModel.Price, Gender = genderAsEnum, Category = categoryAsEnum }; this.dbContext.Products.Add(product); this.dbContext.SaveChanges(); return(product.Id); }
public HttpResponse Add(ProductsAddInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20) { return(this.View()); } if (string.IsNullOrEmpty(inputModel.Description) || inputModel.Description.Length > 10) { return(this.View()); } var productId = this.productsService.Add(inputModel); return(this.Redirect($"/Products/Details?id={productId}")); }