public ActionResult Create([Bind(Include = "ID,TypeName")] ProductType producttype) { if (ModelState.IsValid) { db.ProductTypes.Add(producttype); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(producttype)); }
public TEntity Add(TEntity entity) { context.Set <TEntity>().Add(entity); context.SaveChanges(); return(entity); }
protected void Session_Start() { var record = db.Statistics.Where(r => r.AccessDate.Day == DateTime.Now.Day && r.AccessDate.Month == DateTime.Now.Month && r.AccessDate.Year == DateTime.Now.Year).FirstOrDefault(); if (record == null) { db.Statistics.Add(new Model.Statistics { ProductID = 0, Accessions = 1, AccessDate = DateTime.Now }); } else { record.Accessions += 1; db.Entry(record).State = EntityState.Modified; } db.SaveChanges(); var themeSetting = db.AppSettings.Find("Theme"); if (themeSetting != null) { HttpCookie themeCookie = new HttpCookie("Theme", themeSetting.Value); Response.Cookies.Add(themeCookie); } }
public ActionResult Sales() { var userProperty = db.UserProperties.Find(User.Identity.Name); if (userProperty == null) { userProperty = new Model.UserProperty(); userProperty.Username = User.Identity.Name; userProperty.AttendanceList = "0000000"; db.UserProperties.Add(userProperty); db.SaveChanges(); } var offers = db.Offers.ToList(); ViewBag.UserProperty = userProperty; return(View(offers)); }
public ActionResult Create([Bind(Include = "ID,Percent,OverduedDate,Desc,Image,CoinsConsumed")] Offer offer, HttpPostedFileBase imgFile) { if (ModelState.IsValid) { string fileName = Path.GetFileNameWithoutExtension(imgFile.FileName); string extension = Path.GetExtension(imgFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; offer.Image = "~/Content/UserImages/" + fileName; fileName = Path.Combine(Server.MapPath("~/Content/UserImages/"), fileName); imgFile.SaveAs(fileName); db.Offers.Add(offer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(offer)); }
public ActionResult Edit([Bind(Include = "ID,ProductName,Image,Url,Price,SalePrice,IsOnSale,ShortDesc,Desc,ProductTypeID,UploaderID")] Product product, HttpPostedFileBase imgFile) { if (ModelState.IsValid) { if (imgFile != null) { if (!string.IsNullOrEmpty(product.Image)) { string currentFilePath = Path.Combine(Server.MapPath("~/Content/UserImages/"), Path.GetFileName(product.Image)); if (System.IO.File.Exists(currentFilePath)) { System.IO.File.Delete(currentFilePath); } } string fileName = Path.GetFileNameWithoutExtension(imgFile.FileName); string extension = Path.GetExtension(imgFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; product.Image = "~/Content/UserImages/" + fileName; fileName = Path.Combine(Server.MapPath("~/Content/UserImages/"), fileName); imgFile.SaveAs(fileName); } if (product.ID == 0) { db.Products.Add(product); } else { db.Entry(product).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "ID", "TypeName", product.ProductTypeID); return(View(product)); }
public JsonResult SetTheme(string theme) { try { var themeSetting = db.AppSettings.Find("Theme"); themeSetting.Value = theme; db.Entry(themeSetting).State = EntityState.Modified; db.SaveChanges(); return(Json(new { IsSuccessful = 1 })); } catch (Exception ex) { return(Json(new { IsSuccessful = 0, Msg = ex.Message })); } }
public int Commit() { return(context.SaveChanges()); }