public IActionResult Create(Product item) { _context.products.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetProduct", new{ id = item.productID }, item)); }
public IActionResult Create(Customer item) { _context.customers.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetCustomer", new{ id = item.customerID }, item)); }
public ActionResult Create(ProductViewModel viewModel) { Product product = new Product(); product.Name = viewModel.Name; product.Description = viewModel.Description; product.Price = viewModel.Price; product.CategoryID = viewModel.CategoryID; product.ProductImageMappings = new List <ProductImageMapping>(); //get a list of selected Images without any blanks string[] productImages = viewModel.ProductImages.Where(pi => !string.IsNullOrEmpty(pi)).ToArray(); for (int i = 0; i < productImages.Length; i++) { product.ProductImageMappings.Add(new ProductImageMapping { ProductImage = db.ProductImages.Find(int.Parse(productImages[i])), ImageNumber = i }); } if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } viewModel.CategoryList = new SelectList(db.Categories, "ID", "Name", product.CategoryID); viewModel.ImageLists = new List <SelectList>(); for (int i = 0; i < Constants.NumberOfProductImages; i++) { viewModel.ImageLists.Add(new SelectList(db.ProductImages, "ID", "FileName", viewModel.ProductImages[i])); } // ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", product.CategoryID); return(View(viewModel)); }
public IActionResult Create(Order item) { item.customers = _context.customers.Find(item.customerID); _context.orders.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetOrder", new{ id = item.orderID }, item)); }
public ActionResult Create([Bind(Include = "ID,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "Id,Name,Price,Description,DateOfAdding")] Good good) { if (ModelState.IsValid) { db.Goods.Add(good); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(good)); }
public ActionResult Create([Bind(Include = "Id,FName,LName,DateOfRegistration,Email")] User user) { if (ModelState.IsValid) { user.DateOfRegistration = DateTime.Now; db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
//Register user public bool Create(User item) { var result = _userManager.Create(item, item.PasswordHash); //_context.Users.Add(item); _context.SaveChanges(); if (result.Succeeded) { return(true); } return(false); }
public ActionResult Create([Bind(Include = "ID,ImageNumber,ProductID,ProductImageID")] ProductImageMapping productImageMapping) { if (ModelState.IsValid) { db.ProductImageMappings.Add(productImageMapping); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", productImageMapping.ProductID); ViewBag.ProductImageID = new SelectList(db.ProductImages, "ID", "FileName", productImageMapping.ProductImageID); return(View(productImageMapping)); }
public ActionResult Create([Bind(Include = "OrderID,UserID,DeliveryName,DeliveryAddress,TotalPrice,DateCreated")] Order order) { if (ModelState.IsValid) { order.DateCreated = DateTime.Now; db.Orders.Add(order); db.SaveChanges(); Basket basket = Basket.GetBasket(); order.TotalPrice = basket.CreateOrderLines(order.OrderID); db.SaveChanges(); return RedirectToAction("Details", new { id = order.OrderID }); } return RedirectToAction("Review"); }
public ActionResult Upload(HttpPostedFileBase file) { if (file != null) { if (ValidateFile(file)) { try { SaveFileToDisk(file); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); ModelState.AddModelError("FileName", "Error occured when saving file. Please try again"); } } else { ModelState.AddModelError("FileName", "The file must be in the correct format (gif,png,jpeg,jpg) and less than 2MB"); } } else { ModelState.AddModelError("FineName", "Please choose a file"); } if (ModelState.IsValid) { db.ProductImages.Add(new ProductImage { FileName = file.FileName }); try { db.SaveChanges(); } catch (DbUpdateException ex) { SqlException innerException = ex.InnerException.InnerException as SqlException; if (innerException != null && innerException.Number == 2601) { ModelState.AddModelError("FileName", "The file" + file.FileName + " already exists in the system. Please delete it and try again if you wish to re-add it"); } else { ModelState.AddModelError("FileName", "Sorry an error occurred saving the file to disk, please try again"); } return(View()); } return(RedirectToAction("Index")); } return(View()); }
public void SaveOrder(Order order) { /* * با افزودن سفارش نمی خواهیم محصولات داخل آن دوباره در دیتابیس اضافه شوند * چون محصولات را داریم یعنی قبلا اضافه شده اند * فقط می خواهیم سفارش و خطوط سفارش اضافه شود */ _ctx.AttachRange(order.Lines.Select(l => l.Product)); if (order.OrderId == 0) { _ctx.Orders.Add(order); } _ctx.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Quantity,Date,GoodId")] OrderViewModel orderViewModel) { if (ModelState.IsValid) { var dbOrder = new Order() { Quantity = orderViewModel.Quantity, Date = orderViewModel.Date }; dbOrder.Good = db.Goods.Find(orderViewModel.GoodId); db.Orders.Add(dbOrder); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderViewModel)); }
public ActionResult Delete(int customerId) { MyStoreContext _myStoreContext = new MyStoreContext(); Customer customer = _myStoreContext.Customer.Find(customerId); if (customer != null) { _myStoreContext.Customer.Remove(customer); _myStoreContext.SaveChanges(); } return(RedirectToAction("Index")); }
public IHttpActionResult PostProduct(ProductRequestModel requestModel) { Product product = new Product { StoreId = requestModel.StoreId.Value, Name = requestModel.Name }; _ctx.Products.Add(product); try { _ctx.SaveChanges(); } catch (Exception ex) { throw; } return(Created( Url.Link("DefaultApi", new { controller = "products", id = product.Id }), new ProductDto { Id = product.Id, StoreId = product.StoreId, Name = product.Name })); }
public ActionResult Edit(CustomerDetailsViewModel customerDetails) { MyStoreContext _myStoreContext = new MyStoreContext(); var customer = _myStoreContext.Customer.Find(customerDetails.CustomerId); if (ModelState.IsValid) { customer.FirstName = customerDetails.FirstName; customer.LastName = customerDetails.LastName; customer.ContactNumber = customerDetails.ContactNumber; _myStoreContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerDetails)); }
public ActionResult Delete(int?customerId) { MyStoreContext _myStoreContext = new MyStoreContext(); if (customerId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer customer = _myStoreContext.Customer.Find(customerId); ViewBag.Title = "Got a quarrel with " + customer.FirstName + " or something?"; _myStoreContext.Customer.Remove(customer); _myStoreContext.SaveChanges(); return(View(customer)); }
public ActionResult Index(HttpPostedFileBase file, DocumentDetailsViewModel docViewModel) { using (var dbContext = new MyStoreContext()) { if (file != null && file.ContentLength > 0) { try { Document doc = new Document() { Title = docViewModel.Title, Contents = new byte[file.ContentLength], UploadDate = DateTime.Now, UploadUserId = "*****@*****.**" }; dbContext.Document.Add(doc); dbContext.SaveChanges(); ViewBag.Message = "File uploaded successfully"; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } //go back to index and the new doc should show var docs = (dbContext.Document .OrderBy(u => u.UploadDate) .Select(d => new DocumentViewModel { DocumentId = d.DocumentId, Title = d.Title, UploadDate = d.UploadDate, UploadUserId = d.UploadUserId })); DocumentDetailsViewModel vm = new DocumentDetailsViewModel() { Documents = docs.ToList() }; return(View(vm)); } }
public ActionResult Create(CustomerDetailsViewModel customerDetails) { MyStoreContext _myStoreContext = new MyStoreContext(); if (ModelState.IsValid) { Customer customer = new Customer { FirstName = customerDetails.FirstName, LastName = customerDetails.LastName, ContactNumber = customerDetails.ContactNumber }; _myStoreContext.Customer.Add(customer); _myStoreContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerDetails)); }
public void AddToBasket(int productID, int quantity) { var basketLine = db.BasketLines.FirstOrDefault(b => b.BasketID == BasketID && b.ProductID == productID); if (basketLine == null) { basketLine = new BasketLine { ProductID = productID, BasketID = BasketID, Quantity = quantity, DateCreated = DateTime.Now }; db.BasketLines.Add(basketLine); } else { basketLine.Quantity += quantity; } db.SaveChanges(); }
public void Create(Mark item) { _context.Marks.Add(item); _context.SaveChanges(); }
public void Create(Category item) { _context.Categories.Add(item); _context.SaveChanges(); }
public void Save() { _context.SaveChanges(); }
public void Create(Product item) { _context.Products.Add(item); _context.SaveChanges(); }
public void Create(Picture item) { _context.Pictures.Add(item); _context.SaveChanges(); }
public void Create(Order item) { _context.Orders.Add(item); _context.SaveChanges(); }
public virtual bool Save() { _entities.SaveChanges(); return(true); }