public async Task <ActionResult> Create([Bind(Include = "CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] DashbordCustomer customers) { if (ModelState.IsValid) { Customers customer = new Customers() { CustomerID = CustomerId(), CompanyName = customers.CompanyName, ContactName = customers.ContactName, ContactTitle = customers.ContactTitle, Address = customers.Address, City = customers.City, Region = customers.Region, PostalCode = customers.PostalCode, Country = customers.Country, Phone = customers.Phone, Fax = customers.Fax }; db.Customers.Add(customer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(customers)); }
public async Task <ActionResult> Create([Bind(Include = "SupplierID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Suppliers suppliers) {//if inputs data correspond to the model if (ModelState.IsValid) { db.Suppliers.Add(suppliers); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(suppliers)); }
public async Task <ActionResult> Create([Bind(Include = "ShipperID,CompanyName,Phone")] Shippers shippers) { if (ModelState.IsValid) { db.Shippers.Add(shippers); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(shippers)); }
public async Task <ActionResult> Create([Bind(Include = "EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Notes,ReportsTo")] Employees employees) { if (ModelState.IsValid) { db.Employees.Add(employees); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ReportsTo = new SelectList(db.Employees, "EmployeeID", "LastName", employees.ReportsTo); return(View(employees)); }
public async Task <ActionResult> Create([Bind("ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Products products, IFormFile ProductImage) { try { if (!((ProductImage == null) || ProductImage.ContentType.Contains("image"))) { throw new ArgumentException("The provided file is not an image"); } if (ModelState.IsValid && !(String.IsNullOrEmpty(products.ProductName))) { db.Products.Add(products); await db.SaveChangesAsync(); if (ProductImage != null) { string path = System.IO.Path.Combine(Startup._hostingEnvironment.WebRootPath.Replace("\\", "/") + ($"Images/{db.Categories.Where(x => x.CategoryID == products.CategoryID).FirstOrDefault().CategoryName}/"), $"{products.ProductID}.jpg"); using (var fileStream = new FileStream(path, FileMode.Create)) { await ProductImage.CopyToAsync(fileStream); } } string category = ""; string search = ""; try { category = Request.HttpContext.Request.Query["category"]; search = Request.HttpContext.Request.Query["search"]; } catch { } return(RedirectToAction("Index", "Product", new { category = category, search = search })); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", products.CategoryID); ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", products.SupplierID); return(View(products)); } catch (ArgumentException e) { //todo //logger.Error(e.ToString()); throw new ArgumentException("Fisierul ales nu este o imagine"); } catch (Exception e) { //todo //logger.Error(e.ToString()); throw new Exception("Ceva nu a mers bine, va rugam reincercati. Daca problema persista contactati un administrator."); } }
public async Task <ActionResult> Create([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders) { if (ModelState.IsValid) { db.Orders.Add(orders); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", orders.CustomerID); ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", orders.EmployeeID); ViewBag.ShipVia = new SelectList(db.Shippers, "ShipperID", "CompanyName", orders.ShipVia); return(View(orders)); }
public async Task <ActionResult> Create([Bind(Include = "ProductID,Quantity,Discount")] Order_Details order_Details, int id) { order_Details.OrderID = id; order_Details.UnitPrice = db.Products.Find(order_Details.ProductID).UnitPrice ?? 0; if (ModelState.IsValid) { db.Order_Details.Add(order_Details); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Orders", new { id = id })); } //ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "CustomerID", order_Details.OrderID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", order_Details.ProductID); return(View(order_Details)); }
public async Task <ActionResult> Create([Bind("CategoryID,CategoryName,Description")] Categories categories) { if (!ModelState.IsValid) { return(View(categories)); } if (db.Categories.Where(c => c.CategoryName == categories.CategoryName).Count() != 0) { ModelState.AddModelError("CategoryName", "Numele de categorie este deja folosit"); return(View(categories)); } db.Categories.Add(categories); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Products products, HttpPostedFileBase ProductImage) { try { if (!((ProductImage == null) || ProductImage.ContentType.Contains("image"))) { throw new ArgumentException("The provided file is not an image"); } if (ModelState.IsValid && !(String.IsNullOrEmpty(products.ProductName))) { db.Products.Add(products); await db.SaveChangesAsync(); if (ProductImage != null) { string path = System.IO.Path.Combine(Server.MapPath($"~/images/{db.Categories.Where(x => x.CategoryID == products.CategoryID).FirstOrDefault().CategoryName}/"), $"{products.ProductID}.jpg"); ProductImage.SaveAs(path); } string category = ""; string search = ""; try { category = HttpUtility.ParseQueryString(Request.UrlReferrer.Query)["category"]; search = HttpUtility.ParseQueryString(Request.UrlReferrer.Query)["search"]; } catch { } return(RedirectToAction("Index", "Product", new { category = category, search = search })); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", products.CategoryID); ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", products.SupplierID); return(View(products)); } catch (ArgumentException e) { logger.Error(e.ToString()); throw new ArgumentException("Fisierul ales nu este o imagine"); } catch (Exception e) { logger.Error(e.ToString()); throw new Exception("Ceva nu a mers bine, va rugam reincercati. Daca problema persista contactati un administrator."); } }
public async Task <ActionResult> Create([Bind(Include = "RegionDescription")] Region region) { if (db.Territories.Any()) { region.RegionID = db.Regions.OrderByDescending(x => x.RegionID).First().RegionID + 1; } else { region.RegionID = 1; } if (ModelState.IsValid) { db.Regions.Add(region); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(region)); }
public async Task <ActionResult> Create([Bind(Include = "TerritoryDescription")] Territories territories, int id) { territories.RegionID = id; if (db.Territories.Any()) { var lastItem = db.Territories.Select(x => new { nr = x.TerritoryID }).ToList().OrderByDescending(x => int.Parse(x.nr)).First(); territories.TerritoryID = (int.Parse(lastItem.nr) + 1).ToString(); } else { territories.TerritoryID = "1"; } if (ModelState.IsValid) { db.Territories.Add(territories); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Regions", new { id = id })); } ViewBag.regionid = id; return(View(territories)); }
public async Task <ActionResult> CreateCustomers([Bind("CompanyName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customers) { try { if (!ModelState.IsValid) { return(View(customers)); } if (!String.IsNullOrEmpty(customers.Address)) { if (!String.IsNullOrEmpty(customers.Phone)) { Customers custom = new Customers() { CustomerID = CustomerId(), CompanyName = String.IsNullOrEmpty(customers.CompanyName) ? "Persoana fizica" : customers.CompanyName, ContactName = User.Identity.Name, ContactTitle = customers.ContactTitle, Address = customers.Address, City = customers.City, Region = customers.Region, PostalCode = customers.PostalCode, Country = customers.Country, Phone = customers.Phone, Fax = customers.Fax }; db.Customers.Add(custom); await db.SaveChangesAsync(); return(RedirectToAction("AssignCustomers", "Account")); } else { ModelState.AddModelError("Phone", "Introduceti numarul de telefon"); } } else { ModelState.AddModelError("Address", "Introduceti adresa"); } } catch (Exception /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(customers)); }