public ActionResult Create([Bind(Exclude = "Id")] Product product) { try { //foto opslaan in de map Images en de URL daarvan opslaan in de database zodat deze kan worden uitgelezen string filename = Path.GetFileNameWithoutExtension(product.ImageFile.FileName); string extention = Path.GetExtension(product.ImageFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extention; product.Foto = "~/Images/" + filename; filename = Path.Combine(Server.MapPath("~/Images/"), filename); product.ImageFile.SaveAs(filename); string filename2 = Path.GetFileNameWithoutExtension(product.ImageFile2.FileName); string extention2 = Path.GetExtension(product.ImageFile2.FileName); filename2 = filename2 + DateTime.Now.ToString("yymmssfff") + extention2; product.AchtergrondFoto = "~/Images/" + filename2; filename2 = Path.Combine(Server.MapPath("~/Images/"), filename2); product.ImageFile2.SaveAs(filename2); //Keycode en product toevoegen aan database ProductLogic.CreateProduct(product, product.Hoeveelheid); return(RedirectToAction("Product")); } catch (Exception ex) { string error = ex.ToString(); return(View()); } }
private void btn_Save_Click(object sender, RoutedEventArgs e) { try { Categories chosenCategory = (Categories)lstbx_Categories.SelectedItem; product.CategoryID = chosenCategory.CategoryID; bool wasSuccess = interaction.CreateProduct(product); if (check.CheckTextBoxInputChars(txtbx_Price.Text) == true) { CreateMessage.ShowInputNotValid(); } else if (check.CheckTextBoxInputInteger(txtbx_Price.Text) == true) { CreateMessage.ShowInputNotValid(); } else { if (wasSuccess) { MessageBox.Show("Product was created successfully."); } if (!wasSuccess) { MessageBox.Show("Something went wrong, try again. If this problem persists contact admin."); } this.Content = null; NavigationService.Navigate(new ViewProducts()); } } catch (Exception ex) { ErrorHandler.Log.WriteFail(ex); CreateMessage.ShowInputNotValid(); } }
public void createProduct() { var status = logic.CreateProduct(new Product() { Name = "Pro1", ProductCode = "PRO-01", CreatedDate = DateTime.Now.Date.ToString(), Description = "Product one", ImagePath = "P1.png" }); Assert.IsTrue(status); }
public HttpResponseMessage CreateProduct(Product model) { var status = logic.CreateProduct(model); if (status) { return(Request.CreateResponse(HttpStatusCode.Created, "Created the Product")); } else { return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, "Failed to create Product due to internal error")); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ProductDetails pd = new ProductDetails(); pd.ProductName = txtName.Text; pd.Description = txtDescription.Value; pd.Quantity = Convert.ToInt32(txtQuantity.Text); pd.Price = Convert.ToDecimal(txtUnitPrice.Text); pd.SupplierId = Convert.ToInt32(ddlSupplier.SelectedValue); pd.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); pl.CreateProduct(pd); Response.Redirect("Product.aspx"); } }
static void Main(string[] args) { var finalizar = false; var connectionString = "Server=DESKTOP-RCIFPVC\\SQLEXPRESS; Database=Tienda; User Id=labUser; Password=Password01.;"; IProductLogic logic = new ProductLogic(new ProductDataAccessDatabase(connectionString)); while (!finalizar) { Console.WriteLine(@"Las opciones disponibles son 1 listado de productos 2 alta de producto 3 eliminar producto 4 modificar producto 5 Obtener productos filtrados 6 salir "); var entrada = Console.ReadLine(); switch (entrada) { case "1": { Console.WriteLine("listado"); var productos = logic.ListProducts(); if (!productos.Any()) { Console.WriteLine("No hay productos"); } foreach (var producto in productos) { Console.WriteLine($" id {producto.Id}, Nombre {producto.Name}, Descripcion {producto.Description}, Precio {producto.Price}"); } break; }; case "2": { Console.WriteLine("alta"); Console.WriteLine("Ingrese id"); if (!int.TryParse(Console.ReadLine(), out int id)) { Console.WriteLine("Id incorrecto"); break; } var newProduct = RequestProductData(id); if (newProduct != null) { try { logic.CreateProduct(newProduct); } catch (Exception) { Console.WriteLine("hubo un error al ingresar el producto"); } } break; }; case "3": { Console.WriteLine("eliminar"); Console.WriteLine("Ingrese id"); if (!int.TryParse(Console.ReadLine(), out int id)) { Console.WriteLine("Id incorrecto"); break; } try { var success = logic.DeleteProduct(id); if (success) { Console.WriteLine("Producto eliminado"); } else { Console.WriteLine("No se encontró el producto"); } } catch (Exception) { Console.WriteLine("hubo un error al eliminar el producto"); } break; }; case "4": { Console.WriteLine("modificar"); Console.WriteLine("Ingrese id a modificar"); if (!int.TryParse(Console.ReadLine(), out int id)) { Console.WriteLine("Id incorrecto"); break; } try { var product = logic.GetProduct(id); if (product == null) { Console.WriteLine("El producto no existe"); break; } else { var newProductData = RequestProductData(id); if (newProductData != null) { newProductData.Id = id; logic.UpdateProduct(newProductData); Console.WriteLine("Producto actualizado"); } } } catch (Exception) { Console.WriteLine("hubo un error al modificar el producto"); } break; }; case "5": { Console.WriteLine("Obtener producto filtrado"); Console.Write("PageIndex: "); int pageIndex = int.Parse(Console.ReadLine()); Console.Write("PageSize: "); int pageSize = int.Parse(Console.ReadLine()); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("CategoryId: "); int categoryId; int.TryParse(Console.ReadLine(), out categoryId); Console.Write("OrderByNameOrPrice: "); string orderby = Console.ReadLine(); Console.Write("AscOrDesc: "); string asc = Console.ReadLine(); var products = logic.GetProductsPaginated(pageIndex, pageSize, name, categoryId, orderby, asc); foreach (var producto in products) { Console.WriteLine($" id {producto.Id}, Nombre {producto.Name}, Descripcion {producto.Description}, Precio {producto.Price}"); } break; }; case "6": { Console.WriteLine("salir"); finalizar = true; break; }; default: { Console.WriteLine("Opcion incorrecta"); break; }; } } }