Exemple #1
0
        public void TestIsEmpty_ManyEntries_OneEntryIsEmpty_False()
        {
            TrainingDayDTO day = new TrainingDayDTO(DateTime.Now);

            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry2());
            day.AddEntry(new MyEntry3());
            Assert.IsFalse((day.IsEmpty));
        }
Exemple #2
0
        public void TestCanMove_True()
        {
            TrainingDayDTO day = new TrainingDayDTO(DateTime.Now);

            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry3());
            Assert.IsTrue(day.CanMove);
        }
Exemple #3
0
        public void TestIsEmpty_ManyEntries_AllEmpty_True()
        {
            TrainingDayDTO day = new TrainingDayDTO(DateTime.Now);

            day.AddEntry(new MyEntry2());
            day.AddEntry(new MyEntry2());
            day.AddEntry(new MyEntry2());
            Assert.IsTrue(day.IsEmpty);
        }
Exemple #4
0
        public void TestSplitByType_LoadedOnly_ExtensionMethod()
        {
            TrainingDayDTO day = new TrainingDayDTO(DateTime.Now);

            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry3());
            day.AddEntry(new MyEntry1());
            var groups = day.SplitByType(true);

            Assert.AreEqual(1, groups.Count);
            Assert.AreEqual(2, groups[typeof(MyEntry1)].Count);
        }
Exemple #5
0
        public void TestChangeDate()
        {
            DateTime       now     = DateTime.Now;
            DateTime       newDate = now.AddDays(2);
            TrainingDayDTO day     = new TrainingDayDTO(now);

            day.AddEntry(new MyEntry1());
            day.AddEntry(new MyEntry1());
            var entry3 = new MyEntry3();

            day.AddEntry(entry3);
            day.ChangeDate(newDate);
            Assert.AreEqual(newDate.Date, day.TrainingDate);
            Assert.AreEqual(newDate, entry3.NewDateTime);
        }
        public void AddAnotherEntryToTraining()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            MyTrainingDTO result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new MyTrainingOperationParam();
                param.Operation  = MyTrainingOperationType.Start;
                param.MyTraining = cycle;
                result           = service.MyTrainingOperation(data.Token, param);
            });

            TrainingDayDTO day   = new TrainingDayDTO(DateTime.UtcNow.AddDays(50));
            A6WEntryDTO    entry = new A6WEntryDTO();

            entry.Day        = A6WManager.Days[0];
            entry.MyTraining = result;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.AddDays(3).Date;
                service.SaveTrainingDay(data.Token, day);
            });
        }
        public void ForCustomer_SaveTrainingDay_UpdateSize_TwoTimes_SecondInThePast()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day     = new TrainingDayDTO(DateTime.Now.AddDays(-1));

            day.ProfileId  = profile.GlobalId;
            day.CustomerId = customers[0].GlobalId;
            SizeEntryDTO entry = new SizeEntryDTO();

            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 100;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });

            day                  = new TrainingDayDTO(DateTime.Now.AddDays(-2));
            day.ProfileId        = profile.GlobalId;
            day.CustomerId       = customers[0].GlobalId;
            entry                = new SizeEntryDTO();
            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 50;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });
            var dbCustomer = Session.Get <Customer>(customers[0].GlobalId);

            Assert.AreEqual(100, dbCustomer.Wymiary.Height);
        }
        public void CreateNewTrainingInSaveTrainingDay()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);


            TrainingDayDTO day   = new TrainingDayDTO(DateTime.UtcNow.AddDays(50));
            A6WEntryDTO    entry = new A6WEntryDTO();

            entry.Day        = A6WManager.Days[0];
            entry.MyTraining = cycle;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var result = service.SaveTrainingDay(data.Token, day);
                day        = result.TrainingDay;
            });
            var count = Session.QueryOver <MyTrainingDTO>().RowCount();

            Assert.AreEqual(0, count);
            var dbDay = Session.Get <TrainingDay>(day.GlobalId);

            Assert.IsNull(dbDay.Objects.ElementAt(0).MyTraining);
        }
