Пример #1
0
        public ActionResult EditProfile(UpdateModel model)
        {
            if (Session["user"] != null) {
                Trace.WriteLine("logged");
                if(ModelState.IsValid){
                    Trace.WriteLine("valid");
                    Boolean success = false;
                    Member user = (Member)Session["user"];

                    success = MemberManager.UpdateUser(user, model, db);
                    if(success){
                        var newUser = from u in db.members
                                      where u.ID == user.ID
                                      select u;
                        if (newUser.Count() == 1)
                        {
                            Session["user"] = newUser.First();
                        }
                        else
                        {
                            Session["user"] = null;
                        }
                        return RedirectToAction("MemberProfile", "Account");
                    }
                }
                return View();
            }
            return RedirectToAction("LogOn", "Account");
        }
Пример #2
0
        public static Boolean UpdateUser(Member user, UpdateModel model, OnGameContext _db)
        {
            Boolean success = false;

            Member userDB =_db.members.Find(user.ID);
            if(userDB != null){
                Trace.WriteLine("not null");
                var membersModel = from m in _db.members
                                   where m.email == model.Email
                                   select m;
                if(membersModel.Count() == 0){
                    Trace.WriteLine("doesn't exist");
                    try
                    {
                        userDB.email = model.Email;
                        userDB.description = model.Description;
                        userDB.password = model.Password;
                        _db.Entry(userDB).State = EntityState.Modified;
                        _db.SaveChanges();
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                    }
                }
            }
            return success;
        }