Beispiel #1
0
        public async Task <UserDetailsResponseModel> UpdateUserDetails(UserDetailsResponseModel model, string token)
        {
            try
            {
                var responseClient = _httpClientFactory.CreateClient("ZumbaAPI");

                responseClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var result = await responseClient.PostAsJsonAsync <UserDetailsResponseModel>("api/User", model);

                if (result.StatusCode != HttpStatusCode.OK)
                {
                    var faliedResponse = await result.Content.ReadAsJsonAsync <RestException>();

                    return(new UserDetailsResponseModel()
                    {
                        Message = faliedResponse.Errors.ToString(),
                        Code = Convert.ToInt32(result.StatusCode)
                    });
                }

                model.Code = Convert.ToInt32(result.StatusCode);

                return(model);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserService||UpdateUserDetails ErrorMessage: {ex.Message}");
                throw;
            }
        }
        protected override async Task OnInitializedAsync()
        {
            var(res, details) = await UserServices.GetUserDetails();

            if (res != ErrorCodes.Success)
            {
                if (res != ErrorCodes.NotLoggedIn)
                {
                    await Modal.ErrorAsync(new ConfirmOptions()
                    {
                        Title = "You must log in first"
                    });

                    NavManager.NavigateTo("/User/Login");
                }
                else
                {
                    await Modal.ErrorAsync(new ConfirmOptions()
                    {
                        Title   = "Cannot get user information",
                        Content = ErrorCodes.MessageMap[res]
                    });
                }
            }
            else
            {
                _userDetails    = details;
                _model.Email    = details.Email;
                _model.Phone    = details.Phone;
                _model.NickName = details.NickName;
                StateHasChanged();
            }
        }
