/// <summary> /// Gets the details of a particular event based on its id /// </summary> /// <param name="eventId">the id of the event to get the details of</param> /// <returns>Event Details View</returns> public ActionResult EventDetails(int eventId) { EventModel model = new EventModel(); model.UserLoginName = claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity); GetEventByEventId eventQuery = new GetEventByEventId(eventId); model.Event = commandBus.ProcessQuery(eventQuery); GetEventPostPictures pictureQuery = new GetEventPostPictures(eventId); model.Pictures = commandBus.ProcessQuery(pictureQuery); GetTicketClaimsByEventIdQuery ticketClaimQuery = new GetTicketClaimsByEventIdQuery(eventId); model.TicketClaims = commandBus.ProcessQuery(ticketClaimQuery); SelectUserQuery userQuery = new SelectUserQuery(new CurrentUser { LoginName = claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity) }); model.OrgChartUser = commandBus.ProcessQuery(userQuery); return(View(ViewNames.EventDetails, model)); }
/// <summary> /// Inserts the winners into the ticket winner table and sends them an email. /// </summary> /// <param name="winners">a comma separated string of the usernames of ticket winners</param> /// <param name="eventId">the id of the event we are giving away tickets for</param> public void SubmitWinners(string winners, int eventId, string eventName) { SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity))); CurrentUser user = commandBus.ProcessQuery(currentUser); InsertTicketWinnerCommand insertWinner = new InsertTicketWinnerCommand(winners, eventId, user.LoginName); commandBus.Execute(insertWinner); //Query for the email template GetEmailTemplateQuery query = new GetEmailTemplateQuery(new EmailTemplate(Enumeration.TryFindById <EmailTemplateEnum>(4).DisplayValue)); EmailTemplate winnerEmail = commandBus.ProcessQuery(query); winnerEmail.EmailBody = winnerEmail.EmailBody.Replace("@@EventName@@", eventName); winnerEmail.EmailSubject = winnerEmail.EmailSubject.Replace("@@EventName@@", eventName); List <string> winnerList = winners.Split(',').ToList(); if (winnerList != null && winnerList.Any()) { foreach (string winner in winnerList) { SelectUserQuery winnerInformationQuery = new SelectUserQuery(new CurrentUser(winner)); CurrentUser winnerInformation = commandBus.ProcessQuery(winnerInformationQuery); SendEmailCommand emailCommand = new SendEmailCommand(new Email( Me2YouConstants.EmailProfile, winnerInformation.EmailAddress, winnerEmail.EmailSubject, winnerEmail.EmailBody)); commandBus.Execute(emailCommand); } } }
/// <summary> /// Deletes a post /// </summary> /// <param name="postId">the id of the post to delete</param> /// <returns>true/false, true if successfully deleted, false otherwise</returns> public JsonResult DeletePost(int postId) { //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); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus == Convert.ToInt32(PostStatusEnum.Delivered.Id) || newPost.PostStatus == Convert.ToInt32(PostStatusEnum.PendingDelivery.Id)) { return(Json("false", JsonRequestBehavior.AllowGet)); } RemovePostCommand command = new RemovePostCommand(new Post(postId), user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Adds a team memeber's name to the list of ticket claims for a particular event /// </summary> /// <param name="loginName">the loginname of the individual who has raised their hand</param> /// <param name="eventName">the name of the event</param> /// <param name="eventId">the id of the event that the individual is interested in</param> public void InterestedInEvent(string loginName, string eventName, int eventId) { SelectUserQuery userQuery = new SelectUserQuery(new CurrentUser() { LoginName = loginName }); CurrentUser user = commandBus.ProcessQuery(userQuery); TicketClaims claim = new TicketClaims( ticketClaimsId: 0, eventName: eventName, eventId: eventId, firstName: user.FirstName, lastName: user.LastName, eMailAddress: user.EmailAddress, userName: loginName); InsertTicketClaim command = new InsertTicketClaim(claim); commandBus.Execute(command); }
/// <summary> /// Changes the status of a post to active. /// </summary> /// <param name="postId">the id of the post to set to active status</param> /// <returns>fase if it is trying to change the status on a post that is not allowed, true if everything works ok</returns> public JsonResult RepostItem(int postId, DateTime expirationDate) { ClaimsIdentity id = (ClaimsIdentity)User.Identity; //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(id.Claims.ElementAt(0).Value)); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus == 1 || newPost.PostStatus == 3 || newPost.PostStatus == 5) { return(Json("false", JsonRequestBehavior.AllowGet)); } UpdatePostToActiveCommand command = new UpdatePostToActiveCommand(postId, expirationDate, user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Marks a post as deliverd by changing its status /// </summary> /// <param name="postId">the id of the post to change the status of</param> /// <returns>true / false, true if the status is successfully changed, false if not.</returns> public JsonResult MarkPostAsDelivered(int postId) { ClaimsIdentity id = (ClaimsIdentity)User.Identity; //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(id.Claims.ElementAt(0).Value)); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus != 2) { return(Json("false", JsonRequestBehavior.AllowGet)); } UpdatePostToDeliveredCommand command = new UpdatePostToDeliveredCommand(new Post(postId), user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
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)); } }