示例#1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="userInfo">UserInfo</param>
        /// <returns>insert data</returns>
        public UserInfo Create(UserInfo userInfo)
        {
            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId))
                return null;

            var row = new UserInfoRow();
            UserInfoTransformer.ToRow(userInfo, row);
            _dbContext.UserInfo.Add(row);
            _dbContext.SaveChanges();
            return UserInfoTransformer.ToBean(row);
        }
        public static TrainingDayViewModel TrainingDayToViewModel(TrainingDay trainingDay, UserInfo userInfo)
        {
            var result = new TrainingDayViewModel()
            {
                UserId = trainingDay.UserId,
                Year = trainingDay.Year,
                WeekOfYear = trainingDay.WeekOfYear,
                DayOfWeek = trainingDay.DayOfWeek,
                TrainingDayId = trainingDay.TrainingDayId
            };

            //convert date to user timezone
            var timeZoneInfo = TimeZoneMapper.GetTimeZoneByOlsonName(userInfo.TimeZoneName);
            if (timeZoneInfo == null)
                timeZoneInfo = TimeZoneInfo.Local;
            result.BeginHour = TimeZoneInfo.ConvertTime(trainingDay.BeginHour, timeZoneInfo);
            result.EndHour = TimeZoneInfo.ConvertTime(trainingDay.EndHour, timeZoneInfo);

            return result;
        }
示例#3
0
        internal static UserInfo ToBean(UserInfoRow row)
        {
            if (row == null)
                return null;

            var bean = new UserInfo();
            bean.UserId = row.UserId;
            bean.Unit = (TUnitType)row.Unit;
            bean.Height = row.Height;
            bean.Weight = row.Weight;
            bean.Sex = (TSexType)row.Sex;
            bean.ZipCode = row.ZipCode;
            bean.CountryId = row.CountryId;

            if (string.IsNullOrWhiteSpace(row.TimeZoneName))
                bean.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id);
            else
                bean.TimeZoneName = row.TimeZoneName;

            return bean;
        }
示例#4
0
        public static void ToRow(UserInfo bean, UserInfoRow row)
        {
            if (bean == null)
                return;

            row.UserId = bean.UserId;
            row.Unit = (int)bean.Unit;
            row.Height = bean.Height;
            row.Weight = bean.Weight;
            row.Sex = (int)bean.Sex;
            row.ZipCode = bean.ZipCode;
            row.CountryId = bean.CountryId;

            if (string.IsNullOrWhiteSpace(bean.TimeZoneName))
            {
                if(string.IsNullOrWhiteSpace(row.TimeZoneName)) // only update if not present
                    row.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id);
            }
            else
                row.TimeZoneName = bean.TimeZoneName;
        }
示例#5
0
 public UserInfo UpdateUserInfo(UserInfo userInfo)
 {
     UserInfo result = null;
     BeginTransaction();
     try
     {
         result = GetUserInfoManager().UpdateUserInfo(userInfo);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch (Exception exception)
     {
         _logger.LogCritical("Unable to update user info", exception);
         RollbackTransaction();
         throw exception;
     }
     finally
     {
         EndTransaction();
     }
     return result;
 }
        //
        // 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 = GetUserUnit(userIdViewer);
            var userUnit = GetUserUnit(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));
        }
示例#7
0
        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
                    {
                        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");
        }
