public IHttpActionResult PostConversation(ConversationCreateDto createDto)
        {
            createDto = createDto ?? new ConversationCreateDto();
            var conversation = _conversationAppService.Insert(createDto);

            return(CreatedAtRoute("GetConversation", new { id = conversation.Id }, conversation));
        }
        public ConversationReadDto Update(int id, ConversationCreateDto dto)
        {
            var firstUser  = UserData.Users.FirstOrDefault(e => e.Id == dto.FirstUserId);
            var secondUser = UserData.Users.FirstOrDefault(e => e.Id == dto.SecondUserId);

            if (firstUser == null || secondUser == null)
            {
                throw new BusinessException("User does not exist", 400);
            }

            var conversation = _context.Conversations.FirstOrDefault(e => e.Id == id);

            if (conversation == null)
            {
                throw new BusinessException("conversation does not exist");
            }

            conversation.FirstUserId  = dto.FirstUserId;
            conversation.SecondUserId = dto.SecondUserId;
            conversation.CreatedAt    = dto.CreatedAt;

            _context.SaveChanges();

            return(_mapper.Map <ConversationReadDto>(conversation));
        }
        public ConversationDto Insert(ConversationCreateDto createDto)
        {
            var conversation = Mapper.Map <Conversation>(createDto);

            conversation = _conversationService.Insert(conversation);
            CurrentUnitOfWork.SaveChanges();
            var conversationDto = Mapper.Map <ConversationDto>(conversation);

            FillFields(conversationDto);
            return(conversationDto);
        }
        public async Task <IActionResult> CreateConversation([FromBody] ConversationCreateDto conversation)
        {
            try
            {
                if (conversation == null)
                {
                    return(BadRequest("conversation object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid conversation object"));
                }

                // convert incoming Dto to actual Model instance
                var conversationEntity = _mapper.Map <ConversationModel>(conversation);

                _repository.Conversation.CreateConversation(conversationEntity);
                await _repository.Save();

                // Notification event
                // Conversation notifications go to 2 people,
                // either the ticket owner, or the assigned user (if any).
                var ticket = await _repository.Ticket.GetTicketById(new Guid(conversation.TicketId));

                if (conversation.CvSender == ticket.TktAssignedTo)
                {
                    _repository.Notification.CreateNotification("tktReplied", conversation.TicketId, ticket.TktCreatedBy);
                }
                else if ((conversation.CvSender == ticket.TktCreatedBy) && (ticket.TktAssignedTo != null))
                {
                    _repository.Notification.CreateNotification("tktReplied", conversation.TicketId, ticket.TktAssignedTo);
                }
                await _repository.Save();

                // convert the model back to a DTO for output
                var createdConversation = _mapper.Map <ConversationDto>(conversationEntity);

                return(Ok(createdConversation));
            }
            catch (Exception)
            {
                return(StatusCode(500, "Something went wrong"));
            }
        }
Beispiel #5
0
        public ActionResult <ConversationReadDto> Create([FromBody] ConversationCreateDto request)
        {
            if (_userRepository.Get(request.CreatorId) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "User doesn't exist."));
            }

            if (request.CreatorId != request.ParticipantId && _userRepository.Get(request.ParticipantId) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "User doesn't exist."));
            }

            Conversation newEntity = _mapper.Map <Conversation>(request);

            newEntity = _conversationRepository.Create(newEntity);

            return(StatusCode(StatusCodes.Status201Created, _mapper.Map <ConversationReadDto>(newEntity)));
        }
        public ConversationReadDto Create(ConversationCreateDto dto)
        {
            var firstUser  = UserData.Users.FirstOrDefault(e => e.Id == dto.FirstUserId);
            var secondUser = UserData.Users.FirstOrDefault(e => e.Id == dto.SecondUserId);

            if (firstUser == null || secondUser == null)
            {
                throw new BusinessException("User does not exist", 400);
            }

            var conversation = _mapper.Map <Conversation>(dto);

            _context.Conversations.Add(conversation);

            _context.SaveChanges();

            _logger.Log("Conversation created!");

            return(_mapper.Map <ConversationReadDto>(conversation));
        }
Beispiel #7
0
        public ActionResult PostConversation([FromBody] ConversationCreateDto dto)
        {
            var entity = _repository.Create(dto);

            return(Ok(entity));
        }
Beispiel #8
0
        public ActionResult PutConversation(int id, ConversationCreateDto dto)
        {
            var entity = _repository.Update(id, dto);

            return(Ok(entity));
        }