コード例 #1
0
        public async Task <IActionResult> ChangePassword([Bind("Username,oldPassword,confirmedPassword,Password")] UserProfileEdit userProfile, CancellationToken cancellationToken)
        {
            var user = await _userProfileRepository.FindByUsernameAsync(userProfile.Username, cancellationToken);

            if (user == null)
            {
                ModelState.AddModelError(nameof(UserProfileEdit.Username), "User not found");
                return(View(userProfile));
            }
            var oldPasswordHashed = userProfile.oldPassword.Sha256();

            if (oldPasswordHashed != user.Password)
            {
                ModelState.AddModelError(nameof(UserProfileEdit.oldPassword), "old password does not match");
            }
            if (userProfile.Password != userProfile.confirmedPassword)
            {
                ModelState.AddModelError(nameof(UserProfileEdit.confirmedPassword), "confirmed password does not match password");
            }
            if (ModelState.IsValid)
            {
                var dmUser = _mapper.Map <UserProfile>(userProfile);
                dmUser.Id         = user.Id;
                dmUser.SubjectId  = user.SubjectId;
                dmUser.UpdateDate = DateTime.UtcNow;
                var res = await _userProfileRepository.UpsertAsync(dmUser, cancellationToken);

                return(new OkObjectResult(res));
            }

            return(View(userProfile));
        }
コード例 #2
0
        public ActionResult Index(string id)
        {
            var query = new UserProfileEdit {
                UserName = id
            };

            var response = ProcessQuery <TypedMessageResponse <string> >(query);

            return(Content(response.Data));
        }
コード例 #3
0
        public bool UpdateUserProfile(UserProfileEdit model)
        {
            UserProfile profileToEdit = _db.UserProfiles.Single(up => up.ProfileId == model.ProfileId);

            profileToEdit.ProfileId = model.ProfileId;
            profileToEdit.UserName  = model.UserName;
            profileToEdit.FirstName = model.FirstName;
            profileToEdit.LastName  = model.LastName;
            profileToEdit.Age       = model.Age;

            return(_db.SaveChanges() > 0);
        }
