コード例 #1
0
        public IActionResult GetUserInfo(string userId)
        {
            try
            {
                UserInfo userInfo = null;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    userId = SessionUserId;
                }
                var user = _usersService.GetUser(new UserKey()
                {
                    Id = userId
                });

                if (user != null)
                {
                    userInfo = _userInfosService.GetUserInfo(new UserInfoKey()
                    {
                        UserId = userId
                    });
                    return(new OkObjectResult(userInfo));
                }
                return(new NotFoundResult());
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            }
        }
コード例 #2
0
        public static TUnitType GetUserUnit(IUserInfosService userInfosService, string userId)
        {
            TUnitType result = TUnitType.Imperial;

            if (userId != null && userInfosService != null)
            {
                var userInfo = userInfosService.GetUserInfo(new UserInfoKey()
                {
                    UserId = userId
                });
                if (userInfo != null)
                {
                    result = userInfo.Unit;
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: NitrofCG/BodyReport
        public async Task <IActionResult> ConfirmUserEmail(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                var appUser = await _identityUserManager.FindByIdAsync(id);

                if (appUser != null && !appUser.EmailConfirmed)
                {
                    appUser.EmailConfirmed = true;
                    await _identityUserManager.UpdateAsync(appUser);

                    //Add user role
                    var userKey = new UserKey()
                    {
                        Id = id
                    };
                    var user = _usersService.GetUser(userKey);
                    if (user != null)
                    {
                        //Verify role exist
                        var roleKey = new RoleKey();
                        roleKey.Id = "1"; //User
                        var role = _rolesService.GetRole(roleKey);
                        if (role != null)
                        {
                            user.Role = role;
                            user      = _usersService.UpdateUser(user);
                        }
                    }

                    //Add empty user profil (for correct connect error on mobile application)
                    var userInfoKey = new UserInfoKey()
                    {
                        UserId = id
                    };
                    var userInfo = _userInfosService.GetUserInfo(userInfoKey);
                    if (userInfo == null)
                    {
                        userInfo = new UserInfo()
                        {
                            UserId = id,
                            Unit   = TUnitType.Metric
                        };
                        _userInfosService.UpdateUserInfo(userInfo);
                    }

                    try
                    {
                        string reportData = await _reportService.CreateReportForAdminNewUserAccountCreatedAsync(user.Id);

                        await _emailSender.SendEmailAsync(appUser.Email, Translation.CONFIRM_USER_ACCOUNT, reportData);

                        await _emailSender.SendEmailAsync(appUser.Email, "Account validated",
                                                          "Your account validated by admin");
                    }
                    catch (Exception except)
                    {
                        _logger.LogError(0, except, "can't send email");
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        //
        // GET: /Report/TrainingDayReport/Index
        public IActionResult Index(string userId, int year, int weekOfYear, int dayOfWeek, int?trainingDayId, bool displayImages, string userIdViewer)
        {
            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey()
            {
                UserId = userId
            });

            if (userInfo == null)
            {
                userInfo = new UserInfo();
            }

            var trainingWeekKey = new TrainingWeekKey()
            {
                UserId     = userId,
                Year       = year,
                WeekOfYear = weekOfYear
            };

            var trainingWeekScenario = new TrainingWeekScenario()
            {
                ManageTrainingDay   = true,
                TrainingDayScenario = new TrainingDayScenario()
                {
                    ManageExercise = true
                }
            };
            var trainingWeek = _trainingWeeksService.GetTrainingWeek(trainingWeekKey, trainingWeekScenario);

            if (trainingWeek == null)
            {
                trainingWeek = new TrainingWeek();
            }

            //Unit viewer convertion
            if (string.IsNullOrEmpty(userIdViewer))
            {
                userIdViewer = SessionUserId;
            }
            var viewerUnit = AppUtils.GetUserUnit(_userInfosService, userIdViewer);
            var userUnit   = AppUtils.GetUserUnit(_userInfosService, userId);

            trainingWeek.UserHeight = Utils.TransformLengthToUnitSytem(userUnit, viewerUnit, trainingWeek.UserHeight);
            trainingWeek.UserWeight = Utils.TransformWeightToUnitSytem(userUnit, viewerUnit, trainingWeek.UserWeight);

            var trainingWeekViewModel = TrainingViewModelTransformer.TrainingWeekToViewModel(trainingWeek, _usersService);
            List <TrainingDayViewModel>      trainingDayViewModels      = null;
            List <TrainingExerciseViewModel> trainingExerciseViewModels = null;

            if (trainingWeek != null && trainingWeek.TrainingDays != null && trainingWeek.TrainingDays.Count > 0)
            {
                trainingDayViewModels = new List <TrainingDayViewModel>();
                foreach (var trainingDay in trainingWeek.TrainingDays)
                {
                    if (!trainingDayId.HasValue || trainingDay.TrainingDayId == trainingDayId)
                    {
                        if (trainingDay.DayOfWeek == dayOfWeek)
                        { // Get only current
                            trainingDayViewModels.Add(TrainingViewModelTransformer.TrainingDayToViewModel(trainingDay, userInfo));

                            var trainingExercises = FindTrainingExercise(trainingDay);
                            if (trainingExercises != null)
                            {
                                foreach (var trainingExercise in trainingExercises)
                                {
                                    //Convert user Unit to viewer unit
                                    if (trainingExercise.TrainingExerciseSets != null)
                                    {
                                        foreach (var set in trainingExercise.TrainingExerciseSets)
                                        {
                                            set.Weight = Utils.TransformWeightToUnitSytem(userUnit, viewerUnit, set.Weight);
                                        }
                                    }

                                    if (trainingExerciseViewModels == null)
                                    {
                                        trainingExerciseViewModels = new List <TrainingExerciseViewModel>();
                                    }
                                    trainingExerciseViewModels.Add(TrainingViewModelTransformer.TrainingExerciseToViewModel(trainingExercise, _bodyExercisesService));
                                }
                            }
                        }
                    }
                }
            }

            ViewBag.DayOfWeek     = dayOfWeek;
            ViewBag.displayImages = displayImages;
            ViewBag.ViewerUnit    = viewerUnit;
            return(View(new Tuple <TrainingWeekViewModel, List <TrainingDayViewModel>, List <TrainingExerciseViewModel> >(trainingWeekViewModel, trainingDayViewModels, trainingExerciseViewModels)));
        }
コード例 #5
0
        public IActionResult Index(string userId)
        {
            string userIdViewer = SessionUserId;

            if (userId == null)
            {
                userId = SessionUserId;
            }
            var user = _usersService.GetUser(new UserKey()
            {
                Id = userId
            });

            var viewModel = new UserProfilViewModel();

            viewModel.UserId = user.Id;

            if (user != null)
            {
                viewModel.Name  = user.Name;
                viewModel.Email = user.Email;

                var userInfoViewer = _userInfosService.GetUserInfo(new UserInfoKey()
                {
                    UserId = userIdViewer
                });
                if (userInfoViewer == null)
                {
                    userInfoViewer = new UserInfo();
                }
                var userInfo = _userInfosService.GetUserInfo(new UserInfoKey()
                {
                    UserId = userId
                });
                if (userInfo != null)
                {
                    viewModel.SexId     = (int)userInfo.Sex;
                    viewModel.Unit      = (int)userInfoViewer.Unit; //On viewer Mode, it's viewer unit which display
                    viewModel.Height    = Utils.TransformLengthToUnitSytem(userInfo.Unit, userInfoViewer.Unit, userInfo.Height);
                    viewModel.Weight    = Utils.TransformWeightToUnitSytem(userInfo.Unit, userInfoViewer.Unit, userInfo.Weight);
                    viewModel.ZipCode   = userInfo.ZipCode;
                    viewModel.CountryId = userInfo.CountryId;

                    if (userInfo.CountryId == 0)
                    {
                        ViewBag.City = Translation.NOT_SPECIFIED;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(userInfo.ZipCode))
                        {
                            ViewBag.City = Translation.NOT_SPECIFIED;
                        }
                        else
                        {
                            var city = _citiesService.GetCity(new CityKey()
                            {
                                CountryId = userInfo.CountryId, ZipCode = userInfo.ZipCode
                            });
                            ViewBag.City = city == null ? Translation.NOT_SPECIFIED : city.Name;
                        }
                    }

                    var country = _countriesService.GetCountry(new CountryKey()
                    {
                        Id = userInfo.CountryId
                    });
                    ViewBag.Country = country == null ? Translation.NOT_SPECIFIED : country.Name;

                    ViewBag.TimeZoneName = userInfo.TimeZoneName;
                    viewModel.ImageUrl   = ImageUtils.GetImageUserProfileRelativeURL(user, _env);
                }
            }

            ViewBag.Editable        = userIdViewer == userId;
            ViewBag.IsMobileBrowser = Request.IsMobileBrowser();
            return(View(viewModel));
        }