Ejemplo n.º 1
0
        public ActionResult Edit()
        {
            string     userId = this.User.Identity.GetUserId();
            EditUserVm vm     = this.service.GetEditVm(userId);

            return(this.View(vm));
        }
        public ActionResult Edit()
        {
            var errorModel = this.TempData["errorModel"] as EditUserVm;

            if (errorModel != null)
            {
                this.TempData["errorModel"] = null;
                return(this.View(errorModel));
            }

            var userId = this.User.Identity.GetUserId();

            EditUserVm vm = this.myUserManager.GetEditModelByAppId(userId);

            if (vm.Errors.Any())
            {
                if (vm.Errors.ContainsKey("error"))
                {
                    //error
                    return(this.View());
                }
            }

            vm.LanguageCode = this.CurrentLanguageCode;

            return(this.View(vm));
        }
        public EditUserVm GetEditVm(string userName)
        {
            ApplicationUser user = this.Context.Users.FirstOrDefault(ap => ap.UserName == userName);
            EditUserVm      vm   = Mapper.Map <ApplicationUser, EditUserVm>(user);

            return(vm);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(EditUserBm bind)
        {
            if (this.ModelState.IsValid)
            {
                HttpPostedFileBase file = this.Request.Files["salePicture"];

                if (file == null || !file.ContentType.Contains("image"))
                {
                    this.ModelState.AddModelError("profilePicture", "Invalid image");
                }
                else
                {
                    var    pathToFolder = this.Server.MapPath("~/ProfilePictures");
                    string fileName     = Path.GetFileName(file.FileName);
                    string path         = this.service.GetAdequatePathToSave(pathToFolder, fileName);
                    file.SaveAs(path);

                    var imageUrl = this.service.GetImageUrl(path);
                    bind.ProfilePictureUrl = imageUrl;

                    string currentUsername = this.User.Identity.Name;
                    this.service.EditUser(bind, currentUsername);

                    return(this.RedirectToAction("Profile"));
                }
            }

            string     username = this.User.Identity.Name;
            EditUserVm vm       = this.service.GetEditVm(username);

            return(this.View(vm));
        }
Ejemplo n.º 5
0
        public ActionResult Edit()
        {
            string     userName = this.User.Identity.Name;
            EditUserVm vm       = this.service.GetEditVm(userName);

            return(this.View(vm));
        }
Ejemplo n.º 6
0
        public EditUserVm GetEditModelByAppId(string appUserId)
        {
            User user = this.userService.GetUserByAppId(appUserId);

            if (user == null)
            {
                var model = new EditUserVm();
                model.Errors.Add("error", null);
                return(model);
            }

            var address = user.Addresses.FirstOrDefault(x => x.IsPrimary);

            var cityName    = string.Empty;
            var countryName = string.Empty;

            if (address != null)
            {
                cityName    = address.City.Name;
                countryName = address.City.Country.Name;
            }

            var vm = new EditUserVm()
            {
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                CityName    = cityName,
                CountryName = countryName
            };

            return(vm);
        }
        public EditUserVm GetEditUserVm(User user)
        {
            EditUserVm vm          = new EditUserVm();
            User       currentUser = this.Context.Users.Find(user.Id);

            vm.Email = currentUser.Email;
            vm.Phone = currentUser.Phone;

            return(vm);
        }
Ejemplo n.º 8
0
        public ActionResult Edit(EditUserBm bind)
        {
            if (this.ModelState.IsValid)
            {
                string currentName = this.User.Identity.Name;
                this.service.EditUser(bind, currentName);
                return(this.RedirectToAction("Profile"));
            }

            string     userName = this.User.Identity.Name;
            EditUserVm vm       = this.service.GetEditVm(userName);

            return(this.View(vm));
        }
Ejemplo n.º 9
0
        public ActionResult EditProfile()
        {
            string sessionId = this.Request.Cookies.Get("sessionId")?.Value;

            if (!AuthenticationManager.IsAuthenticated(sessionId))
            {
                return(this.RedirectToAction("Login", "Users"));
            }

            User       user = AuthenticationManager.GetAuthenticatedUser(sessionId);
            EditUserVm vm   = this.service.GetEditUserVm(user);

            return(this.View(vm));
        }
Ejemplo n.º 10
0
        public async Task <UserVm> EditUserAsync(EditUserVm editableUser, long userId)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                User editedUser = await context.Users
                                  .Include(user => user.Phones)
                                  .Include(user => user.Emails)
                                  .FirstOrDefaultAsync(user => user.Id == userId && user.Deleted == false)
                                  .ConfigureAwait(false);

                editedUser = UserConverter.GetUser(editedUser, editableUser);
                context.Update(editedUser);
                await context.SaveChangesAsync().ConfigureAwait(false);

                return(UserConverter.GetUserVm(editedUser));
            }
        }