Beispiel #3
0
        public IHttpActionResult GetUserDetails(string userName)
        {
            var currentUserName = this.User.Identity.Name;
            var user            = this.users
                                  .GetUserByUserName(userName)
                                  .FirstOrDefault();

            if (user == null)
            {
                return(this.BadRequest(GlobalConstants.WrongUserNameErrorMessage));
            }

            var userStatistics = this.userStatistics
                                 .GetAllStatisticsForUser(user)
                                 .ToList();

            var   uniqueUserStatistics = new Dictionary <int, UserQuizStatistic>();
            ulong answeredCorrectly    = 0;
            ulong totalAnswersGiven    = 0;

            foreach (var statistic in userStatistics)
            {
                if (!uniqueUserStatistics.ContainsKey(statistic.QuizId))
                {
                    uniqueUserStatistics.Add(statistic.QuizId, statistic);
                }

                answeredCorrectly += (ulong)statistic.CorrectAnswers;
                totalAnswersGiven += (ulong)statistic.TotalQuizAnswers;
            }

            var details = new UserDetailsResponseModel()
            {
                FirstName      = user.FirstName,
                LastName       = user.LastName,
                UserName       = user.UserName,
                CorrectAnswers = answeredCorrectly,
                TotalAnswers   = totalAnswersGiven
            };

            // checking his own profile
            // shows recently played games
            if (currentUserName == userName)
            {
                var personalDetails = new PersonalUserDetailsResponseModel(details);

                personalDetails.RecentlyPlayed = uniqueUserStatistics
                                                 .Take(QuizConstants.TakeUserPersonalGamesPlayed)
                                                 .Select(s => Mapper.Map <UserQuizStatisticResponseModel>(s.Value));

                return(this.Ok(personalDetails));
            }


            return(this.Ok(details));
        }
        public async Task <UserDetailsResponseModel> GetUserByIdAsync(int id)
        {
            var userdetail = await _userRepository.GetByIdAsync(id);

            if (userdetail == null)
            {
                throw new Exception("User not found");
            }

            var expenditures = new List <ExpenditureResponseModel>();

            var incomes = new List <IncomesResponseModel>();

            foreach (var income in userdetail.Income)
            {
                incomes.Add(new IncomesResponseModel
                {
                    Id     = income.Id,
                    UserId = income.UserId,

                    Amount      = income.Amount,
                    Description = income.Description,
                    IncomeDate  = income.IncomeDate,
                    Remarks     = income.Remarks
                });
            }

            foreach (var expenditure in userdetail.Expenditure)
            {
                expenditures.Add(new ExpenditureResponseModel
                {
                    Id          = expenditure.Id,
                    UserId      = expenditure.UserId,
                    Amount      = expenditure.Amount,
                    Description = expenditure.Description,
                    ExpDate     = expenditure.ExpDate,
                    Remarks     = expenditure.Remarks
                });
            }

            var endUserDetails = new UserDetailsResponseModel
            {
                Id       = userdetail.Id,
                FullName = userdetail.Fullname,
                Email    = userdetail.Email,
                JoinedOn = userdetail.JoinedOn,
            };

            return(endUserDetails);
        }
        // get all the details for one users into one model with a list of
        // the expenditure/income models inside to display in view
        public async Task <UserDetailsResponseModel> GetUserAsync(int userId)
        {
            var user = await _userRepository.GetByIdAsync(userId);

            if (user == null)
            {
                throw new NotFoundException("User Not Found");
            }
            var expenditures = new List <ExpenditureResponseModel>();
            var incomes      = new List <IncomeResponseModel>();

            // map database expenditure values to model
            foreach (var expenditure in user.Expenditures)
            {
                expenditures.Add(new ExpenditureResponseModel
                {
                    Id          = expenditure.Id,
                    UserId      = expenditure.UserId,
                    Amount      = expenditure.Amount,
                    Description = expenditure.Description,
                    ExpDate     = expenditure.ExpDate,
                    Remarks     = expenditure.Remarks
                });
            }
            foreach (var income in user.Incomes)
            {
                incomes.Add(new IncomeResponseModel
                {
                    Id          = income.Id,
                    UserId      = income.UserId,
                    Amount      = income.Amount,
                    Description = income.Description,
                    IncomeDate  = income.IncomeDate,
                    Remarks     = income.Remarks
                });
            }
            var response = new UserDetailsResponseModel
            {
                Id           = user.Id,
                Email        = user.Email,
                Password     = user.Password,
                Fullname     = user.Fullname,
                JoinedOn     = user.JoinedOn,
                Expenditures = expenditures,
                Incomes      = incomes
            };

            return(response);
        }
        public async Task <UserDetailsResponseModel> GetUserById(int id)
        {
            var user = await _userRepository.GetByIdAsync(id);

            if (user == null)
            {
                throw new NotFoundException("user does not exist");
            }

            var userDetails = new UserDetailsResponseModel
            {
                Id = user.Id, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName
            };

            return(userDetails);
        }
        public IHttpActionResult Get([FromUri] string userName)
        {
            if (this.users.GetUserDetails(userName) == null)
            {
                return(this.NotFound());
            }

            var userInfo = new UserDetailsResponseModel
            {
                UserName    = userName.Substring(0, userName.IndexOf('@')),
                RealEstates = this.users.GetRealEstatesPerUser(userName),
                Comments    = this.users.GetCommentsPerUser(userName),
                Rating      = this.users.GetAvgUserRating(userName)
            };

            return(this.Ok(userInfo));
        }
Beispiel #8
0
        public IHttpActionResult Profile(string userName)
        {
            var user = this.users.GetByUserName(userName);

            UserDetailsResponseModel userDetails = new UserDetailsResponseModel
            {
                UserName    = user.UserName,
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                MoneyAmount = user.MoneyAmount
            };

            var projects = user.InnovationProjects.AsQueryable().Select(ProjectListItemResponseModel.FromModel).ToList();

            userDetails.Projects = projects;

            return(this.Ok(userDetails));
        }
