public static int CreateFile(File model) { try { using (var ctx = new PosContext()) { ctx.File.Add(model); ctx.SaveChanges(); return model.Id; } } catch (Exception ex) { return -1; } }
public ActionResult Create(Property property) { if (ModelState.IsValid) { property.CreatedByEmail = GlobalVariables.CurrentUserEmail; property.CreatedDateTime = DateTime.Now; var propertyId = PropertyContext.CreateProperty(property); var httpPostedFileBase = Request.Files["file"]; if (httpPostedFileBase != null) using (var binaryReader = new BinaryReader(httpPostedFileBase.InputStream)) { File file = new File { Content = binaryReader.ReadBytes(httpPostedFileBase.ContentLength), FileName = httpPostedFileBase.FileName, ContentType = httpPostedFileBase.ContentType, PropertyId = propertyId }; FileContext.CreateFile(file); } return RedirectToAction("Index"); } var agencyId = GetAgencyId(); ViewBag.AgencyId = agencyId; var landlords = AgencyContext.GetAgencyLandlords(agencyId); if (landlords.Count <= 0) { TempData["message"] = "You have no landlords to assign a property to"; return RedirectToAction("Index"); } ViewBag.LandlordId = new SelectList(landlords, "Id", "AddressLine"); return View(property); }