public ActionResult Post([FromBody] AssignmentUserChatRoomModel assignmentUserChatRoom) { try { return(this.SuccessResponse(this._chatRoomService.RegisterAssignmentUserChatRoom(assignmentUserChatRoom))); } catch (Exception e) { return(this.BadRequest(e.Message)); } }
public AssignmentUserChatRoomModel RegisterAssignmentUserChatRoom(AssignmentUserChatRoomModel assignmentUserChatRoom) { AssignmentUserChatRoomEntity assignmentUserChatRoomEntity = this._chatRoomContext.AssignmentUserChatRooms .Include(x => x.ChatRoom) .Where(x => x.Id == assignmentUserChatRoom.ChatRoomId) .Where(x => x.UserId == assignmentUserChatRoom.UserId).FirstOrDefault(); if (assignmentUserChatRoomEntity != null) { throw new Exception("Currently exist this user in the chat room:" + assignmentUserChatRoomEntity.ChatRoom.Name); } assignmentUserChatRoom.Status = StatusEnum.Active.GetDescription(); assignmentUserChatRoomEntity = Mapper.MapAssignmentUserChatRoomModelToAssignmentUserChatRoomEntity(assignmentUserChatRoom); this.InsertAssignmentUserChatRoom(assignmentUserChatRoomEntity); return(Mapper.MapAssignmentUserChatRoomEntityToAssignmentUserChatRoomModel(assignmentUserChatRoomEntity)); }
public static AssignmentUserChatRoomEntity MapAssignmentUserChatRoomModelToAssignmentUserChatRoomEntity(AssignmentUserChatRoomModel assignmentUserChatRoom) { return(new AssignmentUserChatRoomEntity { ChatRoomId = assignmentUserChatRoom.ChatRoomId, Id = assignmentUserChatRoom.Id, Status = assignmentUserChatRoom.Status, UserId = assignmentUserChatRoom.UserId }); }