public ActionResult SendPartnershipRequest(int partnershipID, string message, string returnUrl) { var partnership = _workUnit.PartnershipRepository.GetEntityByID(partnershipID); var ownerProfiles = partnership.getOwners(); if (ownerProfiles == null) { updateTempMessage("Can not send request to this partnership! Please choose a different partnership."); return(RedirectToAction("View", "Partnership", new { partnershipID, returnUrl })); } //only send if partnership is valid if (partnership != null) { ownerProfiles.ToList().ForEach(x => { x.Accounts.ToList().ForEach(a => { //create notification var notification = new Notification() { Category = "Request Received", Message = string.Format("{0} has requested to join your \"{1}\" partnership", CurrentAccount.Profile.Organization.Name, partnership.Name), Account = a, Message2 = @"You will be able to choose whether to accept this request, and/or view this user’s Organizational Profile for more information.", LinkToAction = Url.Action("Requests", "Communication") }; _workUnit.NotificationRepository.InsertEntity(notification); }); //create request var request = new PartnershipRequest() { Type = "Partnership Request", PartnershipID = partnershipID, Message = message, Sender = CurrentAccount.Profile, Receiver = x }; _workUnit.RequestRepository.InsertEntity(request); }); _workUnit.saveChanges(); updateTempMessage("Your request has been sent to the admin of this partnership"); return(RedirectToAction("View", "Partnership", new { partnershipID, returnUrl })); } //error updateTempMessage("Error sending join request."); return(RedirectToAction("View", "Partnership", new { partnershipID, returnUrl }));; }
public ActionResult InviteToPartnership(int profileID, int partnershipID, string message, string returnUrl) { var profile = _workUnit.ProfileRepository.GetEntityByID(profileID); ViewBag.returnUrl = returnUrl; var sender = CurrentAccount.Profile; var receiver = profile;//send to all accounts var partnership = _workUnit.PartnershipRepository.GetEntityByID(partnershipID); message = message ?? "You have been invited to join our partnership"; if (partnership != null) { receiver.Accounts.ToList().ForEach(x => { var notification = new Notification() { Category = "Invite Recieved", Message = string.Format("You have been invited to join the \"{0}\" partnership", partnership.Name), Account = x, LinkToAction = Url.Action("Requests", "Communication") }; _workUnit.NotificationRepository.InsertEntity(notification); }); //create request var request = new PartnershipRequest() { Type = "Partnership Invite", PartnershipID = partnershipID, Message = message, Sender = sender, Receiver = receiver }; _workUnit.RequestRepository.InsertEntity(request); _workUnit.saveChanges(); updateTempMessage("Invitation has been sent"); } else { updateTempMessage("Error sending the invite."); } return(View(profile)); }
public ActionResult AcceptRequest(int requestID) { var request = _workUnit.RequestRepository.GetEntityByID(requestID); PartnershipRequest r = null; Notification notification = null; PartnershipDetail detail = null; switch (request.Type.ToLower()) { case "partnership request": r = (PartnershipRequest)request; if (r.Partnership != null) { //check if the requested organization is already a partner if (r.Partnership.getPartners().Contains(r.Sender)) { updateTempMessage("\"" + r.Sender.Organization.Name + "\"is already a partner of this partnership"); _workUnit.RequestRepository.DeleteByID(requestID); break; } //form a partner reference detail = new PartnershipDetail() { Partnership = r.Partnership, Profile = r.Sender, Type = "partner" }; var message = string.Format(@"You have accepted {0} to join the ""{1}"" partnership.", r.Sender.Organization.Name, r.Partnership.Name); updateTempMessage(message); r.Sender.Accounts.ToList().ForEach(x => { //create notification to sender notification = new Notification() { Account = x, Category = "Partnership Request Accepted", Message = string.Format(@"{0} has accepted your request. You are now a partner of ""{1}""", r.Receiver.Organization.Name, r.Partnership.Name), Message2 = "You can now visit the \"" + r.Partnership.Name + "\" partnership’s partnership, and communicate with your partners!", LinkToAction = Url.Action("Detail", "Partnership", new { r.PartnershipID }) }; _workUnit.NotificationRepository.InsertEntity(notification); }); } break; case "partnership invite": r = (PartnershipRequest)request; if (r.Partnership != null) { //check if the invited organization is already a partner if (r.Partnership.getPartners().Contains(r.Receiver)) { updateTempMessage("You are already a partner of this partnership"); break; } //form a partner reference detail = new PartnershipDetail() { Partnership = r.Partnership, Profile = r.Receiver, Type = "partner" }; _workUnit.PartnershipDetailRepository.InsertEntity(detail); var message = "You are now a partner of the \"" + r.Partnership.Name + "\" partnership."; updateTempMessage(message); r.Sender.Accounts.ToList().ForEach(x => { //create notification notification = new Notification() { Account = x, Category = "Partnership Invite Accepted", Message = string.Format(@"{0} is now a new partner of your ""{1}"" partnership", r.Receiver.Organization.Name, r.Partnership.Name), LinkToAction = Url.Action("Detail", "Partnership", new { r.PartnershipID }) }; _workUnit.NotificationRepository.InsertEntity(notification); }); } break; } if (detail != null) { _workUnit.PartnershipDetailRepository.InsertEntity(detail); _workUnit.RequestRepository.DeleteByID(requestID); } _workUnit.saveChanges(); return(RedirectToAction("Requests")); }