Esempio n. 1
0
        public MailObject WriteToMailObject(MailObject message)
        {
            var contactSettings = Engine.Settings.Contact;

            message.PreHeader = NotificationTitle.IsSet() ? NotificationTitle.ReplaceSiteVariables() : contactSettings.Title.ReplaceSiteVariables();
            message.Subject   = NotificationSubject.IsSet() ? NotificationSubject.ReplaceSiteVariables() : contactSettings.Subject.ReplaceSiteVariables();
            message.AddParagraph(NotificationMessage.IsSet() ? NotificationMessage.ReplaceSiteVariables() : contactSettings.Message.ReplaceSiteVariables());
            message.AddParagraph("Name: <strong>" + Name + "</strong>");
            message.AddParagraph("Email: <strong>" + Email + "</strong>");
            message.AddParagraph("Phone: <strong>" + PhoneNumber + "</strong>");
            message.AddParagraph("Subject: <strong>" + Subject + "</strong>");
            message.AddParagraph("Enquiry:");
            message.AddParagraph("<strong>" + Enquiry + "</strong>");
            return(message);
        }
Esempio n. 2
0
 public NotificationSubject Add(NotificationSubject pt)
 {
     _unitOfWork.Repository <NotificationSubject>().Insert(pt);
     return(pt);
 }
Esempio n. 3
0
 public void Update(NotificationSubject pt)
 {
     pt.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <NotificationSubject>().Update(pt);
 }
Esempio n. 4
0
 public void Delete(NotificationSubject pt)
 {
     _unitOfWork.Repository <NotificationSubject>().Delete(pt);
 }
Esempio n. 5
0
 public NotificationSubject Create(NotificationSubject pt)
 {
     pt.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <NotificationSubject>().Insert(pt);
     return(pt);
 }
Esempio n. 6
0
        public async Task <string> SendNotificationAsync(string receiverId, string senderId, string tripId, NotificationSubject subject)
        {
            var receiver = await this.usersService.GetByIdAsync(receiverId);

            var sender = await this.usersService.GetByIdAsync(senderId);

            var trip = await this.tripsService.GetByIdAsync(tripId);

            if (receiver == null || sender == null || trip == null)
            {
                return(null);
            }

            var userTripExists = await this.tripsService.CheckForUserTripAsync(receiver.Id, tripId);

            if ((subject == NotificationSubject.RequestJoin || subject == NotificationSubject.AcceptRequest) &&
                trip.FreeSeats == 0 &&
                !userTripExists)
            {
                return(null);
            }

            var receiverMessage = string.Empty;
            var senderMessage   = string.Empty;

            switch (subject)
            {
            case NotificationSubject.RequestJoin:
                receiverMessage = $"{sender.FirstName} {sender.LastName} wants to join your trip.";
                senderMessage   = $"You made request to join {receiver.FirstName} {receiver.LastName}'s trip.";
                break;

            case NotificationSubject.CancelJoin:
                receiverMessage = $"{sender.FirstName} {sender.LastName} cancelled their trip request.";
                senderMessage   = $"You cancelled your request for {receiver.FirstName} {receiver.LastName}'s trip.";
                break;

            case NotificationSubject.AcceptRequest:
                receiverMessage = $"{sender.FirstName} {sender.LastName} accepted your trip request.";
                senderMessage   = $"You accepted {receiver.FirstName} {receiver.LastName}'s trip request.";
                break;

            case NotificationSubject.RejectRequest:
                receiverMessage = $"{sender.FirstName} {sender.LastName} rejected your trip request.";
                senderMessage   = $"You rejected {receiver.FirstName} {receiver.LastName}'s trip request.";
                break;
            }

            var notification = new Notification
            {
                SenderId        = sender.Id,
                ReceiverId      = receiver.Id,
                TripId          = trip.Id,
                Subject         = subject,
                ReceiverMessage = receiverMessage,
                SenderMessage   = senderMessage,
            };

            receiver.ReceivedNotifications.Add(notification);
            this.usersRepository.Update(receiver);

            sender.SentNotifications.Add(notification);
            this.usersRepository.Update(sender);

            await this.usersRepository.SaveChangesAsync();

            return(notification.Id);
        }