public void updateWeddingData(Wedding wedding) { var result = _db.Wedding.SingleOrDefault(m => m.SN == wedding.SN); if (result != null) { result.Checkin = wedding.Accompanied; result.UpdateTime = DateTime.Now; _db.SaveChanges(); } }
public JsonResult Upload() { for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; //Uploaded file //Use the following properties to get file's name, size and MIMEType int fileSize = file.ContentLength; string fileName = file.FileName; string mimeType = file.ContentType; System.IO.Stream fileContent = file.InputStream; //To save file, use SaveAs method YummyViewModel vm = new YummyViewModel(); var content = new byte[file.ContentLength]; file.InputStream.Read(content, 0, file.ContentLength); TSContext dbContext = new TSContext(); dbContext.Yummies.ToList()[0].Photo = content; dbContext.SaveChanges(); //assignment.FileLocation = content; file.SaveAs(Server.MapPath("~/") + fileName); //File will be saved in application root } return(Json("Uploaded " + Request.Files.Count + " files")); }
public ActionResult UpdateSave(TS model) { if (ModelState.IsValid) { using (TSContext db = new TSContext()) { if (db.TSses.Any(item => item.Surname.ToLower() == model.Surname.ToLower() && item.Phone == model.Phone)) { return(RedirectToAction("Index")); } if (db.TSses.Any(item => item.Surname.ToLower() == model.Surname.ToLower() && item.Id != model.Id)) { ModelState.AddModelError("", $"В справочнике уже есть фамилия {model.Surname}"); return(View(model)); } if (db.TSses.Any(item => item.Phone == model.Phone && item.Id != model.Id)) { ModelState.AddModelError("", $"В справочнике уже есть номер {model.Phone}"); return(View(model)); } db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } else { return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult AddSave(TS model) { if (ModelState.IsValid) { using (TSContext db = new TSContext()) { if (db.TSses.Any(item => item.Surname.ToLower() == model.Surname.ToLower())) { ModelState.AddModelError("", $"В справочнике уже есть фамилия {model.Surname}"); return(View(model)); } if (db.TSses.Any(item => item.Phone == model.Phone)) { ModelState.AddModelError("", $"В справочнике уже есть номер {model.Phone}"); return(View(model)); } db.TSses.Add(model); db.SaveChanges(); } } else { return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult DeleteSave(TS model) { using (TSContext db = new TSContext()) { db.TSses.Remove(db.TSses.Find(model.Id)); db.SaveChanges(); } return(RedirectToAction("Index")); }
public static void Main(string[] args) { var esCtx = new ESContext(); esCtx.Computers.Add(new Computer() { Description = "test", CoolingType = "none", Price = 333, Weight = 2 }); esCtx.SaveChanges(); var tsCtx = new TSContext(); tsCtx.Computers.Add(new TSComputer() { Description = "test", CoolingType = "none", Price = 333, Weight = 2, Server = new Server() { BandWidth = 100 } }); tsCtx.SaveChanges(); }
public static void Store(Account newAccount) { accountContext.Accounts.Add(newAccount); accountContext.SaveChanges(); }