Beispiel #1
0
        public ServiceResult <bool> DeleteConversation(DeleteConversationDTO model)
        {
            string errorMessage = string.Empty;
            EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified;
            bool result = false;

            try
            {
                var existingConversation = _conversationRepository.GetById(model.ConversationId);

                if (existingConversation == null)
                {
                    throw new Exception("Sohbet bilgisi bulunamadı.");
                }

                _conversationRepository.Delete(existingConversation);
                _unitOfWork.SaveChanges();

                result            = true;
                serviceResultType = EnumServiceResultType.Success;
            }
            catch (Exception ex)
            {
                errorMessage      = ex.Message;
                serviceResultType = EnumServiceResultType.Error;
            }
            return(new ServiceResult <bool> {
                ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType
            });
        }
        protected void deleteMessage_Click(object sender, EventArgs e)
        {
            LinkButton linkButton     = (LinkButton)sender;
            long       conversationId = Convert.ToInt64(linkButton.AccessKey);

            try
            {
                DeleteConversationDTO deleteConversation = new DeleteConversationDTO()
                {
                    ConversationId = conversationId
                };

                ServiceResult <bool> serviceResult = new ServiceResult <bool>();
                var queryString = new Dictionary <string, string>();
                var response    = ApiHelper.CallSendApiMethod(ApiKeys.MessageApiUrl, "DeleteConversation", queryString, deleteConversation);
                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception("Hata oluştu!");
                }
                var data = response.Content.ReadAsStringAsync().Result;
                serviceResult = JsonConvert.DeserializeObject <ServiceResult <bool> >(data);

                if (serviceResult.ServiceResultType != EnumServiceResultType.Success)
                {
                    throw new Exception(serviceResult.ErrorMessage);
                }

                GetConversationList();
            }
            catch (Exception ex)
            {
            }
        }
        public IHttpActionResult DeleteConversation(DeleteConversationDTO model)
        {
            if (!Request.Headers.Contains("apiKey"))
            {
                return(Unauthorized());
            }

            string apiKey = Request.Headers.GetValues("apiKey").First();

            if (!ApiHelper.CheckKey(apiKey))
            {
                return(Unauthorized());
            }

            try
            {
                var serviceResult = _messageService.DeleteConversation(model);
                return(Ok(serviceResult));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }