public void Over52Category2_Limit()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 52.01m);

            Assert.AreEqual(56, category);
        }
示例#2
0
        private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Keyboard.Focus(this);
            IsInProgress = true;

            PleaseWait.Run(x =>
            {
                try
                {
                    championship = updateChampionship();
                    var result   = ServiceManager.SaveChampionship(Championship);
                    championship = result.Championship;
                    ChampionshipsReposidory.Instance.Update(Championship);
                    UIHelper.Invoke(() =>
                    {
                        fillImplementation();
                        displayNotificationAboutRecords(result);
                    }, Dispatcher);
                }
                catch (ArgumentException ex)
                {
                    UIHelper.Invoke(() =>
                    {
                        this.ParentWindow.SetException(ex);
                        ExceptionHandler.Default.Process(ex, InstructorStrings.ChampionshipView_ErrCustomerWithoutGender, ErrorWindow.MessageBox);
                    }, Dispatcher);
                }
                catch (LicenceException ex)
                {
                    UIHelper.Invoke(() =>
                    {
                        this.ParentWindow.SetException(ex);
                        ExceptionHandler.Default.Process(ex, Strings.ErrorLicence, ErrorWindow.MessageBox);
                    }, Dispatcher);
                }
                catch (OldDataException ex)
                {
                    UIHelper.Invoke(() =>
                    {
                        this.ParentWindow.SetException(ex);
                        ExceptionHandler.Default.Process(ex, Strings.ErrorOldTrainingDay, ErrorWindow.MessageBox);
                    }, Dispatcher);
                }
                catch (Exception ex)
                {
                    UIHelper.Invoke(() =>
                    {
                        this.ParentWindow.SetException(ex);
                        ExceptionHandler.Default.Process(ex, InstructorStrings.ChampionshipView_ErrSaveUnhandled, ErrorWindow.MessageBox);
                    }, Dispatcher);
                }
                finally
                {
                    UIHelper.Invoke(delegate
                    {
                        IsInProgress = false;
                    }, Dispatcher);
                }
            });
        }
        public void Highest125Category_Limit()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 125.0m);

            Assert.AreEqual(125, category);
        }
        public void Over125Category_Limit()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 125.01m);

            Assert.AreEqual(decimal.MaxValue, category);
        }
        public void MiddleCategory1()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 70m);

            Assert.AreEqual(75, category);
        }
        public void MiddleCategory2_LowerLimit()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 90.01m);

            Assert.AreEqual(100, category);
        }
        public void Less52Category1()
        {
            ChampionshipDTO dto      = new ChampionshipDTO();
            var             category = ModelHelper.GetWeightCategory(dto.WeightMenCategories, 30);

            Assert.AreEqual(52, category);
        }
示例#8
0
        public SaveChampionshipResult SaveChampionship(Token token, ChampionshipDTO championship)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new ChampionshipService(Session, securityInfo, Configuration);

            return(service.SaveChampionship(championship));
        }
示例#9
0
 public static Championship Unmapper(ChampionshipDTO model)
 {
     return(new Championship()
     {
         ID = model.ID,
         Name = model.Name,
     });
 }
示例#10
0
        void fillResults(ChampionshipDTO item)
        {
            List <ChampionshipResultsViewModel> items = new List <ChampionshipResultsViewModel>();

            foreach (IGrouping <ChampionshipCategoryDTO, ChampionshipResultItemDTO> dto in item.Results.GroupBy(x => x.Category).OrderBy(x => x.Key.Category))
            {
                items.Add(new ChampionshipResultsViewModel(dto));
            }
            HasResults             = item.Results.Count > 0;
            lstResults.ItemsSource = items;
        }
示例#11
0
        private void fillImplementation()
        {
            original     = Championship;
            championship = Championship.StandardClone();
            fillChampionship(Championship);
            fillResults(Championship);
            grid.BuildColumns(Championship.ChampionshipType);

            updateReadOnly();
            updateButtons(true);
        }
示例#12
0
        public ChampionshipEntryViewModel(CustomerDTO customer, ChampionshipDTO championship, ChampionshipView mainViewModel)
        {
            this.customer        = customer;
            championshipCustomer = championship.Customers.Where(x => x.CustomerId == customer.GlobalId).SingleOrDefault();
            if (championshipCustomer == null)
            {
                championshipCustomer            = new ChampionshipCustomerDTO();
                championshipCustomer.CustomerId = customer.GlobalId;
                championship.Customers.Add(championshipCustomer);
            }
            var itemGroup = mainViewModel.Groups.Where(x => x.Value == championshipCustomer.Group).SingleOrDefault();

            SelectedGroup = itemGroup;

            var benchPress = ExercisesReposidory.Instance.GetItem(new Guid("ece5dfd7-f995-45ae-bb34-067f26c4f7b4"));
            var przysiad   = ExercisesReposidory.Instance.GetItem(new Guid("3e06a130-b811-4e45-9285-f087403615bf"));
            var deadLift   = ExercisesReposidory.Instance.GetItem(new Guid("505988e1-5663-41f1-aa1a-9b92ea584263"));

            var benchPressEntry = championship.Entries.Where(x => x.Customer.CustomerId == customer.GlobalId && x.Exercise.GlobalId == benchPress.GlobalId).SingleOrDefault();

            if (benchPressEntry == null)
            {
                benchPressEntry          = new ChampionshipEntryDTO();
                benchPressEntry.Exercise = benchPress;
                benchPressEntry.Customer = championshipCustomer;
            }
            var przysiadEntry = championship.Entries.Where(x => x.Customer.CustomerId == customer.GlobalId && x.Exercise.GlobalId == przysiad.GlobalId).SingleOrDefault();

            if (przysiadEntry == null)
            {
                przysiadEntry          = new ChampionshipEntryDTO();
                przysiadEntry.Exercise = przysiad;
                przysiadEntry.Customer = championshipCustomer;
            }

            var deadLiftEntry = championship.Entries.Where(x => x.Customer.CustomerId == customer.GlobalId && x.Exercise.GlobalId == deadLift.GlobalId).SingleOrDefault();

            if (deadLiftEntry == null)
            {
                deadLiftEntry          = new ChampionshipEntryDTO();
                deadLiftEntry.Exercise = deadLift;
                deadLiftEntry.Customer = championshipCustomer;
            }

            exercise1 = new ChampionshipExerciseViewModel(benchPressEntry);
            exercise2 = new ChampionshipExerciseViewModel(przysiadEntry);
            exercise3 = new ChampionshipExerciseViewModel(deadLiftEntry);

            weightCategory = getWeightCategory();
        }
示例#13
0
 public override void Fill()
 {
     Header       = string.Format(InstructorStrings.ChampionshipView_Header, ChampionshipPageContext.Championship.Name);
     IsInProgress = true;
     updateButtons(false);
     ParentWindow.RunAsynchronousOperation(x =>
     {
         var champWait     = ChampionshipsReposidory.Instance.BeginEnsure();
         var custWait      = CustomersReposidory.Instance.BeginEnsure();
         var exercisesWait = ExercisesReposidory.Instance.BeginEnsure();
         WaitHandle.WaitAll(new WaitHandle[] { custWait, champWait, exercisesWait });
         UIHelper.Invoke(() =>
         {
             championship = ChampionshipsReposidory.Instance.GetItem(((BAGlobalObject)ChampionshipPageContext.Championship).GlobalId);
             fillImplementation();
             IsInProgress = false;
         }, Dispatcher);
     });
 }
示例#14
0
        void fillChampionship(ChampionshipDTO item)
        {
            groups.Clear();
            Groups.Add(new ListItem <ChampionshipGroupDTO>("", null));
            foreach (var championshipGroupDto in item.Groups)
            {
                Groups.Add(new ListItem <ChampionshipGroupDTO>(championshipGroupDto.Name, championshipGroupDto));
            }

            Items.Clear();
            foreach (var reservation in item.Reservations)
            {
                var customer = CustomersReposidory.Instance.GetItem(reservation.CustomerId);
                ChampionshipEntryViewModel itemViewModel = new ChampionshipEntryViewModel(customer, item, this);

                Items.Add(itemViewModel);
            }

            if (teamsControl != null)
            {
                teamsControl.Fill(this);
            }
        }
示例#15
0
 public void Insert(ChampionshipDTO _Championship)
 {
     this.InsertEntity(ChampionshipMapper.Unmapper(_Championship));
 }
