protected void Create_Click(object sender, EventArgs e) { if (this.ModelState.IsValid) { var catalogItem = new CatalogItem { Name = Name.Text, Description = Description.Text, CatalogBrandId = int.Parse(Brand.SelectedValue), CatalogTypeId = int.Parse(Type.SelectedValue), Price = decimal.Parse(Price.Text), AvailableStock = int.Parse(Stock.Text), RestockThreshold = int.Parse(Restock.Text), MaxStockThreshold = int.Parse(Maxstock.Text), TempImageName = TempImageName.Value }; if (!string.IsNullOrEmpty(catalogItem.TempImageName)) { var fileName = Path.GetFileName(catalogItem.TempImageName); catalogItem.PictureFileName = fileName; } CatalogService.CreateCatalogItem(catalogItem); if (!string.IsNullOrEmpty(catalogItem.TempImageName)) { ImageService.UpdateImage(catalogItem); } Response.Redirect("~"); } }