public Order Create(Order order) { _context.Orders.Add(order); var result = _context.SaveChanges(); return(order); }
public Review Create(Review review) { _context.Reviews.Add(review); var result = _context.SaveChanges(); return(review); }
public Product Create(Product product) { _context.Products.Add(product); var result = _context.SaveChanges(); return(product); }
public IHttpActionResult PutItem(long id, Item item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != item.ItemID) { return(BadRequest()); } db.Entry(item).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ProductID,Title,Description,Price,Delivery,Category")] Product product, HttpPostedFileBase file) { if (file != null) { var dir_path = Server.MapPath("/Images/" + "\\"); var site_path = "/Images/"; var file_name = file.FileName; var path = dir_path + file_name; if (System.IO.File.Exists(path)) { } file.SaveAs(path); foreach (User user in db.Users.ToList()) { if (SessionContainer.UserID.ToString().Equals(user.ID.ToString())) { product.Seller = user; } } if (ModelState.IsValid) { product.Image = site_path + file_name; product.Status = false; product.CreatedDate = DateTime.Now; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(HttpNotFound()); } } return(View(product)); }
public Category Create(Category category) { _context.Categories.Add(category); var result = _context.SaveChanges(); return(category); }
public User Create(User user) { _context.Users.Add(user); var result = _context.SaveChanges(); return(user); }
public IHttpActionResult PutCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.CateoryID) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool dbMarketContextTranIslemiSiparisveDetayKaydet(Siparis yeniSiparis, List <SiparisDetayi> SiparisDetayListesi) { MarketContext db = new MarketContext(); bool durum = false; using (var tran = db.Database.BeginTransaction()) { try { db.Siparisler.Add(yeniSiparis); db.SaveChanges(); foreach (SiparisDetayi item in SiparisDetayListesi) { item.SiparisID = yeniSiparis.SiparisID; db.SiparisDetaylari.Add(item); } db.SaveChanges(); tran.Commit(); durum = true; } catch (Exception ex) { tran.Rollback(); throw ex; } } return(durum); }
public bool dbMarketContextSiparisIptalEt(Siparis siparis) { List <SiparisDetayi> siparisDetaylari = new SiparisDetayiRepo().GetAll().Where(x => x.SiparisID == siparis.SiparisID).ToList(); bool iptalDurumu = false; MarketContext db = new MarketContext(); using (var tran = db.Database.BeginTransaction()) { try { foreach (SiparisDetayi item in siparisDetaylari) { db.SiparisDetaylari.Remove(item); db.SaveChanges(); } db.Siparisler.Remove(siparis); db.SaveChanges(); iptalDurumu = true; } catch (Exception ex) { tran.Rollback(); throw ex; } } return(iptalDurumu); }
static void Purchase(User user) { Console.Clear(); ShowAssortimentsList(); Console.WriteLine("*********************************\n" + "Добавьте в корзину товар для пoкупки по его номеру: "); int choice = 0; Market market = new Market(); using (var context = new MarketContext()) { while (choice == 0) { int.TryParse(Console.ReadLine(), out choice); if (choice < 0 || choice > context.Markets.Count()) { choice = 0; } else { market = context.Markets.FirstOrDefault(m => m.Id == choice); break; } } Basket basket = new Basket { UserId = user.Id, User = user, MarketId = market.Id, Market = market }; context.Baskets.Add(basket); context.SaveChanges(); List <Basket> baskets = new List <Basket>(); Console.WriteLine("Просмотр корзины: "); foreach (var b in context.Baskets.ToList()) { Console.WriteLine($"Пользователь: {b.User.Email}," + $" Товар: {b.Market.Product}," + $" Цена: {b.Market.Price}," + $" Вес(кг.): {b.Market.Quantity},"); baskets.Add(b); } foreach (var b in baskets) { if (b != null) { context.Baskets.Remove(b); context.SaveChanges(); } } } }
public ActionResult Create([Bind(Include = "EmployeeID,firstName,lastName,Salary,bonusPercent,DateOfBirth,StartTime,Email,URL,DocumentTypeID,DocumentNumber")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); } var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(dba)); var user = userManager.FindByName(employee.Email); if (user == null) { user = new ApplicationUser { UserName = employee.Email, Email = employee.Email }; userManager.Create(user, employee.Email); userManager.AddToRole(user.Id, "View"); dba.SaveChanges(); return(RedirectToAction("Index")); } ; ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", employee.DocumentTypeID); return(View(employee)); }
public void AddToCart(Product product) { _marketContext.ShopCartItem.Add(new ShopCartItem { ShopCartId = ShopCartId, Product = product, Price = product.Price }); _marketContext.SaveChanges(); }
public JsonResult Register(string UserID, string Password) { List <Models.User> lst = db.Users.Where(m => m.UserID == UserID).ToList(); if (lst.Count > 0) { return(Json(0)); } else { Models.User user = new Models.User(); user.UserID = UserID; user.Password = Password; user.CreateTime = System.DateTime.Now; db.Users.Add(user); db.SaveChanges(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, user.ID.ToString(), DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), false, "guest" ); HttpCookie cookie = new HttpCookie( FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket) ); Response.Cookies.Add(cookie); return(Json(1)); } //return Json("Login"); }
public ActionResult Create([Bind(Include = "ID,Name,JoinDate,location")] Author author) { if (ModelState.IsValid) { db.Authors.Add(author); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(author)); }
public ActionResult Create([Bind(Include = "SupplierID,Name,ContactFirstName,ContactLastName,Phone,Address,Email")] Supplier supplier) { if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Create([Bind(Include = "ProductID,Description,Price,LastBuy,Stock,Remarks")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "ID,Name,Price,Picture,Category")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "CategoryId,CategoryName")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "DocumentTypeID,Description")] DocumentType documentType) { if (ModelState.IsValid) { db.DocumentTypes.Add(documentType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(documentType)); }
public ActionResult Create([Bind(Include = "TrademarkID,Name,State")] Trademark trademark) { if (ModelState.IsValid) { db.Trademark.Add(trademark); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trademark)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Age")] Driver driver) { if (ModelState.IsValid) { db.Drivers.Add(driver); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(driver)); }
public ActionResult Create([Bind(Include = "ProductID,Description,Price,Margin,Remarks")] Product product) { if (ModelState.IsValid) { product.Margin = float.Parse(Request["Margin"]) / 100; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,Salary,BonusPercent,DateOfBirth,StartTime,Email,URL,DocumentTypeID")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", employee.DocumentTypeID); return View(employee); }
public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,Phone,Address,Email,Document,DocumentTypeID")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", customer.DocumentTypeID); return(View(customer)); }
public ActionResult Create([Bind(Include = "OrderDetailID,OrderID,ProductID,Description,Price,Quantity")] OrderDetail orderDetail) { if (ModelState.IsValid) { db.OrderDetail.Add(orderDetail); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Description", orderDetail.ProductID); return(View(orderDetail)); }
public ActionResult Create(Flavor flavor, int TreatId) { _db.Flavors.Add(flavor); if (TreatId != 0) { _db.TreatFlavor.Add(new TreatFlavor() { TreatId = TreatId, FlavorId = flavor.FlavorId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public void ParseStoresXml(MarketContext context, string filePath) #region Parse and add Chains to DB { var doc = XDocument.Load(filePath); //Root element query for ChainId, ChainName and LastUpdateDate, creating "Chain" object: long chainId; long.TryParse(doc.Root?.Element("ChainId")?.Value, out chainId); string chainName = doc.Root?.Element("ChainName")?.Value; DateTime lastUpdateDate; DateTime.TryParse(doc.Root?.Element("LastUpdateDate")?.Value, out lastUpdateDate); var chain = new Chain() { ChainID = chainId, Name = chainName }; context.Chains.AddOrUpdate(chain); context.SaveChanges(); #endregion #region Parse and add Stores to DB //Link to xml query for all other fields, creating "Store" object: long storeId = -1; var storesData = (from element in doc.Descendants("StoreId") let storeElement = element.Parent //Choose only elements where StoreID can be parsed where long.TryParse(storeElement.Element("StoreId")?.Value, out storeId) select new Store() { StoreID = storeId, ChainID = chainId, Name = storeElement.Element("StoreName")?.Value, Address = storeElement.Element("Address")?.Value, City = storeElement.Element("City")?.Value, UpdateDate = lastUpdateDate, //Store object has a chain object in a one to one DB relationship. Chain = context.Chains.Find(chainId) }).Distinct(); foreach (var store in storesData) { context.Stores.AddOrUpdate(store); } context.SaveChanges(); #endregion }
public virtual ActionResult Delete(long id) { try { using (var db = new MarketContext()) { var models = db.Set <T>(); var model = models.Find(id); if (model == null) { throw new Exception("رکورد با ایدی داده شد یافت نشد"); } db.Entry(model).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Images")); } catch (Exception e) { Console.WriteLine(e); return(PartialView("Error", e)); } }
public virtual ActionResult DeleteImage(long id, long productId) { try { using (var db = new MarketContext()) { var img = db.Images.Find(id); if (img == null) { throw new Exception("رکورد با ایدی داده شد یافت نشد"); } db.Images.Remove(img); db.SaveChanges(); } return(RedirectToAction("Images", new{ id = productId })); } catch (Exception e) { Console.WriteLine(e); return(PartialView("Error", e)); } }