示例#16
0
        public SaveChampionshipResult SaveChampionship(ChampionshipDTO championship)
        {
            SaveChampionshipResult result = new SaveChampionshipResult();

            if (!SecurityInfo.Licence.IsInstructor)
            {
                throw new LicenceException("This feature is allowed for Instructor account");
            }
            if (championship.IsNew)
            {
                throw new InvalidOperationException("Cannot create a championship using this method");
            }

            using (var trans = Session.BeginSaveTransaction())
            {
                var dbMe           = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var dbChampionship = Session.QueryOver <Championship>()
                                     .Fetch(x => x.Reservations).Eager
                                     .Fetch(x => x.Reservations.First().Customer).Eager
                                     .Where(x => x.GlobalId == championship.GlobalId).SingleOrDefault();

                //for eager fetch only
                Session.QueryOver <Championship>()
                .Fetch(x => x.Customers).Eager
                //.Fetch(x => x.Categories).Eager
                .Fetch(x => x.Entries).Eager
                .Where(x => x.GlobalId == championship.GlobalId).SingleOrDefault();


                if (dbChampionship.Profile != dbMe)
                {
                    throw new CrossProfileOperationException("Championship belongs to another user");
                }
                if (dbChampionship.State != ScheduleEntryState.Done)
                {
                    throw new InvalidOperationException("You can add data to championships with Done state only");
                }
                if (dbChampionship.Version != championship.Version)
                {
                    throw new StaleObjectStateException("Championship", championship.GlobalId);
                }


                dbChampionship.Results.Clear();
                Session.Flush();

                var championshipDb = championship.Map <Championship>();

                championshipDb.Profile = dbMe;
                championshipDb.Version = dbChampionship.Version;

                //first clear old result items
                //championshipDb.Results = dbChampionship.Results;
                //championshipDb.Results.Clear();


                championshipDb.Reservations = dbChampionship.Reservations;
                //check if all customers are in reservation list (there cannot be customer in Customers list and not in Reservations)
                foreach (var championshipCustomer in championshipDb.Customers)
                {
                    if (championshipDb.Reservations.Where(x => x.Customer == championshipCustomer.Customer).Count() == 0)
                    {
                        throw new ObjectNotFoundException("Customer is not available in reservations");
                    }
                }

                var benchPress = Session.Load <Exercise>(new Guid("ece5dfd7-f995-45ae-bb34-067f26c4f7b4"));
                var deadlift   = Session.Load <Exercise>(new Guid("505988e1-5663-41f1-aa1a-9b92ea584263"));
                var sqad       = Session.Load <Exercise>(new Guid("3e06a130-b811-4e45-9285-f087403615bf"));

                //calculate max for each exercise
                foreach (var entryDto in championshipDb.Entries)
                {
                    if (championshipDb.ChampionshipType == ChampionshipType.ZawodyWyciskanieSztangi)
                    {
                        if (entryDto.Exercise != benchPress)
                        {
                            throw new ConsistencyException("Wrong exercise");
                        }
                    }
                    else
                    {
                        if (entryDto.Exercise != benchPress && entryDto.Exercise != deadlift && entryDto.Exercise != sqad)
                        {
                            throw new ConsistencyException("Wrong exercise");
                        }
                    }
                    decimal max = 0;
                    if (entryDto.Try1.Result == ChampionshipTryResult.Success && max < entryDto.Try1.Weight)
                    {
                        max = entryDto.Try1.Weight;
                    }
                    if (entryDto.Try2.Result == ChampionshipTryResult.Success && max < entryDto.Try2.Weight)
                    {
                        max = entryDto.Try2.Weight;
                    }
                    if (entryDto.Try3.Result == ChampionshipTryResult.Success && max < entryDto.Try3.Weight)
                    {
                        max = entryDto.Try3.Weight;
                    }
                    entryDto.Max   = max;
                    entryDto.Wilks = calculateWilks(entryDto.Customer.Customer, entryDto.Customer.Weight, max);
                }

                //reset total and wilks. they will be calculated later
                foreach (var customer in championshipDb.Customers)
                {
                    customer.TotalWilks = 0;
                    customer.Total      = 0;
                }
                //calculate total sum
                foreach (var group in championshipDb.Entries.GroupBy(x => x.Customer))
                {
                    foreach (var entryDto in group)
                    {
                        group.Key.Total += entryDto.Max;
                    }
                    group.Key.TotalWilks = calculateWilks(group.Key.Customer, group.Key.Weight, group.Key.Total);
                }

                calculateResults(championshipDb);

                calculatePostCategories(championshipDb);

                var records = createStrengthTrainingEntries(dbMe, championshipDb, dbChampionship);
                result.NewRecords = records.Map <IList <SerieDTO> >();

                championshipDb = Session.Merge(championshipDb);

                trans.Commit();
                result.Championship = championshipDb.Map <ChampionshipDTO>();
            }
            return(result);
        }
 public IActionResult Post([FromBody] ChampionshipDTO model)
 {
     _championshipService.Insert(model);
     return(Ok());
 }
 public IActionResult Put(int id, [FromBody] ChampionshipDTO model)
 {
     model.ID = id;
     _championshipService.Update(model);
     return(Ok());
 }
 public ChampionshipHtmlExporter(ChampionshipDTO championship)
     : base(championship.Name)
 {
     this.championship = championship;
 }
示例#20
0
 public static SaveChampionshipResult SaveChampionship(ChampionshipDTO championship)
 {
     return(exceptionHandling(() => Instance.SaveChampionship(Token, championship)));
 }
示例#21
0
 public void Update(ChampionshipDTO model)
 {
     this.UpdateEntity(ChampionshipMapper.Unmapper(model));
 }
 public SaveChampionshipResult SaveChampionship(Token token, ChampionshipDTO championship)
 {
     return(exceptionHandling(token, () => InternalService.SaveChampionship(token, championship)));
 }
 public ChampionshipViewModel(ChampionshipDTO championship)
 {
     this.championship = championship;
 }