Exemple #9
0
        public void AddTwoComments()
        {
            var            profile  = (ProfileDTO)profiles[0].Tag;
            var            profile1 = (ProfileDTO)profiles[1].Tag;
            SessionData    data     = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day      = new TrainingDayDTO(DateTime.Now);

            day.ProfileId = profile.GlobalId;

            BlogEntryDTO blogEntry = new BlogEntryDTO();

            blogEntry.Comment = "jakis tekst";
            day.AllowComments = true;
            day.AddEntry(blogEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });


            TrainingDayCommentDTO comment = new TrainingDayCommentDTO();

            comment.Profile = profile;
            comment.Comment = "msg";
            DateTime time = DateTime.UtcNow;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = time;
                TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();
                arg.TrainingDayId = day.GlobalId;
                arg.Comment       = comment;
                arg.OperationType = TrainingDayOperationType.Add;
                Service.TrainingDayCommentOperation(data.Token, arg);
            });
            data            = CreateNewSession(profile1, ClientInformation);
            comment         = new TrainingDayCommentDTO();
            comment.Profile = profile1;
            comment.Comment = "msg1";
            time            = DateTime.UtcNow.AddHours(2);
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = time;
                TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();
                arg.TrainingDayId = day.GlobalId;
                arg.Comment       = comment;
                arg.OperationType = TrainingDayOperationType.Add;
                Service.TrainingDayCommentOperation(data.Token, arg);
            });

            var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault();

            Assert.IsNotNull(dbDay);
            Assert.AreEqual(2, dbDay.CommentsCount);
            Assert.IsTrue(dbDay.LastCommentDate.Value.CompareDateTime(time));
        }
        public void Test_SaveTrainingDay_UpdateSize_TwoTimes()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day     = new TrainingDayDTO(DateTime.Now.AddDays(-2));

            day.ProfileId = profile.Id;
            SizeEntryDTO entry = new SizeEntryDTO();

            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 100;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });

            day                  = new TrainingDayDTO(DateTime.Now.AddDays(-1));
            day.ProfileId        = profile.Id;
            entry                = new SizeEntryDTO();
            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 50;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });
            var dbProfile = Session.Get <Profile>(profile.Id);

            Assert.AreEqual(50, dbProfile.Wymiary.Height);
        }
Exemple #11
0
        public void DeleteTrainingDay_EntryWithReminder()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.GlobalId;
            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.RemindBefore   = TimeSpan.FromMinutes(10);
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;

                Service.DeleteTrainingDay(data.Token, param);
            });

            var count = Session.QueryOver <ReminderItem>().RowCount();

            Assert.AreEqual(0, count);
        }
Exemple #12
0
        public void TestDeleteTrainingDay_RemoveAllTrainingDays()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.Id;

            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.SaveTrainingDay(data.Token, day);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                Service.DeleteTrainingDay(data.Token, day);
            });

            var dbProfile = Session.Get <Profile>(profile.Id);

            Assert.AreEqual(0, dbProfile.Statistics.TrainingDaysCount);
            Assert.AreEqual(null, dbProfile.Statistics.LastEntryDate);
            Assert.AreEqual(0, dbProfile.Statistics.SizeEntriesCount);
        }
Exemple #13
0
        public void TestDeleteTrainingDay_Mode_OnlyWithoutMyTraining_TrainingDayShouldBeDeleted()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.GlobalId;

            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;
                param.Mode          = DeleteTrainingDayMode.OnlyWithoutMyTraining;
                Service.DeleteTrainingDay(data.Token, param);
            });

            Assert.AreEqual(0, Session.QueryOver <TrainingDay>().RowCount());
            Assert.AreEqual(0, Session.QueryOver <SizeEntry>().RowCount());
        }
Exemple #14
0
        public void DeleteTrainingDay_AnotherProfile()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.GlobalId;
            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            data = CreateNewSession((ProfileDTO)profiles[1].Tag, ClientInformation);
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;

                Service.DeleteTrainingDay(data.Token, param);
            });
        }
Exemple #15
0
        public static TrainingDayPageContext CreateTrainingDayWindow(TrainingDayDTO day, UserDTO user, CustomerDTO customer, IEntryObjectBuilderProvider builder = null)
        {
            if (day.GlobalId == Constants.UnsavedGlobalId)
            {
                day.AllowComments = UserContext.Current.ProfileInformation.Settings.AllowTrainingDayComments;
                //set default entries for newly created TrainingDay
                var options = UserContext.Current.Settings.GuiState.CalendarOptions;
                foreach (var defaultEntry in options.DefaultEntries)
                {
                    if (defaultEntry.IsDefault == true)
                    {
                        var plugin = PluginsManager.Instance.GetEntryObjectProvider(defaultEntry.ModuleId);
                        if (plugin != null && plugin.EntryObjectType.CanBeManuallyAdded())
                        {
                            var entry = day.AddEntry(plugin.EntryObjectType);
                            if (builder != null)
                            {
                                builder.EntryObjectCreated(entry);
                            }
                            if (day.TrainingDate.IsFuture())
                            {//for entries in future set planned status
                                entry.Status = EntryObjectStatus.Planned;
                            }
                        }
                    }
                }
                //needed for SizeEntryDTO for example
                day.ChangeDate(day.TrainingDate);
            }
            TrainingDayPageContext context = new TrainingDayPageContext(user, customer, day, builder);

            return(context);
        }
Exemple #16
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.Wait;
            try
            {
                var menuItem  = (MenuItem)sender;
                var pairEntry = (ImageSourceListItem <Type>)menuItem.DataContext;

                EntryObjectInstanceAttribute entryAttribute = new EntryObjectInstanceAttribute();
                var attributes = pairEntry.Value.GetCustomAttributes(typeof(EntryObjectInstanceAttribute), true);
                if (attributes.Length > 0)
                {
                    entryAttribute = (EntryObjectInstanceAttribute)attributes[0];
                }
                //if this type can be only once added then we need to check if we can add it
                if (entryAttribute.Instance == EntryObjectInstance.Single)
                {
                    if (day.ContainsSpecifiedEntry(pairEntry.Value))
                    {
                        BAMessageBox.ShowError(Strings.ErrorEntryObjectTypeAlreadyExists);
                        return;
                    }
                }
                var entry = day.AddEntry(pairEntry.Value);
                if (day.TrainingDate.IsFuture())
                {//for entries in future set planned status
                    entry.Status = EntryObjectStatus.Planned;
                }
                if (EntryObjectBuilder != null)
                {
                    EntryObjectBuilder.EntryObjectCreated(entry);
                }
                try
                {
                    createNewEntryControl(entry, true, null);

                    SetModifiedFlag();
                    Cursor = Cursors.Arrow;
                }
                catch (TrainingIntegrationException ex)
                {
                    day.RemoveEntry(entry);
                    ExceptionHandler.Default.Process(ex, Strings.ErrorTrainingIntegrity, ErrorWindow.MessageBox);
                }
                catch (Exception ex)
                {
                    day.RemoveEntry(entry);
                    ExceptionHandler.Default.Process(ex, Strings.ErrorUnhandledException, ErrorWindow.EMailReport);
                }
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
Exemple #17
0
        public void TestDeleteTrainingDay_LatestNotChanged()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.GlobalId;

            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });
            date = DateTime.Now;
            var day1 = new TrainingDayDTO(DateTime.Now);

            day1.ProfileId = profile.GlobalId;

            sizeEntry                = new SizeEntryDTO();
            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day1.AddEntry(sizeEntry);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day1);
                day1   = result.TrainingDay;
            });
            var dbProfile = Session.Get <Profile>(profile.GlobalId);

            Assert.AreEqual(2, dbProfile.Statistics.TrainingDaysCount);
            Assert.AreEqual(date.Date, dbProfile.Statistics.LastEntryDate.Value);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;

                Service.DeleteTrainingDay(data.Token, param);;
            });

            dbProfile = Session.Get <Profile>(profile.GlobalId);
            Assert.AreEqual(1, dbProfile.Statistics.TrainingDaysCount);
            Assert.AreEqual(date.Date, dbProfile.Statistics.LastEntryDate.Value);
        }
Exemple #18
0
        public void AddComment_SetLoginData()
        {
            var            profile  = (ProfileDTO)profiles[0].Tag;
            var            profile1 = (ProfileDTO)profiles[1].Tag;
            SessionData    data     = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day      = new TrainingDayDTO(DateTime.Now);

            day.ProfileId = profile.GlobalId;

            BlogEntryDTO blogEntry = new BlogEntryDTO();

            blogEntry.Comment = "jakis tekst";
            day.AllowComments = true;
            day.AddEntry(blogEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            LoginData loginData = new LoginData();

            loginData.ApiKey              = apiKey;
            loginData.ApplicationVersion  = "1.0.0";
            loginData.LoginDateTime       = DateTime.UtcNow;
            loginData.ApplicationLanguage = "en";
            loginData.PlatformVersion     = "NUnit";
            insertToDatabase(loginData);

            data = CreateNewSession(profile1, ClientInformation, loginData);
            TrainingDayCommentDTO comment = new TrainingDayCommentDTO();

            comment.Profile = profile1;
            comment.Comment = "msg";
            DateTime time = DateTime.UtcNow;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = time;
                TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();
                arg.TrainingDayId = day.GlobalId;
                arg.Comment       = comment;
                arg.OperationType = TrainingDayOperationType.Add;
                Service.TrainingDayCommentOperation(data.Token, arg);
            });

            var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault();

            Assert.AreEqual(loginData.ApiKey.ApiKey, dbDay.Comments.First().LoginData.ApiKey.ApiKey);
        }
Exemple #19
0
        public void AddComment_SendEMailAndMessage()
        {
            var profile  = (ProfileDTO)profiles[0].Tag;
            var profile1 = (ProfileDTO)profiles[1].Tag;

            profiles[0].Settings.NotificationBlogCommentAdded = ProfileNotification.Message | ProfileNotification.Email;
            insertToDatabase(profiles[0]);

            SessionData    data = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day  = new TrainingDayDTO(DateTime.Now);

            day.ProfileId = profile.GlobalId;

            BlogEntryDTO blogEntry = new BlogEntryDTO();

            blogEntry.Comment = "jakis tekst";
            day.AllowComments = true;
            day.AddEntry(blogEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            data = CreateNewSession(profile1, ClientInformation);
            TrainingDayCommentDTO comment = new TrainingDayCommentDTO();

            comment.Profile = profile1;
            comment.Comment = "msg";
            DateTime time = DateTime.UtcNow;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = time;
                TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();
                arg.TrainingDayId = day.GlobalId;
                arg.Comment       = comment;
                arg.OperationType = TrainingDayOperationType.Add;
                Service.TrainingDayCommentOperation(data.Token, arg);
                Assert.True(((MockEmailService)Service.EMailService).EMailSent);
            });

            var messages = Session.QueryOver <Message>().Where(x => x.Receiver == profiles[0]).SingleOrDefault();

            Assert.IsNotNull(messages);
            Assert.IsNotNull(messages.Content);
            Assert.AreEqual(MessagePriority.System, messages.Priority);
        }
Exemple #20
0
        private void tsStrengthTraining_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                ToolStripDropDownItem     menuItem  = (ToolStripDropDownItem)sender;
                KeyValuePair <Type, Type> pairEntry = (KeyValuePair <Type, Type>)menuItem.Tag;

                EntryObjectInstanceAttribute entryAttribute = new EntryObjectInstanceAttribute();
                var attributes = pairEntry.Key.GetCustomAttributes(typeof(EntryObjectInstanceAttribute), true);
                if (attributes.Length > 0)
                {
                    entryAttribute = (EntryObjectInstanceAttribute)attributes[0];
                }
                //if this type can be only once added then we need to check if we can add it
                if (entryAttribute.Instance == EntryObjectInstance.Single)
                {
                    if (day.ContainsSpecifiedEntry(pairEntry.Key))
                    {
                        FMMessageBox.ShowError(ApplicationStrings.ErrorEntryObjectTypeAlreadyExists);
                        return;
                    }
                }
                var entry = day.CreateEntryObject(pairEntry.Key);

                try
                {
                    createNewEntryControl(entry, true);

                    day.AddEntry(entry);
                    Cursor = Cursors.Default;
                }
                catch (TrainingIntegrationException ex)
                {
                    ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorTrainingIntegrity, ErrorWindow.MessageBox);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorUnhandledException, ErrorWindow.EMailReport);
                }
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Exemple #21
0
        public void AddComment_AnotherProfile()
        {
            var            profile  = (ProfileDTO)profiles[0].Tag;
            var            profile1 = (ProfileDTO)profiles[1].Tag;
            SessionData    data     = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day      = new TrainingDayDTO(DateTime.Now);

            day.ProfileId = profile.GlobalId;

            BlogEntryDTO blogEntry = new BlogEntryDTO();

            blogEntry.Comment = "jakis tekst";
            day.AllowComments = true;
            day.AddEntry(blogEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            data = CreateNewSession(profile1, ClientInformation);
            TrainingDayCommentDTO comment = new TrainingDayCommentDTO();

            comment.Profile = profile;
            comment.Comment = "msg";
            DateTime time = DateTime.UtcNow;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = time;
                TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();
                arg.TrainingDayId = day.GlobalId;
                arg.Comment       = comment;
                arg.OperationType = TrainingDayOperationType.Add;
                Service.TrainingDayCommentOperation(data.Token, arg);
            });
        }
        public void Test_DeleteTrainingDay_UpdateSize()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day     = new TrainingDayDTO(DateTime.Now.AddDays(-2));

            day.ProfileId = profile.GlobalId;
            SizeEntryDTO entry = new SizeEntryDTO();

            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 100;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });

            day                  = new TrainingDayDTO(DateTime.Now.AddDays(-1));
            day.ProfileId        = profile.GlobalId;
            entry                = new SizeEntryDTO();
            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 50;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                day = service.SaveTrainingDay(data.Token, day).TrainingDay;
            });

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;

                service.DeleteTrainingDay(data.Token, param);
            });

            var dbProfile = Session.Get <Profile>(profile.GlobalId);

            Assert.AreEqual(100, dbProfile.Wymiary.Height);
        }
