예제 #1
0
        /// <summary>
        ///     Gets current user DTO </summary>
        /// <remarks>
        /// The method is used to get/set data. So here I implemented to check by a company
        /// </remarks>
        protected UserDto GetUserDto()
        {
            Guid userId  = IdentityExtensions1.GetUserId(this.User.Identity);
            var  userDto = Mapper.Map <UserDto>(this.UserManager.FindById(userId));

            if (userDto.CompanyId == Guid.Empty)
            {
                throw new Exception("Please create a company");
            }
            return(userDto);
        }
예제 #2
0
        public async Task <WebApiResult> AcceptCompany()
        {
            try {
#if DEBUG
                await Task.Delay(500);
#endif
                return(await Task.Factory.StartNew(() => {
                    Guid userId = IdentityExtensions1.GetUserId(this.User.Identity);
                    _service.AcceptCompany(userId);
                    return WebApiResult.Succeed();
                }));
            } catch (Exception e) {
                Logger.e("AcceptCompany", e);
                return(WebApiResult.Failed(e.Message));
            }
        }
예제 #3
0
        public async Task <WebApiResult> FindUser(UserDto userDto)
        {
            try {
#if DEBUG
                await Task.Delay(500);
#endif
                return(await Task.Factory.StartNew(() => {
                    Guid userId = IdentityExtensions1.GetUserId(this.User.Identity);
                    userDto = _service.FindUser(userId, userDto);
                    return WebApiResult.Succeed(new { User = userDto });
                }));
            } catch (Exception e) {
                Logger.e("FindUser", e);
                return(WebApiResult.Failed(e.Message));
            }
        }
예제 #4
0
        public async Task <WebApiResult> InvertFavoriteFilter()
        {
            try {
#if DEBUG
                await Task.Delay(100);
#endif
                return(await Task.Factory.StartNew(() => {
                    Guid userId = IdentityExtensions1.GetUserId(this.User.Identity);
                    TaskManagerUser user = base.UserManager.FindById(userId);
                    user.FavoriteFilter = !user.FavoriteFilter;
                    base.UserManager.Update(user);
                    return WebApiResult.Succeed(new { FavoriteFilter = user.FavoriteFilter });
                }));
            } catch (Exception e) {
                Logger.e("SaveSorting", e);
                return(WebApiResult.Failed(e.Message));
            }
        }
예제 #5
0
        public async Task <WebApiResult> GetData()
        {
            try {
#if DEBUG
                await Task.Delay(500);
#endif
                return(await Task.Factory.StartNew(() => {
                    Guid userId = IdentityExtensions1.GetUserId(this.User.Identity);
                    CompanyDto company, invitationCompany;
                    List <UserDto> users, invitedUsers;
                    _service.GetData(userId, out company, out invitationCompany, out users, out invitedUsers);
                    return WebApiResult.Succeed(new {
                        Company = company,
                        InvitationCompany = invitationCompany,
                        Users = users,
                        InvitedUsers = invitedUsers
                    });
                }));
            } catch (Exception e) {
                Logger.e("GetData", e);
                return(WebApiResult.Failed(e.Message));
            }
        }
예제 #6
0
        public async Task <WebApiResult> ChangePassword(ChangePasswordModel model)
        {
#if DEBUG
            await Task.Delay(500);
#endif
            return(await Task.Factory.StartNew(() => {
                if (!ModelState.IsValid)
                {
                    return WebApiResult.Failed("Invalid model state");
                }
                Guid userId = IdentityExtensions1.GetUserId(this.User.Identity);
                TaskManagerUser user = base.UserManager.FindById(userId);
                var result = UserManager.ChangePassword(user.Id, model.OldPassword, model.NewPassword);
                if (result.Succeeded)
                {
                    SignInManager.SignIn(user, true, true);
                    return WebApiResult.Succeed();
                }
                else
                {
                    return WebApiResult.Failed(String.Join(Environment.NewLine, result.Errors));
                }
            }));
        }