public ActionResult Create(RegistrantInfo registrantinfo, int userId)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UserProfile user = _context.UserProfiles.Find(userId);
                    registrantinfo.ExamNumber = user.UserName + GetRandomString();
                    registrantinfo.UserProfile = user;
                    _context.RegistrantInfos.Add(registrantinfo);
                    _context.SaveChanges();
                    return RedirectToAction("ExamNumber", new {userId});
                }
            }
            catch (DataException ex)
            {
                string msg = ex + "\r\n"
                             + "Unable to save changes. Try again, and if the problem persists see your system administrator.";

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", msg);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }

            ViewBag.RegistrantInfoId = new SelectList(_context.UserProfiles, "UserId", "UserName", registrantinfo.RegistrantInfoId);
            return View(registrantinfo);
        }
Exemplo n.º 2
0
 public void Update(RegistrantInfo newValue)
 {
     Name       = newValue.Name;
     Sex        = newValue.Sex;
     BirthPlace = newValue.BirthPlace;
     BirthDate  = newValue.BirthDate;
     Address    = newValue.Address;
     ExamNumber = newValue.ExamNumber;
 }
Exemplo n.º 3
0
 public void Update(RegistrantInfo newValue)
 {
     Name = newValue.Name;
     Sex = newValue.Sex;
     BirthPlace = newValue.BirthPlace;
     BirthDate = newValue.BirthDate;
     Address = newValue.Address;
     ExamNumber = newValue.ExamNumber;
 }
        public ActionResult Edit(RegistrantInfo registrantinfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    RegistrantInfo registrantInfoOld = _context.RegistrantInfos.Find(registrantinfo.RegistrantInfoId);
                    registrantInfoOld.Update(registrantinfo);

                    //_context.Entry(registrantinfo).State = EntityState.Modified;
                    _context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (DataException ex)
            {
                string msg = ex + "\r\n"
                             + "Unable to save changes. Try again, and if the problem persists see your system administrator.";

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", msg);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }
            ViewBag.RegistrantInfoId = new SelectList(_context.UserProfiles, "UserId", "UserName", registrantinfo.RegistrantInfoId);
            return View(registrantinfo);
        }