Example #1
0
        public async Task <IActionResult> PostUserConversation([FromBody] UserConversationViewModel userConversation)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            this.context.UserConversations.Add(userConversation.ToModel());
            try
            {
                await this.context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (this.UserConversationExists(userConversation.ConversationId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(this.CreatedAtAction("GetUserConversation", new { id = userConversation.ConversationId }, userConversation));
        }
Example #2
0
 public static UserConversation ToModel(this UserConversationViewModel viewModel)
 {
     return(new UserConversation
     {
         IsOwner = viewModel.IsOwner,
         ConversationId = viewModel.ConversationId,
         NotRead = viewModel.NotRead,
         NotReadCount = viewModel.NotReadCount,
         UserId = viewModel.UserId
     });
 }