示例#1
0
        public TraineeInfoModel GetTraineeById(string traineeId)
        {
            var elmt = (from t in _aspnetGymTrackerContext.Trainee
                        join u in _aspnetGymTrackerContext.ApplicationUser
                        on t.TraineeId equals u.Id
                        where t.TraineeId == traineeId
                        select new { t.TraineeId, t.TrainerId, u.Name, u.Surname, t.Birthday, t.Gender, u.Email, u.PhoneNumber, u.GymId, u.City, u.Image, t.EntryDate }).FirstOrDefault();
            TraineeInfoModel model = new TraineeInfoModel
            {
                TraineeId   = elmt.TraineeId,
                TrainerId   = elmt.TrainerId,
                Name        = elmt.Name,
                Surname     = elmt.Surname,
                Birthday    = elmt.Birthday,
                Gender      = elmt.Gender,
                Email       = elmt.Email,
                PhoneNumber = elmt.PhoneNumber,
                GymId       = elmt.GymId,
                City        = elmt.City,
                EntryDate   = elmt.EntryDate,
                Image       = elmt.Image
            };
            var measurements = _aspnetGymTrackerContext.TraineeMeasurements.Where(u => u.TraineeId == traineeId).OrderByDescending(u => u.Date).FirstOrDefault();

            if (measurements != null)
            {
                model.Weight   = measurements.Weight;
                model.Height   = measurements.Height;
                model.FatRatio = measurements.FatRatio;
            }
            return(model);
        }
        public async Task <IActionResult> UpdateTraineeInfo(EditTraineeViewModel model)
        {
            model.DateOfBirth = DateTime.ParseExact(model.StrDateOfBirth, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            TraineeInfoModel trainee = new TraineeInfoModel
            {
                Name        = model.Name,
                Surname     = model.Surname,
                Email       = model.Email,
                City        = model.City,
                PhoneNumber = model.Phone,
                Birthday    = model.DateOfBirth,
                Gender      = model.Gender,
                TraineeId   = model.TraineeId
            };

            if (model.Image != null && model.Image.Length > 0)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await model.Image.CopyToAsync(memoryStream);

                    trainee.Image = memoryStream.ToArray();
                }
            }
            _traineeRepository.UpdateTrainee(trainee);
            return(RedirectToAction("Trainees", "Home"));
        }
        public IActionResult TraineeDetails(string Id)
        {
            TraineeInfoModel            personalInfo = _traineeRepository.GetTraineeById(Id);
            IEnumerable <DailyProgress> dp           = _dailyProgressRepository.DailyProgresses(Id);
            List <DailyProgress>        dpList       = new List <DailyProgress>();

            foreach (DailyProgress prog in dp)
            {
                DailyProgress progress = new DailyProgress();
                progress.AssignedSets  = prog.AssignedSets;
                progress.CompletedSets = prog.CompletedSets;
                progress.Date          = prog.Date;
                progress.ProgressId    = prog.ProgressId;
                progress.TraineeId     = prog.TraineeId;
                progress.ExerciseId    = prog.ExerciseId;
                dpList.Add(progress);
            }
            //var dailyProgressesJson = JsonConvert.SerializeObject(dpList, Formatting.None,
            //            new JsonSerializerSettings()
            //            {
            //                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            //            });
            TraineeDetailsPageViewModel model = new TraineeDetailsPageViewModel
            {
                Id                = personalInfo.TraineeId,
                Name              = personalInfo.Name,
                Surname           = personalInfo.Surname,
                Email             = personalInfo.Email,
                DateOfBirth       = (DateTime)personalInfo.Birthday,
                Image             = personalInfo.Image,
                Phone             = personalInfo.PhoneNumber,
                Weight            = (personalInfo.Weight != null ? (double)personalInfo.Weight : double.NaN),
                Height            = (personalInfo.Height != null ? (double)personalInfo.Height : double.NaN),
                FatRatio          = personalInfo.FatRatio,
                City              = personalInfo.City,
                Gender            = personalInfo.Gender,
                EntryDate         = personalInfo.EntryDate,
                DailyProgresses   = dp,
                DailyProgressList = dpList,
                DailyRoutines     = _dailyRoutineRepository.DailyRoutines(Id),
                Exercises         = _exerciseRepository.Exercises,
                Measurements      = _traineeMeasurementsRepository.GetTraineeMeasurements(Id)
            };

            return(View(model));
        }
        //to open edit trainee page
        public IActionResult EditTrainee(string Id)
        {
            TraineeInfoModel     model   = _traineeRepository.GetTraineeById(Id);
            EditTraineeViewModel trainee = new EditTraineeViewModel
            {
                Name         = model.Name,
                Surname      = model.Surname,
                Email        = model.Email,
                Phone        = model.PhoneNumber,
                City         = model.City,
                DateOfBirth  = (DateTime)model.Birthday,
                Gender       = model.Gender,
                CurrentImage = model.Image,
                TraineeId    = model.TraineeId
            };

            return(View(trainee));
        }
示例#5
0
        public void UpdateTrainee(TraineeInfoModel trainee)
        {
            var result = _aspnetGymTrackerContext.Trainee.SingleOrDefault(b => b.TraineeId == trainee.TraineeId);

            if (result != null)
            {
                result.Birthday = trainee.Birthday;
                result.Gender   = trainee.Gender;
                _aspnetGymTrackerContext.SaveChanges();
            }
            var result2 = _aspnetGymTrackerContext.ApplicationUser.SingleOrDefault(b => b.Id == trainee.TraineeId);

            if (result2 != null)
            {
                result2.Name        = trainee.Name;
                result2.Email       = trainee.Email;
                result2.PhoneNumber = trainee.PhoneNumber;
                result2.City        = trainee.City;
                result2.Image       = trainee.Image;
                _aspnetGymTrackerContext.SaveChanges();
            }
        }
示例#6
0
        public IEnumerable <TraineeInfoModel> GetTrainees(string trainerId)
        {
            var traineesGeneral = (from t in _aspnetGymTrackerContext.Trainee
                                   join u in _aspnetGymTrackerContext.ApplicationUser
                                   on t.TraineeId equals u.Id
                                   where t.TrainerId == trainerId
                                   select new { t.TraineeId, t.TrainerId, u.Name, u.Surname, t.Birthday, t.Gender, u.Email, u.PhoneNumber, u.GymId, u.City, u.Image, t.EntryDate }).ToList();
            List <TraineeInfoModel> trainees = new List <TraineeInfoModel>();

            foreach (var elmt in traineesGeneral)
            {
                TraineeInfoModel trainee = new TraineeInfoModel
                {
                    TraineeId   = elmt.TraineeId,
                    TrainerId   = elmt.TrainerId,
                    Name        = elmt.Name,
                    Surname     = elmt.Surname,
                    Birthday    = elmt.Birthday,
                    Gender      = elmt.Gender,
                    Email       = elmt.Email,
                    PhoneNumber = elmt.PhoneNumber,
                    GymId       = elmt.GymId,
                    City        = elmt.City,
                    EntryDate   = elmt.EntryDate,
                    Image       = elmt.Image
                };
                TraineeMeasurements measurements = _aspnetGymTrackerContext.TraineeMeasurements.Where(u => u.TraineeId == trainee.TraineeId).OrderByDescending(u => u.Date).FirstOrDefault();
                if (measurements != null)
                {
                    trainee.Weight   = measurements.Weight;
                    trainee.Height   = measurements.Height;
                    trainee.FatRatio = measurements.FatRatio;
                }
                trainees.Add(trainee);
            }
            return(trainees);
        }