示例#1
0
        public HttpResponseMessage AddReply(string tid, string message, string from, IEnumerable <string> to, IEnumerable <HttpPostedFileBase> files)
        {
            try
            {
                var errorMessage = string.Empty;
                var attachments  = docUtils.UploadFiles(from, files, ref errorMessage);

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error uploading files: " + errorMessage));
                }

                TasksService.CreateReply(new CreateReplyRequest
                {
                    From        = from,
                    Message     = message,
                    To          = "",
                    TopicId     = int.Parse(tid),
                    Attachments = attachments
                });

                return(new HttpResponseMessage(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#2
0
        public HttpResponseMessage AddReply(string tid, string from, string to)
        {
            try
            {
                var errorMessage = string.Empty;
                var message      = HttpContext.Current.Request.Form["message"];
                IEnumerable <TopicAttachmentInfo> attachments = null;
                if (HttpContext.Current.Request.Files.Count > 0)
                {
                    var files = Enumerable.Range(0, HttpContext.Current.Request.Files.Count).Select(
                        t =>
                    {
                        HttpPostedFileBase filebase = new HttpPostedFileWrapper(HttpContext.Current.Request.Files[t]);
                        return(filebase);
                    });

                    attachments = docUtils.UploadFiles(from, files, ref errorMessage);
                }

                var content = new AddReplyModel
                {
                    Result = true,
                    Reply  = new CreateReplyRequest
                    {
                        From        = from,
                        Message     = message,
                        To          = to,
                        TopicId     = int.Parse(tid),
                        Attachments = attachments
                    }
                };

                //insert reply to topic
                TasksService.CreateReply(content.Reply);

                var json = JsonConvert.SerializeObject(
                    content,
                    Formatting.Indented,
                    new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }
                    );
                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StringContent(json, Encoding.UTF8, "text/plain");
                return(result);
            }
            catch (Exception e)
            {
                var content = new AddReplyModel {
                    Result = false, ErrorMessage = e.Message
                };
                var json = JsonConvert.SerializeObject(
                    content,
                    Formatting.Indented,
                    new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }
                    );
                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StringContent(json, Encoding.UTF8, "text/plain");
                return(result);
            }
        }