示例#8
0
        public async Task<IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return View("Error");
            }
            var applicationUser = await _identityUserManager.FindByIdAsync(userId);
            if (applicationUser == null)
            {
                return View("Error");
            }
            var result = await _identityUserManager.ConfirmEmailAsync(applicationUser, code);

            if(result.Succeeded)
            {
                // add role to user
                //await _userManager.AddToRoleAsync(user, "user"); //don't work on rc2???
                // Verify not exist on id
                var key = new UserKey() { Id = applicationUser.Id };
                var user = _usersService.GetUser(key);
                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);
                    }

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

                    return RedirectToAction("Index", "Home", new { area = "Site" });
                }
            }
            return View(result.Succeeded ? "ConfirmEmail" : "Error");
        }
        public IActionResult EditTrainingDay(string userId, int year, int weekOfYear, int dayOfWeek, int trainingDayId)
        {
            if (string.IsNullOrWhiteSpace(userId) || year == 0 || weekOfYear == 0 || dayOfWeek < 0 || dayOfWeek > 6 || trainingDayId == 0 || SessionUserId != userId)
                return RedirectToAction("Index");

            var key = new TrainingDayKey()
            {
                UserId = userId,
                Year = year,
                WeekOfYear = weekOfYear,
                DayOfWeek = dayOfWeek,
                TrainingDayId = trainingDayId
            };
            var trainingDayScenario = new TrainingDayScenario() { ManageExercise = true };
            var trainingDay = _trainingDaysService.GetTrainingDay(key, trainingDayScenario);
            if (trainingDay == null) // no data found
                return RedirectToAction("View", new { userId = userId, year = year, weekOfYear = weekOfYear, dayOfWeek = dayOfWeek });

            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = SessionUserId });
            if (userInfo == null)
                userInfo = new UserInfo();
            return View(TrainingViewModelTransformer.TrainingDayToViewModel(trainingDay, userInfo));
        }
        public IActionResult Create()
        {
            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = SessionUserId });
            if (userInfo == null)
                userInfo = new UserInfo();

            var timeZoneInfo = TimeZoneMapper.GetTimeZoneByOlsonName(userInfo.TimeZoneName);
            if (timeZoneInfo == null)
                timeZoneInfo = TimeZoneInfo.Local;
            DateTime dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);

            var trainingWeek = new TrainingWeek();
            trainingWeek.UserId = SessionUserId;
            trainingWeek.Year = dateTime.Year;
            trainingWeek.WeekOfYear = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
            trainingWeek.UserHeight = userInfo.Height;
            trainingWeek.UserWeight = userInfo.Weight;
            trainingWeek.Unit = userInfo.Unit;

            ViewBag.UserUnit = userInfo.Unit;
            return View(TrainingViewModelTransformer.TrainingWeekToViewModel(trainingWeek, _usersService));
        }
        public IActionResult Copy(string userId, int year, int weekOfYear)
        {
            if (string.IsNullOrWhiteSpace(userId) || year == 0 || weekOfYear == 0 || SessionUserId != userId)
                return RedirectToAction("Index");

            ViewBag.UserUnit = GetUserUnit(userId);
            var key = new TrainingWeekKey()
            {
                UserId = userId,
                Year = year,
                WeekOfYear = weekOfYear
            };
            var trainingWeekScenario = new TrainingWeekScenario()
            {
                ManageTrainingDay = true,
                TrainingDayScenario = new TrainingDayScenario() { ManageExercise = true }
            };
            var trainingWeek = _trainingWeeksService.GetTrainingWeek(key, trainingWeekScenario);
            if (trainingWeek == null) // no data found
                return RedirectToAction("Index");

            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = SessionUserId });
            if (userInfo == null)
                userInfo = new UserInfo();
            var timeZoneInfo = TimeZoneMapper.GetTimeZoneByOlsonName(userInfo.TimeZoneName);
            if (timeZoneInfo == null)
                timeZoneInfo = TimeZoneInfo.Local;
            DateTime dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo);
            int nextWeekOfYear = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);

            if (dateTime.Year == year && nextWeekOfYear == weekOfYear
                && nextWeekOfYear < 52)
            {
                nextWeekOfYear++;
            }

            var viewModel = new CopyTrainingWeekViewModel()
            {
                UserId = userId,
                OriginWeekOfYear = weekOfYear,
                OriginYear = year,
                Year = dateTime.Year,
                WeekOfYear = nextWeekOfYear
            };

            //Need for refresh WeekOfYear in CopyTrainingWeekViewModel. Why? i don't understand on this page.
            ModelState.Clear();
            return View(viewModel);
        }
        public IActionResult View(string userId, int year, int weekOfYear, int? dayOfWeekSelected)
        {
            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = userId });
            if (userInfo == null)
                userInfo = new UserInfo();

            var timeZoneInfo = TimeZoneMapper.GetTimeZoneByOlsonName(userInfo.TimeZoneName);
            if (timeZoneInfo == null)
                timeZoneInfo = TimeZoneInfo.Local;

            DayOfWeek currentDayOfWeek = GetCurrentDayOfWeek(dayOfWeekSelected, timeZoneInfo);
            if (!dayOfWeekSelected.HasValue)
                dayOfWeekSelected = (int)currentDayOfWeek;

            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)
                return RedirectToAction("Index");

            //Unit viewer convertion
            string userIdViewer = SessionUserId;
            var viewerUnit = GetUserUnit(userIdViewer);
            var userUnit = GetUserUnit(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)
                {
                    trainingDayViewModels.Add(TrainingViewModelTransformer.TrainingDayToViewModel(trainingDay, userInfo));

                    if (dayOfWeekSelected.HasValue && trainingDay.DayOfWeek == dayOfWeekSelected)
                    { // Get only current
                        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.UserIdViewer = userIdViewer;
            ViewBag.CurrentDayOfWeek = currentDayOfWeek;
            ViewBag.ViewerUnit = viewerUnit;
            ViewBag.Editable = userId == userIdViewer;
            return View(new Tuple<TrainingWeekViewModel, List<TrainingDayViewModel>, List<TrainingExerciseViewModel>>(trainingWeekViewModel, trainingDayViewModels, trainingExerciseViewModels));
        }
示例#13
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);
        }
示例#14
0
        public IActionResult Edit(UserProfilViewModel viewModel, IFormFile imageFile)
        {
            int sexId = 0, countryId = 0;
            if (ModelState.IsValid && _signInManager.IsSignedIn(User) && viewModel != null)
            {
                if (viewModel.UserId == SessionUserId)
                {
                    if (viewModel.CountryId == 0) // not specified
                    {
                        viewModel.ZipCode = string.Empty;
                    }
                    bool continute = true;
                    if (sexId < 0 && sexId > 1)
                    {
                        ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.SEX));
                        viewModel.SexId = 0;
                        continute = false;
                    }

                    if (continute && viewModel.CountryId != 0)
                    {
                        var country = _countriesService.GetCountry(new CountryKey() { Id = viewModel.CountryId });
                        if (country == null)
                        {
                            ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.COUNTRY));
                            viewModel.CountryId = 0;
                            continute = false;
                        }
                    }

                    if (continute && !string.IsNullOrEmpty(viewModel.ZipCode))
                    { // ZipCode not Required
                        var city = _citiesService.GetCity(new CityKey() { CountryId = viewModel.CountryId, ZipCode = viewModel.ZipCode });
                        if (city == null)
                        {
                            ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.ZIP_CODE));
                            continute = false;
                        }
                    }

                    sexId = viewModel.SexId;
                    countryId = viewModel.CountryId;

                    if (continute)
                    {
                        var userInfo = new UserInfo()
                        {
                            UserId = viewModel.UserId,
                            Unit = (TUnitType)viewModel.Unit,
                            Height = viewModel.Height,
                            Weight = viewModel.Weight,
                            ZipCode = viewModel.ZipCode,
                            CountryId = viewModel.CountryId,
                            Sex = (TSexType)viewModel.SexId,
                            TimeZoneName = viewModel.TimeZoneName,
                        };

                        userInfo = _userInfosService.UpdateUserInfo(userInfo);

                        if (!string.IsNullOrWhiteSpace(userInfo.UserId) && ImageUtils.CheckUploadedImageIsCorrect(imageFile))
                        {
                            string ext = ImageUtils.GetImageExtension(imageFile);
                            if (string.IsNullOrWhiteSpace(ext))
                                return BadRequest();
                            ImageUtils.SaveImage(imageFile, Path.Combine(_env.WebRootPath, "images", "userprofil"), userInfo.UserId + ext);
                        }

                        return RedirectToAction("Index");
                    }
                }
            }

            ViewBag.Sex = ControllerUtils.CreateSelectSexItemList(sexId);
            ViewBag.Countries = ControllerUtils.CreateSelectCountryItemList(_countriesService.FindCountries(), countryId);
            ViewBag.Units = ControllerUtils.CreateSelectUnitItemList(viewModel.Unit);
            ViewBag.TimeZones = ControllerUtils.CreateSelectTimeZoneItemList(viewModel.TimeZoneName);
            return View(viewModel);
        }
示例#15
0
 internal UserInfo UpdateUserInfo(UserInfo userInfo)
 {
     return _userInfoModule.Update(userInfo);
 }
示例#16
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="userInfo">data</param>
        /// <returns>updated data</returns>
        public UserInfo Update(UserInfo userInfo)
        {
            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId))
                return null;

            var row = _dbContext.UserInfo.Where(m => m.UserId == userInfo.UserId).FirstOrDefault();
            if (row == null)
            { // No data in database
                return Create(userInfo);
            }
            else
            { //Modify Data in database
                UserInfoTransformer.ToRow(userInfo, row);
                _dbContext.SaveChanges();
                return UserInfoTransformer.ToBean(row);
            }
        }