コード例 #4
0
        public IHttpActionResult UpdateUserProfile(UserProfileEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userProfileService = CreateUserProfileService();

            if (!userProfileService.UpdateUserProfile(model))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
コード例 #5
0
        //GET: Edit
        public ActionResult Edit(int id)
        {
            var service = CreateUserProfileService();
            var detail  = service.GetProfileById(id);
            var model   =
                new UserProfileEdit
            {
                ProfileId = detail.ProfileId,
                UserName  = detail.UserName,
                LastName  = detail.LastName,
                FirstName = detail.FirstName
            };

            return(View(model));
        }
コード例 #6
0
        public TypedMessageResponse <string> Handle(UserProfileEdit message)
        {
            var response = new TypedMessageResponse <string>();

            if (CorePrincipal.CurrentPrincipal.Identity.Name.Equals(message.UserName,
                                                                    StringComparison.OrdinalIgnoreCase))
            {
                response.Data = "Welcome " + CorePrincipal.CurrentPrincipal.Identity.Name;
            }
            else
            {
                response.Data = "You are not authorized for this action";
            }

            return(response);
        }
コード例 #7
0
        public bool UpdateUserProfile(UserProfileEdit model)
        {
            UserProfile profileToEdit = _context.UserProfiles.Single(up => up.UserProfileId == model.UserProfileId);

            profileToEdit.UserName    = model.UserName;
            profileToEdit.BooksToRead = _context.Books.Where(up => model.BookIds.Contains(up.BookId)).ToList();

            List <Book> booksToRemove = profileToEdit.BooksToRead.Where(up => !model.BookIds.Contains(up.BookId)).ToList();

            foreach (Book book in booksToRemove)
            {
                profileToEdit.BooksToRead.Remove(book);
            }

            return(_context.SaveChanges() > 0);
        }
コード例 #8
0
        public ActionResult Edit(int id)
        {
            var service = CreateUserProfileService();
            var detail  = service.GetUserProfileById(id);
            var model   =
                new UserProfileEdit
            {
                UserProfileId = detail.UserProfileId,
                FirstName     = detail.FirstName,
                LastName      = detail.LastName,
                Address       = detail.Address,
                Email         = detail.Email
            };

            return(View(model));
        }
コード例 #9
0
        public ActionResult EditProfile()
        {
            string username = User.Identity.Name;

            // Fetch the userprofile
            ApplicationUser user = db.Users.FirstOrDefault(u => u.UserName.Equals(username));

            // Construct the viewmodel
            UserProfileEdit model = new UserProfileEdit();

            model.Password = user.PasswordHash;
            model.Phone    = user.Phone;
            model.Email    = user.Email;

            return(View(user));
        }
コード例 #10
0
        public bool UpdateUserProfile(UserProfileEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .UserProfiles
                    .Single(e => e.UserProfileId == model.UserProfileId && e.OwnerId == _userId);

                entity.UserName = model.UserName;
                entity.Email    = model.Email;
                entity.ZipCode  = model.ZipCode;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #11
0
        public async Task <IActionResult> Create(UserProfileEdit userProfile, CancellationToken cancellationToken = default)
        {
            if (userProfile == null)
            {
                return(BadRequest());
            }
            if (ModelState.IsValid)
            {
                var uProfile = _mapper.Map <UserProfile>(userProfile);
                var res      = await _userProfileRepository.UpsertAsync(uProfile, cancellationToken);

                //var userProfileDTO = _mapper.Map<UserProfileDTO>(userProfile);
                return(new CreatedResult("/userprofile", new { Id = res.Id }));
            }
            else
            {
                return(View(userProfile));
            }
        }
コード例 #12
0
        public ActionResult ChangeData()
        {
            var userId = User.Identity.GetUserId();

            // Fetch the userprofile
            //UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.Equals(username));
            var user = UserManager.FindById(User.Identity.GetUserId());
            // Construct the viewmodel
            UserProfileEdit model = new UserProfileEdit();

            model.FirstName   = user.FirstName;
            model.SecondName  = user.SecondName;
            model.Email       = user.Email;
            model.BirthDate   = Convert.ToDateTime(user.BirthDate);
            model.PhoneNumber = user.PhoneNumber;
            //model.Sex = user.Sex;


            return(View(model));
        }
コード例 #13
0
        //GET : UserProfile/Edit
        public ActionResult Edit(int id)
        {
            var service = CreateUserProfileService();
            var detail  = service.GetUserProfileById(id);
            var model   =
                new UserProfileEdit
            {
                UserProfileId   = detail.UserProfileId,
                Title           = detail.Title,
                Description     = detail.Description,
                CaloryTarget    = detail.CaloryTarget,
                CarbTarget      = detail.CarbTarget,
                FiberTarget     = detail.FiberTarget,
                FatTarget       = detail.FatTarget,
                ProteinTarget   = detail.ProteinTarget,
                SodiumTarget    = detail.SodiumTarget,
                PotassiumTarget = detail.PotassiumTarget,
            };

            return(View(model));
        }
コード例 #14
0
        public async Task <IActionResult> Edit([Bind("Id,SubjectId,Username,Claims,isActive,isAdmin,isStoreOwner,isCustomer")] UserProfileEdit userProfile, CancellationToken cancellationToken = default)//oldPassword,confirmedPassword,Password,
        {
            //var user = await _userProfileRepository.GetByIdAsync(userProfile.Id, cancellationToken);
            //var oldPasswordHashed = userProfile.oldPassword.Sha256();
            //if (oldPasswordHashed != user.Password)
            //{
            //    ModelState.AddModelError(nameof(UserProfileEdit.oldPassword), "old password does not match");
            //}
            //if(userProfile.Password!=userProfile.confirmedPassword)
            //{
            //    ModelState.AddModelError(nameof(UserProfileEdit.confirmedPassword), "confirmed password does not match password");
            //}
            if (ModelState.IsValid)
            {
                var dmUser = _mapper.Map <UserProfile>(userProfile);
                var res    = await _userProfileRepository.UpsertAsync(dmUser, cancellationToken);

                return(new OkObjectResult(res));
            }

            return(View(userProfile));
        }
コード例 #15
0
ファイル: UserProfileService.cs プロジェクト: nrwehner/LogIt
        public bool UpdateUserProfile(UserProfileEdit model)
        {
            var entity =
                _db
                .UserProfiles
                .Single(e => e.UserProfileId == model.UserProfileId);

            entity.Title           = model.Title;
            entity.Description     = model.Description;
            entity.CaloryTarget    = model.CaloryTarget;
            entity.CarbTarget      = model.CarbTarget;
            entity.FiberTarget     = model.FiberTarget;
            entity.FatTarget       = model.FatTarget;
            entity.ProteinTarget   = model.ProteinTarget;
            entity.SodiumTarget    = model.SodiumTarget;
            entity.PotassiumTarget = model.PotassiumTarget;
            entity.IsStarred       = model.IsStarred;
            entity.ModifiedBy      = _db.Users.Find(_userId).FirstName + " " + _db.Users.Find(_userId).LastName;
            entity.ModifiedUtc     = DateTimeOffset.UtcNow;

            return(_db.SaveChanges() == 1);
        }
コード例 #16
0
        public ActionResult Edit(int id, UserProfileEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ProfileId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateUserProfileService();

            if (service.UpdateUserProfile(model))
            {
                TempData["SaveResult"] = "This profile has been updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "This profile could not be updated.");
            return(View(model));
        }
コード例 #17
0
        public ActionResult ChangeData(UserProfileEdit userprofile)
        {
            if (ModelState.IsValid)
            {
                string username = User.Identity.Name;
                // Get the userprofile
                //UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.Equals(username));
                var user = UserManager.FindById(User.Identity.GetUserId());

                //// Update fields
                user.FirstName   = userprofile.FirstName;
                user.SecondName  = userprofile.SecondName;
                user.Email       = userprofile.Email;
                user.BirthDate   = userprofile.BirthDate;
                user.PhoneNumber = userprofile.PhoneNumber;
                //db.Entry(user).State = EntityState.Modified;

                //db.SaveChanges();
                UserManager.Update(user);
                return(RedirectToAction("Index", "Home")); // or whatever
            }

            return(View(userprofile));
        }