Exemple #1
0
        public ActionResult EditProfile(User model, HttpPostedFileBase uploadPhoto, HttpPostedFileBase uploadAvatar)
        {
            if (WebSecurity.IsAuthenticated)
            {
                User currentUser = Storage.Users.Where(u => u.Id == WebSecurity.CurrentUserId).FirstOrDefault();

                if (uploadAvatar != null && uploadAvatar.ContentLength > 0)
                {
                    currentUser.ForumAvatar     = ReadFully(uploadAvatar.InputStream);
                    currentUser.ForumAvatarType = uploadAvatar.ContentType;
                }

                if (uploadPhoto != null && uploadPhoto.ContentLength > 0)
                {
                    currentUser.ProfilePhoto     = ReadFully(uploadPhoto.InputStream);
                    currentUser.ProfilePhotoType = uploadPhoto.ContentType;
                }

                currentUser.FirstName = model.FirstName;
                currentUser.LastName  = model.LastName;
                currentUser.Location  = model.Location;

                Storage.SaveChanges();
                if (currentUser != null)
                {
                    return(RedirectToAction("EditProfile"));
                }
            }

            return(RedirectToAction("Index"));
        }