public bool CreateUnitInfo(UnitInfoCreate model) { using (var ctx = new ApplicationDbContext()) { var newEntry = ctx.PersonnelDbSet.OrderByDescending(o => o.PersonnelId).FirstOrDefault(); var newId = newEntry.PersonnelId; var entity = new UnitInfo() { PersonnelId = newId, Personnel = model.Personnel, TeamId = model.SelectedTeam, //Team = model.Team, Role = model.Role, Arrived = model.Arrived, LossDate = model.LossDate, DutyStatus = model.DutyStatus, CreatedBy = _userId, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; ctx.UnitInfoDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(UnitInfoCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateUnitInfoService(); if (service.CreateUnitInfo(model)) { TempData["Save Result"] = "Record created."; return(RedirectToAction("Index", "Record")); } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
public bool CreateUnitInfo(UnitInfoCreate model) { var entity = new UnitInfo() { PersonnelId = model.PersonnelId, Personnel = model.Personnel, TeamId = model.TeamId, Team = model.Team, Role = model.Role, Arrived = model.Arrived, LossDate = model.LossDate, DutyStatus = model.DutyStatus, CreatedBy = _userId, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; using (var ctx = new ApplicationDbContext()) { ctx.UnitInfoDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }