コード例 #1
0
        public ActionResult <List <Object> > GetDairy(long diaryId)
        {
            List <Object> result = new List <object>();
            var           diary  = _diaryService.GetById(diaryId);

            if (diary != null)
            {
                result.Add(diary);
                if (diary.TravelId != null)
                {
                    var travel = _travelService.GetById(diary.TravelId);
                    if (travel != null)
                    {
                        result.Add(travel);
                        var routes = _routeService.GetByTravelIdOrderStartTime(travel.TravelId);
                        foreach (Route r in routes)
                        {
                            var startSite = _siteService.GetById(r.StartSiteId);
                            var endSite   = _siteService.GetById(r.EndSiteId);
                            result.Add(r);
                            result.Add(startSite);
                            result.Add(endSite);
                        }
                    }
                }
                return(result);
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #2
0
        public ActionResult <Diary> GetDairy(long diaryId)
        {
            var diary = _diaryService.GetById(diaryId);

            if (diary != null)
            {
                return(diary);
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #3
0
        public async Task <IActionResult> Upload(long diaryId)
        {
            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                ModelState.AddModelError("File",
                                         $"The request couldn't be processed (Error 1).");
                return(BadRequest(ModelState));
            }
            var fileName = "";
            var diary    = _diaryService.GetById(diaryId);

            if (diary == null)
            {
                return(BadRequest("The diary is not existed."));
            }
            var boundary = MultipartRequestHelper.GetBoundary(
                MediaTypeHeaderValue.Parse(Request.ContentType),
                _defaultFormOptions.MultipartBoundaryLengthLimit);
            var reader  = new MultipartReader(boundary, HttpContext.Request.Body);
            var section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                var hasContentDispositionHeader =
                    ContentDispositionHeaderValue.TryParse(
                        section.ContentDisposition, out var contentDisposition);

                if (hasContentDispositionHeader)
                {
                    if (!MultipartRequestHelper
                        .HasFileContentDisposition(contentDisposition))
                    {
                        ModelState.AddModelError("File",
                                                 $"The request couldn't be processed (Error 2).");
                        return(BadRequest(ModelState));
                    }
                    else
                    {
                        fileName = Path.GetRandomFileName();
                        var streamedFileContent = await FileHelpers.ProcessStreamedFile(
                            section, contentDisposition, ModelState,
                            _permittedExtensions, _fileSizeLimit);

                        if (!ModelState.IsValid)
                        {
                            return(BadRequest(ModelState));
                        }

                        using (var targetStream = System.IO.File.Create(Path.Combine(_rootPath, fileName)))
                        {
                            await targetStream.WriteAsync(streamedFileContent);
                        }
                    }
                }
                // Drain any remaining section body that hasn't been consumed and
                // read the headers for the next section.
                diary.Photo = String.Join(" ", new string[] { diary.Photo, fileName });
                _diaryService.Update(diary);
                section = await reader.ReadNextSectionAsync();
            }
            return(Ok());
        }
コード例 #4
0
 public async Task <ActionResponse <DiaryDto> > GetById(SimpleRequestBase request)
 {
     return(await diaryService.GetById(request.Id));
 }