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);
     }
 }
Пример #2
0
        public IHttpActionResult Post(PersonnelCreate personnelById)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreatePersonnelService();

            if (!service.CreatePersonnel(personnelById))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Пример #3
0
        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));
        }
Пример #4
0
        //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));
        }