public void Create(Report report) { using (PhoneshopContext context = new PhoneshopContext()) { context.Reports.Add(report); context.SaveChanges(); } }
public ActionResult Create([Bind(Exclude = "Id")] ItemCreateViewModel model) { if (ModelState.IsValid) { Item item = new Item {Name = model.Name, Description = model.Description, Price = model.Price}; using (MemoryStream ms = new MemoryStream()) { model.Image.InputStream.CopyTo(ms); item.ImageBytes = ms.GetBuffer(); } item.ImageMIMEType = model.Image.ContentType; using (PhoneshopContext context = new PhoneshopContext()) { context.Items.Add(item); context.SaveChanges(); return RedirectToAction("Index"); } } return View(model); }