コード例 #1
0
        public ActionResult Edit(int?id)
        {
            ConsultantService consultantService = new ConsultantService();
            ConsultantEditVM  model             = new ConsultantEditVM();
            Consultant        consultant;

            if (!id.HasValue)
            {
                consultant = new Consultant();
            }
            else
            {
                consultant = consultantService.GetById(id.Value);
                if (consultant == null)
                {
                    return(RedirectToAction("List"));
                }
            }

            model.Id        = consultant.Id;
            model.Username  = consultant.Username;
            model.Password  = consultant.Password;
            model.FirstName = consultant.FirstName;
            model.LastName  = consultant.LastName;
            model.Email     = consultant.Email;
            model.Rank      = consultant.Rank;
            return(View(model));
        }
コード例 #2
0
        public ActionResult Edit(int? id)
        {
            ConsultantService consultantService = new ConsultantService();
            ConsultantEditVM model = new ConsultantEditVM();
            Consultant consultant;

            if (!id.HasValue)
            {
                consultant = new Consultant();
            }
            else
            {
                consultant = consultantService.GetById(id.Value);
                if (consultant == null)
                {
                    return RedirectToAction("List");
                }
            }

            model.Id = consultant.Id;
            model.Username = consultant.Username;
            model.Password = consultant.Password;
            model.FirstName = consultant.FirstName;
            model.LastName = consultant.LastName;
            model.Email = consultant.Email;
            model.Rank = consultant.Rank;
            return View(model);
        }
コード例 #3
0
        public ActionResult Edit()
        {
            ConsultantService consultantService = new ConsultantService();
            ConsultantEditVM  model             = new ConsultantEditVM();

            TryUpdateModel(model);

            Consultant consultant;

            if (model.Id == 0)
            {
                consultant = new Consultant();
            }
            else
            {
                consultant = consultantService.GetById(model.Id);
                if (consultant == null)
                {
                    return(RedirectToAction("List"));
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            consultant.Id        = model.Id;
            consultant.Username  = model.Username;
            consultant.Password  = model.Password;
            consultant.FirstName = model.FirstName;
            consultant.LastName  = model.LastName;
            consultant.Email     = model.Email;
            consultant.Rank      = model.Rank;

            consultantService.Save(consultant);
            return(RedirectToAction("List"));
        }
コード例 #4
0
        public ActionResult Edit()
        {
            ConsultantService consultantService = new ConsultantService();
            ConsultantEditVM model = new ConsultantEditVM();
            TryUpdateModel(model);

            Consultant consultant;
            if (model.Id == 0)
            {
                consultant = new Consultant();
            }
            else
            {
                consultant = consultantService.GetById(model.Id);
                if (consultant == null)
                {
                    return RedirectToAction("List");
                }
            }

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            consultant.Id = model.Id;
            consultant.Username = model.Username;
            consultant.Password = model.Password;
            consultant.FirstName = model.FirstName;
            consultant.LastName = model.LastName;
            consultant.Email = model.Email;
            consultant.Rank = model.Rank;

            consultantService.Save(consultant);
            return RedirectToAction("List");
        }