/// <summary>
 /// Handler for the InsertPostClaimCommand command
 /// </summary>
 /// <param name="command">the InsertPostClaim Command</param>
 public void HandleCommand(InsertPostClaimCommand command)
 {
     postRepository.InsertPostClaim(command.PostClaim);
 }
Beispiel #2
0
        public JsonResult ClaimItem(int postId, string postedBy, string postTitle, string postEmail, string postPurpose)
        {
            String[] jsonResult = new String[2];

            //Queries for the current user and their email address. - Chris
            SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity)));
            CurrentUser     user        = commandBus.ProcessQuery(currentUser);

            SelectAllPostClaimsByUserWithinThirtyDaysQuery postQuery =
                new SelectAllPostClaimsByUserWithinThirtyDaysQuery(user.LoginName);
            List <PostClaim> returnedClaims = commandBus.ProcessQuery(postQuery);

            if (returnedClaims.Count >= 2 && postPurpose == PostPurposeEnum.ItemPost.Id)
            {
                jsonResult[0] = "False";
                jsonResult[1] = returnedClaims.OrderBy(x => x.DateClaimed).Select(x => x.DateClaimed).FirstOrDefault().AddDays(30).ToString("D");
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
            else
            {
                InsertPostClaimCommand command =
                    new InsertPostClaimCommand(
                        new PostClaim(postId, claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity), user.EmailAddress, DateTime.Now));
                commandBus.Execute(command);

                if (postPurpose == PostPurposeEnum.ItemPost.Id)
                {
                    //Query for the email template
                    GetEmailTemplateQuery query        = new GetEmailTemplateQuery(new EmailTemplate(Enumeration.TryFindById <EmailTemplateEnum>(1).DisplayValue));
                    EmailTemplate         ClaimedEmail = commandBus.ProcessQuery(query);

                    //Replace the email body/subject with the correct parameters
                    ClaimedEmail.EmailBody    = ClaimedEmail.EmailBody.Replace("@@PostOwner@@", postedBy);
                    ClaimedEmail.EmailBody    = ClaimedEmail.EmailBody.Replace("@@FullName@@", user.FullName);
                    ClaimedEmail.EmailBody    = ClaimedEmail.EmailBody.Replace("@@PostTitle@@", postTitle);
                    ClaimedEmail.EmailSubject = ClaimedEmail.EmailSubject.Replace("@@PostTitle@@", postTitle);

                    SendEmailCommand emailCommand = new SendEmailCommand(new Email(
                                                                             Me2YouConstants.EmailProfile,
                                                                             postEmail,
                                                                             ClaimedEmail.EmailSubject,
                                                                             ClaimedEmail.EmailBody));
                    commandBus.Execute(emailCommand);

                    //Query for the email template
                    GetEmailTemplateQuery claimerEmailQuery = new GetEmailTemplateQuery(new EmailTemplate(Enumeration.TryFindById <EmailTemplateEnum>(2).DisplayValue));
                    EmailTemplate         ClaimerEmail      = commandBus.ProcessQuery(claimerEmailQuery);

                    //Replace the email body/subject with the correct parameters
                    ClaimerEmail.EmailBody    = ClaimerEmail.EmailBody.Replace("@@PostOwner@@", postedBy);
                    ClaimerEmail.EmailBody    = ClaimerEmail.EmailBody.Replace("@@PostTitle@@", postTitle);
                    ClaimerEmail.EmailSubject = ClaimerEmail.EmailSubject.Replace("@@PostTitle@@", postTitle);

                    SendEmailCommand claimerEmailCommand = new SendEmailCommand(new Email(
                                                                                    Me2YouConstants.EmailProfile,
                                                                                    user.EmailAddress,
                                                                                    ClaimerEmail.EmailSubject,
                                                                                    ClaimerEmail.EmailBody));
                    commandBus.Execute(claimerEmailCommand);
                }
                else if (postPurpose == PostPurposeEnum.ItemRequest.Id)
                {
                    //Query for the email template
                    GetEmailTemplateQuery postedItemRequestEmailQuery = new GetEmailTemplateQuery(new EmailTemplate(Enumeration.TryFindById <EmailTemplateEnum>(5).DisplayValue));
                    EmailTemplate         postedItemRequestEmail      = commandBus.ProcessQuery(postedItemRequestEmailQuery);

                    postedItemRequestEmail.EmailBody    = postedItemRequestEmail.EmailBody.Replace("@@PosterName@@", postedBy);
                    postedItemRequestEmail.EmailBody    = postedItemRequestEmail.EmailBody.Replace("@@ClaimerName@@", user.FullName);
                    postedItemRequestEmail.EmailSubject = postedItemRequestEmail.EmailSubject.Replace("@@ItemTitle@@", postTitle);

                    SendEmailCommand postedItemRequestEmailCommand = new SendEmailCommand(new Email(
                                                                                              Me2YouConstants.EmailProfile,
                                                                                              postEmail,
                                                                                              postedItemRequestEmail.EmailSubject,
                                                                                              postedItemRequestEmail.EmailBody));
                    commandBus.Execute(postedItemRequestEmailCommand);

                    //Query for the email template
                    GetEmailTemplateQuery claimedItemRequestEmailQuery = new GetEmailTemplateQuery(new EmailTemplate(Enumeration.TryFindById <EmailTemplateEnum>(6).DisplayValue));
                    EmailTemplate         claimedItemRequestEmail      = commandBus.ProcessQuery(claimedItemRequestEmailQuery);

                    claimedItemRequestEmail.EmailBody    = claimedItemRequestEmail.EmailBody.Replace("@@PosterName@@", postedBy);
                    claimedItemRequestEmail.EmailSubject = claimedItemRequestEmail.EmailSubject.Replace("@@ItemTitle@@", postTitle);

                    SendEmailCommand claimedItemRequestEmailCommand = new SendEmailCommand(new Email(
                                                                                               Me2YouConstants.EmailProfile,
                                                                                               user.EmailAddress,
                                                                                               claimedItemRequestEmail.EmailSubject,
                                                                                               claimedItemRequestEmail.EmailBody));
                    commandBus.Execute(claimedItemRequestEmailCommand);
                }
                jsonResult[0] = "True";
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
        }