public HttpResponse Add(ProductAddInputModel inputModel) { if (!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()); } //TODO if price is empty make validation //if (inputModel.Price.Equals("")) //{ // return this.Redirect("/"); //} var productId = this.productsService.Add(inputModel); // return this.View(); return(this.Redirect($"/Products/Details?id={productId}")); }
public HttpResponse Add(ProductAddInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20 || string.IsNullOrWhiteSpace(inputModel.Name)) { return(this.Error("Name lenght must be between 4 and 20 symbols!")); } if (inputModel.Price <= 0 || string.IsNullOrWhiteSpace(inputModel.Price.ToString())) { return(this.Error("Invalid price!")); } if (string.IsNullOrEmpty(inputModel.Description) || inputModel.Description.Length > 10) { return(this.Error("Description must be less than 10 symbols!")); } var productId = this.productsService.Add(inputModel); return(this.Redirect($"/Products/Details?id={productId}")); }
public HttpResponse Add(ProductAddInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect(this.loginUrl)); } if (string.IsNullOrWhiteSpace(inputModel.Name)) { // return this.Error(string.Format(this.requiredError, "Name")); return(this.View()); } if (string.IsNullOrWhiteSpace(inputModel.Description)) { // return this.Error(string.Format(this.requiredError, "Description")); return(this.View()); } if (string.IsNullOrEmpty(inputModel.Price.ToString())) { // return this.Error(string.Format(this.requiredError, "Price")); return(this.View()); } if (string.IsNullOrWhiteSpace(inputModel.Category)) { // return this.Error(string.Format(this.requiredError, "Category")); return(this.View()); } if (string.IsNullOrWhiteSpace(inputModel.Gender)) { // return this.Error(string.Format(this.requiredError, "Gender")); return(this.View()); } if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20) { // return this.Error("Product Name should be between 4 and 20 characters!"); return(this.View()); } if (inputModel.Description.Length > 10) { // return this.Error("Product Description should be max 10 characters long!"); return(this.View()); } var productId = this.productsService.Add(inputModel); return(this.Redirect($"/Products/Details?id={productId}")); }
public int Add(ProductAddInputModel model) { var categoryEnum = Enum.Parse <Category>(model.Category); var genderEnum = Enum.Parse <Gender>(model.Gender); var product = new Product() { Name = model.Name, Description = model.Description, ImageUrl = model.ImageUrl, Price = model.Price, Category = categoryEnum, Gender = genderEnum }; this.db.Products.Add(product); this.db.SaveChanges(); return(product.Id); }
public HttpResponse Add(ProductAddInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(inputModel.Name) || inputModel.Name.Length < 4 || inputModel.Name.Length > 20) { return(this.View()); } if (string.IsNullOrWhiteSpace(inputModel.Name) || inputModel.Description.Length > 10) { return(this.View()); } var productId = this.productsService.Add(inputModel); return(this.Redirect("/Products/Details?id=" + productId)); }
public int Add(ProductAddInputModel productAddInputModel) { var categoryAsEnum = Enum.Parse <Category>(productAddInputModel.Category); var genderAsEnum = Enum.Parse <Gender>(productAddInputModel.Gender); var product = new Product { Name = productAddInputModel.Name, Description = productAddInputModel.Description, ImageUrl = productAddInputModel.ImageUrl, Price = productAddInputModel.Price, Category = categoryAsEnum, Gender = genderAsEnum, }; this.dbContext.Products.Add(product); this.dbContext.SaveChanges(); return(product.Id); }
public HttpResponse Add(ProductAddInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name.Length < 4 || model.Name.Length > 20) { return(this.View()); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length > 10) { return(this.View()); } var productId = this.productService.Add(model); return(this.Redirect($"/Products/Details?id={productId}")); }
public HttpResponse Add(ProductAddInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name?.Length < 4 || model.Name?.Length > 20) { return(this.Redirect("/Products/Add")); } if (!string.IsNullOrWhiteSpace(model.Description)) { if (model.Description.Length > 10) { return(this.Redirect("/Products/Add")); } } else { model.Description = null; } if (model.Price < 0.01M) { return(this.Redirect("/Products/Add")); } this.productsService.Add( model.Name, model.Description, model.ImageUrl, model.Category, model.Gender, model.Price); return(this.Redirect("/")); }
public HttpResponse Add(ProductAddInputModel inputModel) { var productId = productsService.Add(inputModel); return(this.View()); }