// GET: UserController/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(View(""));
            }

            var Model = _User.Entity.GetById(id);

            if (Model == null)
            {
                return(NotFound());
            }

            UserviewModel user = new UserviewModel
            {
                FirstName       = Model.UserName,
                LastName        = Model.LastName,
                Address         = Model.Address,
                phone           = Model.PhoneNumber,
                Email           = Model.Email,
                ConfirmPassword = Model.PasswordHash,
                Password        = Model.PasswordHash,

                ImageUrl = Model.Image,
                Id       = Model.Id
            };


            return(View(user));
        }
        public async Task <ActionResult> Create(UserviewModel Model)
        {
            if (ModelState.IsValid)
            {
                if (Model.File != null)
                {
                    string uploads  = Path.Combine(_hosting.WebRootPath, @"img\ImageUsers");
                    string fullPath = Path.Combine(uploads, Model.FirstName + Model.LastName + Model.File.FileName);
                    Model.File.CopyTo(new FileStream(fullPath, FileMode.Create));
                }


                var user = new ApplicationUser
                {
                    UserName     = Model.FirstName,
                    LastName     = Model.LastName,
                    Address      = Model.Address,
                    PhoneNumber  = Model.phone,
                    Email        = Model.Email,
                    PasswordHash = Model.Password,
                    Image        = Model.FirstName + Model.LastName + Model.File.FileName
                };



                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)


                {
                    return(RedirectToAction("Index"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }


            return(View(Model));
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            List <UserviewModel> users = new List <UserviewModel>();

            foreach (var item in manager.Users.ToList())
            {
                UserviewModel userviewModel = new UserviewModel();
                userviewModel.ID             = item.Id;
                userviewModel.FullName       = item.FName + item.LName;
                userviewModel.Phone          = item.PhoneNumber;
                userviewModel.ProfilePicture = item.ProfilePicture;
                userviewModel.Gender         = item.Gender;
                userviewModel.Email          = item.Email;
                var roles = await manager.GetRolesAsync(item);

                userviewModel.UserRole = roles[0];
                users.Add(userviewModel);
            }
            ViewBag.roles = roleManager.Roles.ToList();
            return(View(users));
        }
        public ActionResult Edit(UserviewModel Model)
        {
            if (ModelState.IsValid)
            {
                string ImageValue = Model.ImageUrl;
                if (Model.File != null)
                {
                    string uploads  = Path.Combine(_hosting.WebRootPath, @"img\ImageUsers");
                    string fullPath = Path.Combine(uploads, Model.FirstName + Model.LastName + Model.File.FileName);
                    ImageValue = Model.FirstName + Model.LastName + Model.File.FileName;
                    Model.File.CopyTo(new FileStream(fullPath, FileMode.Create));
                }



                ApplicationUser Userr = _User.Entity.GetById(Model.Id);

                Userr.UserName             = Model.FirstName;
                Userr.LastName             = Model.LastName;
                Userr.Address              = Model.Address;
                Userr.PhoneNumber          = Model.phone;
                Userr.Email                = Model.Email;
                Userr.PasswordHash         = Model.Password;
                Userr.Image                = ImageValue;
                Userr.LockoutEnabled       = true;
                Userr.AccessFailedCount    = 0;
                Userr.PhoneNumberConfirmed = false;
                Userr.TwoFactorEnabled     = false;
                Userr.EmailConfirmed       = false;
                Userr.NormalizedEmail      = Model.Email;

                _User.Entity.Update(Userr);
                _User.Save();

                return(RedirectToAction("Index"));
            }

            return(View(Model));
        }