Exemplo n.º 1
0
        public void Create(NewMessageBoardModel model)
        {
            var from =
                _systemUserRepository.GetFirstOrDefault(predicate: a => a.SystemUserId == model.FromSystemUserId,
                                                        include: a => a.Include(b => b.Business));

            if (from == null)
            {
                throw new ApplicationException("From Id is invalid.");
            }

            var to =
                _systemUserRepository.GetFirstOrDefault(predicate: a => a.SystemUserId == model.ToSystemUserId,
                                                        include: a => a.Include(b => b.Business));

            if (to == null)
            {
                throw new ApplicationException("To Id is invalid.");
            }

            var businessToBusiness = _businessToBusinessRepository.GetFirstOrDefault(predicate: a =>
                                                                                     a.BusinessId1 == from.BusinessId && a.BusinessId2 == to.BusinessId); if (businessToBusiness == null)

            {
                throw new ApplicationException("The Connection is not found.");
            }

            if (businessToBusiness.IsPending == false)
            {
                throw new ApplicationException("Your connection is not pending anymore");
            }
            var requester = businessToBusiness.CreatedBy == from.SystemUserId ? from : to;
            var accepter  = requester.SystemUserId == from.SystemUserId ? to : from;

            var message = new MentifiMessage
            {
                Subject          = "Message Board Post",
                Body             = model.Body,
                DateSent         = DateTime.UtcNow,
                FromBusinessId   = requester.BusinessId,
                FromSystemUserId = requester.SystemUserId,
                ToSystemUserId   = accepter.SystemUserId,
                ToBusinessId     = accepter.BusinessId,
            };
            var messagePostChecker = new MentifiMessageBoardPostChecker()
            {
                CreatedBy      = model.FromSystemUserId,
                HubMessageId   = message.MentifiMessageId,
                MentifiMessage = message
            };

            _mentifiMessageBoardPostRepository.Insert(messagePostChecker);
            CreateNotif(model.ToSystemUserId, model.FromSystemUserId, Constant.NOTIFTYPE_MENTIFIMESSAGEBOARD,
                        message.MentifiMessageId.ToString());

            _unitOfWork.SaveChanges();
        }
Exemplo n.º 2
0
        public void RequestConnection(RequestedConnectionMessageBoardModel model)
        {
            var message = new MentifiMessage()
            {
                Subject          = "Mentor/Mentee Connection Request",
                Body             = model.Body,
                DateSent         = DateTime.UtcNow,
                FromBusinessId   = model.FromBusinessId,
                FromSystemUserId = model.FromSystemUserId,
                ToSystemUserId   = model.ToSystemUserId,
                ToBusinessId     = model.ToBusinessId,
            };

            var messagePostChecker = new MentifiMessageBoardPostChecker()
            {
                CreatedBy      = model.FromSystemUserId,
                HubMessageId   = message.MentifiMessageId,
                MentifiMessage = message
            };

            _mentifiMessageBoardPostRepository.Insert(messagePostChecker);
            CreateNotif(model.FromSystemUserId, model.FromSystemUserId, Constant.NOTIFTYPE_MENTIFIMESSAGEBOARDREQUESTSENT,
                        model.ToSystemUserId.ToString());
        }