Exemple #23
0
        public void TestDeleteTrainingDay_DataInfo_Refresh()
        {
            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = CreateNewSession(profile, ClientInformation);
            DateTime       date    = DateTime.Now.AddDays(-2);
            TrainingDayDTO day     = new TrainingDayDTO(date);

            day.ProfileId = profile.GlobalId;

            SizeEntryDTO sizeEntry = new SizeEntryDTO();

            sizeEntry.Wymiary        = new WymiaryDTO();
            sizeEntry.Wymiary.Height = 100;
            day.AddEntry(sizeEntry);

            SaveTrainingDayResult result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.SaveTrainingDay(data.Token, day);
                day    = result.TrainingDay;
            });

            var dbProfile = Session.Get <Profile>(profile.GlobalId);
            var oldHash   = dbProfile.DataInfo.TrainingDayHash;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                TimerService.UtcNow = DateTime.UtcNow.AddHours(1);
                var param           = new DeleteTrainingDayParam();
                param.TrainingDayId = day.GlobalId;

                Service.DeleteTrainingDay(data.Token, param);
            });

            dbProfile = Session.Get <Profile>(profile.GlobalId);
            Assert.AreNotEqual(oldHash, dbProfile.DataInfo.TrainingDayHash);
        }
        public void Test_SaveTrainingDay_AutomaticUpdateDisable()
        {
            profiles[0].Settings.AutomaticUpdateMeasurements = false;
            insertToDatabase(profiles[0]);

            var            profile = (ProfileDTO)profiles[0].Tag;
            SessionData    data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            TrainingDayDTO day     = new TrainingDayDTO(DateTime.Now);

            day.ProfileId = profile.Id;
            SizeEntryDTO entry = new SizeEntryDTO();

            entry.Wymiary        = new WymiaryDTO();
            entry.Wymiary.Height = 100;
            day.AddEntry(entry);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveTrainingDay(data.Token, day);
            });
            var dbProfile = Session.Get <Profile>(profile.Id);

            Assert.IsNull(dbProfile.Wymiary);
        }
        private void openTrainingDay(DateTime selectedDate)
        {
            AddTrainingDay dlg = new AddTrainingDay();

            if (!isFilled || UserContext.LoginStatus != LoginStatus.Logged || IsSelectedDateFuture)
            {
                return;
            }

            var day  = new TrainingDayDTO(selectedDate, UserContext.CurrentProfile.Id);
            var info = monthCalendar1.GetDateInfo(selectedDate);

            if (info.Length > 0)
            {
                day = (TrainingDayDTO)info[0].Tag;
            }
            else if (ReadOnly)
            {
                return;
            }

            if (day.Id == Constants.UnsavedObjectId)
            {
                //set default entries for newly created TrainingDay
                var options = UserContext.Settings.GuiState.CalendarOptions;
                foreach (var defaultEntry in options.DefaultEntries)
                {
                    if (defaultEntry.Value)
                    {
                        var plugin = PluginsManager.Instance.GetEntryObjectProvider(defaultEntry.Key);
                        if (plugin != null)
                        {
                            day.AddEntry(plugin.EntryObjectType);
                        }
                    }
                }
                //needed for SizeEntryDTO for example
                day.ChangeDate(selectedDate);
            }
            dlg.Fill(day, User);
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    //save day only when we didn't press Delete button (deleting is performed directly in usrAddTrainingDay control)
                    if (dlg.DayRemoved)
                    {
                        monthCalendar1.RemoveDateInfo(dlg.CurrentDay.TrainingDate);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorRemoveTrainingDay, ErrorWindow.EMailReport);
                    return;
                }
            }
            //day = ServiceManager.Instance.SaveTrainingDay(UserContext.Token, day);
            if (dlg.FillRequired)
            {
                Fill(User, day.TrainingDate);
            }
        }