// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public ConversationDomain CheckConversationExists(ConversationInsertRequest model)
        {
            ConversationDomain conversation = null;

            try
            {
                DataProvider.ExecuteCmd(GetConnection, "dbo.Conversation_CheckIfExists"
                                        , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@sender_id", model.SenderId);
                    paramCollection.AddWithValue("@receiver_id", model.ReceiverId);
                },
                                        map : delegate(IDataReader reader, short set)
                {
                    conversation      = new ConversationDomain();
                    int startingIndex = 0; //startingOrdinal

                    conversation.ConversationId = reader.GetSafeInt32(startingIndex++);
                    conversation.SenderId       = reader.GetSafeString(startingIndex++);
                    conversation.ReceiverId     = reader.GetSafeString(startingIndex++);
                    conversation.CreateDate     = reader.GetSafeDateTime(startingIndex++);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(conversation);
        }
Exemple #2
0
        public HttpResponseMessage CheckConversationExists(ConversationInsertRequest model)

        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            //- Check for existing conversations.


            ConversationDomain conversationDomain = _ConversationService.CheckConversationExists(model);

            //- If no conversation found, create new conversation.

            if (conversationDomain == null)
            {
                int conversationId = _ConversationService.InsertConversation(model);

                conversationDomain = _ConversationService.GetConversationById(conversationId);
            }

            var response = new ItemResponse <ConversationDomain> {
                Item = conversationDomain
            };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public int InsertConversation(ConversationInsertRequest model)
        {
            int id = 0;

            try
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.Conversation_Insert"
                                             , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@sender_id", model.SenderId);
                    paramCollection.AddWithValue("@receiver_id", model.ReceiverId);

                    SqlParameter p = new SqlParameter("@id", System.Data.SqlDbType.Int);
                    p.Direction    = System.Data.ParameterDirection.Output;

                    paramCollection.Add(p);
                }, returnParameters : delegate(SqlParameterCollection param)
                {
                    int.TryParse(param["@Id"].Value.ToString(), out id);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(id);
        }
Exemple #4
0
        public HttpResponseMessage InsertConversation(ConversationInsertRequest model)

        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            int conversationId = _ConversationService.InsertConversation(model);

            ItemResponse <int> response = new ItemResponse <int>(); // { Item = conversationId };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }