public bool CreatePersonnel(PersonnelCreate model) { using (var ctx = new ApplicationDbContext()) { var user = ctx.Users.Find(_userId.ToString()); var userName = user.UserName; var entity = new Personnel() { Rank = model.Rank, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, Sex = model.Sex, SSN = model.SSN, DOD = model.DOD, DOB = model.DOB, MaritalStatus = model.MaritalStatus, CreatedBy = _userId, CreatedByUserName = userName, CreatedUtc = DateTimeOffset.Now, ModifiedLast = Guid.Empty }; ctx.PersonnelDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(PersonnelCreate personnelById) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreatePersonnelService(); if (!service.CreatePersonnel(personnelById)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create(PersonnelCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatePersonnelService(); if (service.CreatePersonnel(model)) { TempData["Save Result"] = "Record created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }
//Create Personnel public bool CreatePersonnel(PersonnelCreate model) { var entity = new Personnel() { FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, SSN = model.SSN, DOB = model.DOB, DOH = model.DOH, DOT = model.DOT, }; using (var ctx = new ApplicationDbContext()) { ctx.PersonnelDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PersonnelCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatePersonnelService(); if (service.CreatePersonnel(model)) { using (var ctx = new ApplicationDbContext()) { var count = ctx.PersonnelDbSet.Count(); TempData["Key Value"] = count++; TempData["Save Result"] = "Record created."; return(RedirectToAction("CreateContactRecord", "Record")); } } ; ModelState.AddModelError("", "Unable to create record."); return(View(model)); }