コード例 #1
0
        public ActionResult UpdateAccount(UpdateAccount ua)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var u = _db.Logins.SingleOrDefault(m => m.Username.Equals(User.Identity.Name));
                    if (u != null)
                    {
                        var authId = u.UniversityId;

                        var si = _db.StudentInformations.SingleOrDefault(m => m.StudentId.Equals(authId));
                        if (si != null)
                        {
                            si.Email = ua.Email;
                            si.PresentAddress = ua.PresentAddress;
                            si.Phone = ua.PhoneNumber;
                            _db.Entry(si).State = EntityState.Modified;
                        }
                    }
                    _db.SaveChanges();
                    ViewBag.successNotificationId = 1;
                }
                catch (Exception e)
                {

                    Response.Write(e.Message);
                }
            }
            return View();
        }
コード例 #2
0
        public ActionResult UpdateAccount()
        {
            var ua = new UpdateAccount();
            var u = _db.Logins.SingleOrDefault(m => m.Username.Equals(User.Identity.Name));
            if (u != null)
            {
                string authId = u.UniversityId;
                var v = _db.StudentInformations.FirstOrDefault(x => x.StudentId.Equals(authId));
                if (v != null)
                    ua.Email = v.Email;
                var w = _db.StudentInformations.FirstOrDefault(x => x.StudentId.Equals(authId));
                if (w != null)
                    ua.PresentAddress = w.PresentAddress;
                var c = _db.StudentInformations.FirstOrDefault(x => x.StudentId.Equals(authId));
                if (c != null)
                    ua.PhoneNumber = c.Phone;
            }

            return View(ua);
        }