示例#1
0
        public ActionResult Index(IndexViewModel model)
        {
            RVVRBDBEntities2 rv = new RVVRBDBEntities2();

            ApplicationDbContext db = new ApplicationDbContext();
            int userID = Convert.ToInt32(User.Identity.GetUserId());

            var user = rv.AspNetUsers.Single(i => i.Id == userID);
            
            if (model.ProfileImage != null)
            {
                MiddleTier mt = new MiddleTier();

                HttpPostedFileBase photo = model.ProfileImage;
                string extension = Path.GetExtension(photo.FileName);
                string imagePath = "/profile/" + user.UserName + "/";
                string filename = user.UserName + "-" + DateTime.Now.Ticks;
                string fullfilepath = imagePath + filename + extension;
                string serverpath = Server.MapPath("~")+"\\profile\\"+user.UserName+"\\";
                string fullserverfilepath = serverpath + filename + extension;

                Session["ProfileImage"] = fullfilepath;

                mt.UpdateDbImage(Convert.ToInt32(User.Identity.GetUserId()), fullfilepath);

                bool pathExists = Directory.Exists(serverpath);
                if (!pathExists)
                    Directory.CreateDirectory(serverpath);

                photo.SaveAs(fullserverfilepath);
            }

            return View(model);
        }
示例#2
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(User.Identity.GetUserId<int>()),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId<int>()),
                Logins = await UserManager.GetLoginsAsync(User.Identity.GetUserId<int>()),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }