public void CreatePraise()
        {
            //ARRANGE
            var controller = GetAuthenticatedControllerMock<NotesController>(Orguser); //MockRepository.GeneratePartialMock<AccountController>();
            //set controller context. 
            controller.ControllerContext = new ControllerContext(GetContext(true), new RouteData(), controller);

            var vm = new PraiseViewModel
            {
                Comment = "Test",
                EventDate = DateTime.Now,
                SubjectUserId = Orguser.Id,

            };

            //ACT
            var result = controller.CreatePraise(vm);

            //ASSERT
            var jsonresponse = ValidateAndUnwrapJsonResult(result);
            var unwrappedresponse = (List<TimelineItem>)jsonresponse.Data; 
        }
Exemplo n.º 2
0
        /// <summary>
        /// update an existing praise
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult UpdatePraise(PraiseViewModel model)
        {
            //remove Id from modelstate if there. 
            ModelState.Remove("Id");
            ModelState.Remove("EventDate");
            ModelState.Remove("CreatedBy");
            ModelState.Remove("SubjectUserId");

            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {

                    var praise = orgSession.Load<Praise>(model.Id);

                    if (praise != null)
                    {
                        praise.EventDate = model.EventDate;
                        praise.ConsolidatedCompletionDate = model.EventDate;

                        praise.Comment = model.Comment;
                        praise.Level = model.Level;

                        orgSession.Store(praise);
                        orgSession.SaveChanges();
                        return JsonSuccess(praise.ToTimelineItems(), "Praise updated");
                    }
                    
                }
            }
            return JsonError("Invalid data");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a priase for a person
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult CreatePraise(PraiseViewModel model)
        {
            //remove Id from modelstate if tehre. 
            ModelState.Remove("Id");
            ModelState.Remove("EventDate");
            ModelState.Remove("CreatedBy");
            
            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {
                    //who is the priase for
                    var target = orgSession.Load<User>(model.SubjectUserId);

                    var praise = new Praise
                                      {
                                          CreatedBy = OrgUser.ToSimpleUser(),
                                          EventDate = DateTime.Now,
                                          ConsolidatedCompletionDate = DateTime.Now,
                                          Comment = model.Comment,
                                          SubjectUser = target.ToSimpleUser(),
                                          Level = model.Level,
                                          Id = IlluminateDatabase.GenerateId<Praise>()
                                      };

                    orgSession.Store(praise);
                    //also send the target an email letting them know
                    var notify = new Notification
                    {

                        Body =Email.GetPraiseEmailBody(target,OrgUser,model.Comment),
                        SendDate = DateTime.Now,
                        Title = string.Format("Congratulations you have been praised"),
                        From = EmailRecipient.GetIlluminateRecipient(),
                        NotificationRecipients = new[]
                                                                          {
                                                                              new NotificationRecipient
                                                                                  {

                                                                                      NotificationDeliveryTypes =
                                                                                          
                                                                                          NotificationDeliveryTypes
                                                                                              .Email ,
                                                                                      
                                                                                      Users = new List<SimpleUser>{target.ToSimpleUser()}

                                                                                  }
                                                                          },
                    };
                    orgSession.Store(notify);
                    orgSession.SaveChanges();

                    return JsonSuccess(praise.ToTimelineItems(), "Praise created");
                }
            }
            return JsonError("Invalid data");
        }