コード例 #1
0
 public bool UpdatePersonnel(PersonnelEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var user     = ctx.Users.Find(_userId.ToString());
         var userName = user.UserName;
         var entity   =
             ctx
             .PersonnelDbSet
             .Single(e => e.PersonnelId == model.PersonnelId);
         entity.Rank               = model.Rank;
         entity.FirstName          = model.FirstName;
         entity.LastName           = model.LastName;
         entity.MiddleName         = model.MiddleName;
         entity.Sex                = model.Sex;
         entity.SSN                = model.SSN;
         entity.DOD                = model.DOD;
         entity.DOB                = model.DOB;
         entity.MaritalStatus      = model.MaritalStatus;
         entity.ModifiedByUserName = userName;
         entity.ModifiedLast       = _userId;
         entity.ModifiedUtc        = DateTimeOffset.Now;
         return(ctx.SaveChanges() == 1);
     }
 }
コード例 #2
0
        //GET: Personnel/Edit/id
        public ActionResult Edit(int id)
        {
            var svc    = CreatePersonnelService();
            var detail = svc.GetPersonnelById(id);
            var model  =
                new PersonnelEdit
            {
                PersonnelId   = detail.PersonnelId,
                Rank          = detail.Rank,
                FirstName     = detail.FirstName,
                LastName      = detail.LastName,
                MiddleName    = detail.MiddleName,
                Sex           = detail.Sex,
                SSN           = detail.SSN,
                DOD           = detail.DOD,
                DOB           = detail.DOB,
                MaritalStatus = detail.MaritalStatus,
                CreatedBy     = detail.CreatedBy,
                CreatedUtc    = detail.CreatedUtc,
                ModifiedLast  = detail.ModifiedLast,
                ModifiedUtc   = detail.ModifiedUtc
            };

            return(View(model));
        }
コード例 #3
0
        public ActionResult Edit(int id, PersonnelEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.PersonnelId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var svc = CreatePersonnelService();

            if (svc.UpdatePersonnel(model))
            {
                TempData["SaveResult"] = "Record updated.";
                return(RedirectToAction("Details", new { id = model.PersonnelId }));
            }
            ModelState.AddModelError("", "Unable to update record.");
            return(View());
        }