Exemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "UserID,Generation,FamilyName,GivenName,LogonId,Age,EmailAddress,OccupationCode")] NormalUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user  = model.GetNormalUserEntity();
                var email = model.GetEmailAddressEntity();

                var db = R.Context;
                db.Entry(user).State = EntityState.Modified;

                var emailAddressRepository = R.EmailAddressRepository;
                var persistedEmail         = emailAddressRepository.Find(user.logon_id, user.generation);
                if (persistedEmail != null)
                {
                    persistedEmail.address = email.address;
                }
                else
                {
                    db.email_address.Add(email);
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "UserID,Generation,FamilyName,GivenName,LogonID,Age,EmailAddress,OccupationCode")] NormalUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var db = R.Context;
                db.normal_user.Add(model.GetNormalUserEntity());
                db.email_address.Add(model.GetEmailAddressEntity());
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }