public ActionResult Create(HousingCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateHousingService(); if (service.CreateHousing(model)) { TempData["Save Result"] = "Record created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
public bool CreateHousing(HousingCreate model) { var entity = new Housing() { PersonnelId = model.PersonnelId, Personnel = model.Personnel, Address = model.Address, Room = model.Room, CreatedBy = _userId, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; using (var ctx = new ApplicationDbContext()) { ctx.HousingDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateHousing(HousingCreate model) { using (var ctx = new ApplicationDbContext()) { var newEntry = ctx.PersonnelDbSet.OrderByDescending(o => o.PersonnelId).FirstOrDefault(); var newId = newEntry.PersonnelId; var entity = new Housing() { PersonnelId = newId, Personnel = model.Personnel, Address = model.Address, Room = model.Room, CreatedBy = _userId, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; ctx.HousingDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(HousingCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateHousingService(); if (service.CreateHousing(model)) { using (var ctx = new ApplicationDbContext()) { var newEntry = ctx.PersonnelDbSet.OrderByDescending(o => o.PersonnelId).FirstOrDefault(); TempData["Key Value"] = newEntry.PersonnelId; TempData["Save Result"] = "Record created."; return(RedirectToAction("CreateUnitInfoRecord", "Record")); } } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
// Post public bool CreateHousing(HttpPostedFileBase file, HousingCreate model) { model.Image = ConvertToBytes(file); var entity = new Housing() { Name = model.Name, Address = model.Address, UnitsAvailable = model.UnitsAvailable, AcceptVoucher = model.AcceptVoucher, SectionType = model.SectionType, Image = model.Image }; using (var ctx = new ApplicationDbContext()) { ctx.Housings.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(HousingCreate model) { HttpPostedFileBase file = Request.Files["ImageData"]; if (!ModelState.IsValid) { return(View(model)); } var service = CreateHousingService(); if (service.CreateHousing(file, model)) { TempData["SaveResult"] = "The Housing was succesfully created"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Your Housing could not be added"); //return View(model); return(RedirectToAction("Index")); }