Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public TrainingDayCommentDTO TrainingDayCommentOperation(Token token, TrainingDayCommentOperationParam arg)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new VoteService(Session, securityInfo, Configuration, PushNotificationService, EMailService);

            return(service.TrainingDayCommentOperation(arg));
        }
Ejemplo n.º 3
0
 public static TrainingDayCommentDTO TrainingDayCommentOperation(TrainingDayCommentOperationParam arg)
 {
     return(exceptionHandling(delegate
     {
         return Instance.TrainingDayCommentOperation(Token, arg);
     }));
 }
Ejemplo n.º 4
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam();

            arg.TrainingDayId   = day.GlobalId;
            arg.Comment         = new TrainingDayCommentDTO();
            arg.Comment.Comment = txtComment.Text;
            arg.Comment.Profile = UserContext.Current.CurrentProfile;

            ParentWindow.RunAsynchronousOperation(delegate
            {
                try
                {
                    ServiceManager.TrainingDayCommentOperation(arg);
                }
                catch (InvalidOperationException ex)
                {
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrSendComment_MustSaveDayFirst".TranslateStrings(), ErrorWindow.MessageBox), Dispatcher);
                    return;
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    if (day != null && !day.IsNew)
                    {
                        blogCommentsList1.Fill(day);
                    }
                    txtComment.Text = string.Empty;
                }));
            }, asyncOperationStateChange);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtComment.Text == string.Empty)
            {
                return;
            }
            this.Focus();
            progressBar.ShowProgress(true, ApplicationStrings.BlogPage_ProgressSavingComment);
            var m = new ServiceManager <TrainingDayCommentOperationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <TrainingDayCommentOperationCompletedEventArgs> operationCompleted)
            {
                TrainingDayCommentOperationParam operation = new TrainingDayCommentOperationParam();
                operation.OperationType = TrainingDayOperationType.Add;
                var dto                 = new TrainingDayCommentDTO();
                dto.Comment             = txtComment.Text;
                dto.Profile             = ApplicationState.Current.SessionData.Profile;
                operation.Comment       = dto;
                operation.TrainingDayId = viewModel.Day.GlobalId;
                client1.TrainingDayCommentOperationAsync(ApplicationState.Current.SessionData.Token, operation);
                client1.TrainingDayCommentOperationCompleted -= operationCompleted;
                client1.TrainingDayCommentOperationCompleted += operationCompleted;
            });

            m.OperationCompleted += (s1, a1) =>
            {
                FaultException <BAServiceException> serviceEx = a1.Error as FaultException <BAServiceException>;
                if (serviceEx != null && serviceEx.Detail.ErrorCode == ErrorCode.InvalidOperationException)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrCommentsAreDisabled);
                    return;
                }
                else if (a1.Error != null)
                {
                    progressBar.ShowProgress(false);
                    BAMessageBox.ShowError(ApplicationStrings.BlogPage_ErrSavingComment);
                    return;
                }
                else
                {
                    txtComment.Text = string.Empty;
                    progressBar.ShowProgress(true, ApplicationStrings.BlogPage_ProgressRetrieveComments);
                    viewModel.LoadComments();
                }
            };

            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
                return;
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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 TrainingDayCommentDTO TrainingDayCommentOperation(Token token, TrainingDayCommentOperationParam arg)
 {
     return(exceptionHandling(token, () => InternalService.TrainingDayCommentOperation(token, arg)));
 }
Ejemplo n.º 10
0
        public TrainingDayCommentDTO TrainingDayCommentOperation(TrainingDayCommentOperationParam arg)
        {
            Log.WriteWarning("TrainingDayCommentOperationParam:Username={0},operation: {1},TrainingDayId={2}", SecurityInfo.SessionData.Profile.UserName, arg.OperationType, arg.TrainingDayId);

            if (SecurityInfo.SessionData.Profile.GlobalId != arg.Comment.Profile.GlobalId)
            {
                throw new CrossProfileOperationException("Cannot add comment for another user");
            }
            var session = Session;

            if (string.IsNullOrWhiteSpace(arg.Comment.Comment))
            {
                throw new ArgumentNullException("Comment cannot be empty");
            }
            var dbComment = Mapper.Map <TrainingDayCommentDTO, TrainingDayComment>(arg.Comment);

            using (var tx = session.BeginSaveTransaction())
            {
                var trainingDay = session.Get <TrainingDay>(arg.TrainingDayId);
                var dbProfile   = session.Get <Profile>(arg.Comment.Profile.GlobalId);
                if (trainingDay == null)
                {
                    throw new Shared.ObjectNotFoundException("Training Day doesn't exist");
                }
                if (!trainingDay.AllowComments)
                {
                    throw new InvalidOperationException("Comments are disabled for this training day");
                }

                if (arg.OperationType == TrainingDayOperationType.Add)
                {
                    if (!dbComment.IsNew)
                    {
                        throw new InvalidOperationException("Cannot add again existing comment");
                    }

                    dbComment.DateTime    = Configuration.TimerService.UtcNow;
                    dbComment.TrainingDay = trainingDay;
                    dbComment.Profile     = dbProfile;
                    dbComment.LoginData   = SecurityInfo.LoginData;
                    session.SaveOrUpdate(dbComment);

                    trainingDay.LastCommentDate = dbComment.DateTime;
                    session.SaveOrUpdate(trainingDay);
                }
                ProfileStatisticsUpdater.UpdateBlogComments(session, dbProfile);
                ProfileStatisticsUpdater.UpdateMyBlogComments(session, trainingDay);


                try
                {
                    //send message only when someone else add comment (when blog autor add the comment we don't need to send the message)
                    if (trainingDay.Profile != dbProfile)
                    {
                        //if ((trainingDay.Profile.Settings.NotificationBlogCommentAdded & ProfileNotification.Message) == ProfileNotification.Message)
                        //{
                        //    string param = string.Format("{0},{1},{2}", trainingDay.TrainingDate.ToShortDateString(), dbProfile.UserName, dbComment.DateTime);
                        //    MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification);
                        //    messageService.SendSystemMessage(param, dbProfile, trainingDay.Profile, MessageType.TrainingDayCommentAdded);
                        //}
                        //if ((trainingDay.Profile.Settings.NotificationBlogCommentAdded & ProfileNotification.Email) == ProfileNotification.Email)
                        //{
                        //    emailService.SendEMail(trainingDay.Profile, "AddTrainingDayCommentEMailSubject", "AddTrainingDayCommentEMailMessage", DateTime.Now, dbProfile.UserName, trainingDay.TrainingDate, arg.Comment);
                        //}
                        //string messageFormat = string.Format("{0},{1},{2}", trainingDay.TrainingDate.ToShortDateString(), dbProfile.UserName, dbComment.DateTime);
                        //SendMessage(trainingDay.Profile.Settings.NotificationBlogCommentAdded, dbProfile, trainingDay.Profile, messageFormat, MessageType.TrainingDayCommentAdded, "AddTrainingDayCommentEMailSubject", "AddTrainingDayCommentEMailMessage", DateTime.Now, dbProfile.UserName, trainingDay.TrainingDate, arg.Comment);
                        NewSendMessageEx(trainingDay.Profile.Settings.NotificationBlogCommentAdded, dbProfile, trainingDay.Profile, "AddTrainingDayCommentEMailSubject", "AddTrainingDayCommentEMailMessage", DateTime.Now, dbProfile.UserName, trainingDay.TrainingDate.ToShortDateString(), arg.Comment.Comment);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Default.Process(ex);
                }
                tx.Commit();
                return(Mapper.Map <TrainingDayComment, TrainingDayCommentDTO>(dbComment));
            }
        }