Ejemplo n.º 11
0
        public async Task EditUser()
        {
            var        user       = fillTestDbHelper.Users.FirstOrDefault(opt => !opt.Deleted && opt.Confirmed.Value);
            EditUserVm userEdited = new EditUserVm
            {
                About      = "Edited about",
                Photo      = "Edited photo",
                NameFirst  = "Edited namefirst",
                NameSecond = "Edited namesecond"
            };
            var actualUser = await updateUsersService.EditUserAsync(userEdited, user.Id);

            Assert.True(actualUser.About == userEdited.About &&
                        actualUser.NameFirst == userEdited.NameFirst &&
                        actualUser.NameSecond == userEdited.NameSecond &&
                        actualUser.Photo == userEdited.Photo);
        }
        public ActionResult Edit(int id)
        {
            using (var dbModel = new BazaProjekatEntities4())
            {
                var user = dbModel.Korisniks.FirstOrDefault(x => x.KorisnikID == id);
                //Uraditi ako je korisnik Null , vratiti "nije nadjen korisnik"

                var vm = new EditUserVm {
                    Id = id
                };
                vm.Korisnickoime = user.Korisnickoime;
                vm.Admin         = user.DaLiJeAdmin;
                vm.Gost          = user.Gost;
                vm.PravoUnosa    = user.PravoUnosa;
                return(View(vm));
            }
        }
        public ActionResult Edit(EditUserVm model)
        {
            var db   = new BazaProjekatEntities4();
            var user = db.Korisniks.FirstOrDefault(x => x.KorisnikID == model.Id);

            // to do : Do a null check on user to be safe :)

            // Map the property values from view model to entity object
            user.Korisnickoime  = model.Korisnickoime;
            user.DaLiJeAdmin    = model.Admin;
            user.PotvrdiLozinku = user.Lozinka;
            user.Gost           = model.Gost;
            user.PravoUnosa     = model.PravoUnosa;

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Izlistaj"));
        }
Ejemplo n.º 14
0
        public static User GetUser(User editableUser, EditUserVm editUser)
        {
            if (editUser == null || editableUser == null)
            {
                return(editableUser);
            }

            editableUser.About           = editUser.About ?? editableUser.About;
            editableUser.Birthday        = editUser.Birthday ?? editableUser.Birthday;
            editableUser.City            = editUser.City ?? editableUser.City;
            editableUser.Country         = editUser.Country ?? editableUser.Country;
            editableUser.NameFirst       = editUser.NameFirst ?? editableUser.NameFirst;
            editableUser.NameSecond      = editUser.NameSecond ?? editableUser.NameSecond;
            editableUser.Security        = editUser.Security?.ToArray() ?? editableUser.Security;
            editableUser.Privacy         = editUser.Privacy?.ToInt32() ?? editUser.Visible?.FirstOrDefault()?.ToInt32() ?? editableUser.Privacy;
            editableUser.ContactsPrivacy = editUser.ContactsPrivacy?.ToInt32();
            editableUser.Photo           = editUser.Photo ?? editableUser.Photo;
            editableUser.Language        = editUser.Language ?? editableUser.Language;
            editableUser.SyncContacts    = editUser.SyncContacts ?? editableUser.SyncContacts;
            return(editableUser);
        }
Ejemplo n.º 15
0
        public ActionResult EditProfile(EditUserBm bind)
        {
            string sessionId = this.Request.Cookies.Get("sessionId")?.Value;

            if (!AuthenticationManager.IsAuthenticated(sessionId))
            {
                return(this.RedirectToAction("Login", "Users"));
            }

            User user = AuthenticationManager.GetAuthenticatedUser(sessionId);

            if (this.ModelState.IsValid && bind.CurrentPassword == user.Password)
            {
                this.service.EditUser(bind, user);
                return(this.RedirectToAction("Profile"));
            }

            EditUserVm vm = this.service.GetEditUserVm(user);

            return(this.View(vm));
        }
        public async Task <IActionResult> EditUser(string id)
        {
            var user = await userManager.FindByIdAsync(id);

            if (user == null)
            {
                ViewBag.Message = $"User with id = {id} not found.";
                return(View("NotFound"));
            }

            var roles = await userManager.GetRolesAsync(user);

            var model = new EditUserVm
            {
                Id       = user.Id,
                UserName = user.UserName,
                FullName = user.FullName,
                Roles    = roles
            };

            return(View(model));
        }
        public async Task <IActionResult> EditUser(EditUserVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                ViewBag.Message = $"User with id = {model.Id} not found.";
                return(View("NotFound"));
            }

            user.FullName = model.FullName;
            user.UserName = model.UserName;
            user.Email    = model.UserName;

            var result = await userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                TempData["Success"] = $"User '{user.FullName}' was updated successfully.";
                return(RedirectToAction("ListUsers"));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(model));
            }
        }