Beispiel #9
0
        public async Task <UserDetailsResponseModel> GetUserDetails(BaseRequestData data)
        {
            var userExists = await GetPlayerById(data.PlayerId);

            if (userExists != null)
            {
                var result      = new UserDetailsResponseModel();
                var playerStats = await _context.PlayerStatistics.FirstOrDefaultAsync(t => t.PlayerId == userExists.Id);

                result.Kills       = playerStats.Kills;
                result.Deaths      = playerStats.Deaths;
                result.Assists     = playerStats.Assists;
                result.GamesPlayed = playerStats.GamesPlayed;
                result.GamesWon    = playerStats.GamesWon;
                result.GameLose    = playerStats.GameLose;

                var clanMemberEntity = await _context.ClanMembers.FirstOrDefaultAsync(t => t.PlayerId == userExists.Id);

                if (clanMemberEntity != null)
                {
                    result.Function   = clanMemberEntity.Function;
                    result.DateOfJoin = clanMemberEntity.DateOfJoin;

                    var clanEntity = await _context.Clans.FirstOrDefaultAsync(t => t.Id == clanMemberEntity.ClanId);

                    result.AvatarId   = clanEntity.AvatarId;
                    result.Acronym    = clanEntity.Acronym;
                    result.AvatarUrl  = clanEntity.AvatarUrl;
                    result.Experience = clanEntity.Experience;
                    result.Name       = clanEntity.Name;

                    var clanStatsEntity = await _context.ClanStatistics.FirstOrDefaultAsync(t => t.ClanId == clanEntity.Id);

                    result.Wins   = clanStatsEntity.Wins;
                    result.Losses = clanStatsEntity.Losses;
                    result.Draws  = clanStatsEntity.Draws;
                }

                return(result);
            }

            return(new UserDetailsResponseModel());
        }
Beispiel #10
0
        public async Task <UserDetailsResponseModel> getUserById(int id)
        {
            var user = await _userRepository.GetByIdAsync(id);

            var incomes = new List <SubIncomeResponseModel>();

            foreach (var income in user.Incomes)
            {
                incomes.Add(new SubIncomeResponseModel
                {
                    Id          = income.Id,
                    Amount      = income.Amount,
                    Description = income.Description,
                    IncomeDate  = income.IncomeDate,
                    Remarks     = income.Remarks
                });
            }
            var expenditures = new List <SubExpenditureResponseModel>();

            foreach (var expenditure in user.Expenditures)
            {
                expenditures.Add(new SubExpenditureResponseModel
                {
                    Id          = expenditure.Id,
                    Amount      = expenditure.Amount,
                    Description = expenditure.Description,
                    ExpDate     = expenditure.ExpDate,
                    Remarks     = expenditure.Remarks
                });
            }
            var result = new UserDetailsResponseModel
            {
                Id           = user.Id,
                Email        = user.Email,
                Fullname     = user.Fullname,
                JoinedOn     = user.JoinedOn,
                Expenditures = expenditures,
                Incomes      = incomes
            };

            return(result);
        }
Beispiel #11
0
        public async Task <IActionResult> UserSetting(UserDetailsResponseModel model)
        {
            try
            {
                var result = await _userInterface.UpdateUserDetails(model, (Request.Cookies[_configuration["ZumbaCookies:ZumbaJwt"]]));

                if (result.Code != 200)
                {
                    _logger.LogError($"Error encountered in UserController||UpdateUserSettings Error Message {result.Message}");
                    ViewBag.ErrorMessage = result.Message;
                    return(RedirectToAction("Index", "Error"));
                }

                return(View());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in UserController||UserSetting ErrorMessage: {ex.Message}");
                throw;
            }
        }
Beispiel #12
0
        public static IEnumerable <Claim> ToClaims([NotNull] this UserDetailsResponseModel user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var claims = new List <Claim>
            {
                new Claim(JwtClaimTypes.PreferredUserName, user.Login)
            };

            var person = user.Person;

            claims.Add(new Claim(JwtClaimTypes.GivenName, person.FirstName));
            claims.Add(new Claim(JwtClaimTypes.FamilyName, person.LastName));

            if (!string.IsNullOrEmpty(person.Email))
            {
                claims.Add(new Claim(JwtClaimTypes.Email, person.Email));
            }

            if (!string.IsNullOrEmpty(person.MiddleName))
            {
                claims.Add(new Claim(JwtClaimTypes.MiddleName, person.MiddleName));
            }

            if (!string.IsNullOrEmpty(person.AvatarPath))
            {
                claims.Add(new Claim(JwtClaimTypes.Picture, person.AvatarPath));
            }

            claims.AddRange(
                user.Roles.SelectMany(x => x.Permissions).Select(x => x.Name).Distinct()
                .Select(permission => new Claim("permissions", permission))
                );

            return(claims);
        }