Exemplo n.º 1
0
        public async Task <ActionResult <HRSubmitPictureOutputDto> > Post([FromBody] FileToCreateDto theFile)
        {
            //TODO move in a specific serviec, controller is doing too much stuffs!
            if (theFile == null ||
                theFile.SubmittedPicture == null ||
                theFile.SubmittedPicture.Id == null ||
                theFile.SubmittedPicture.Id == System.Guid.Empty)
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
            try
            {
                //1-
                using var uploadTask = _storageService.UploadAsync(theFile);
                await uploadTask;
                if (uploadTask.IsCompletedSuccessfully)
                {
                    //2-
                    HRSubmitPictureInputDto pictureToSubmit = new HRSubmitPictureInputDto();
                    pictureToSubmit.VernacularName = theFile.SubmittedPicture?.VernacularName;
                    pictureToSubmit.SourceType     = theFile.SubmittedPicture?.SourceType;
                    pictureToSubmit.Id             = theFile.SubmittedPicture.Id;
                    pictureToSubmit.GenderType     = theFile.SubmittedPicture?.GenderType;
                    pictureToSubmit.Credit         = theFile.SubmittedPicture?.Credit;
                    pictureToSubmit.Comment        = theFile.SubmittedPicture?.Comment;
                    pictureToSubmit.AgeType        = theFile.SubmittedPicture?.AgeType;
                    pictureToSubmit.ThumbnailUrl   = theFile.SubmittedPicture?.ThumbnailUrl;
                    pictureToSubmit.FullImageUrl   = uploadTask.Result;

                    using var subTask = _birdsSubmissionService.UpdatePictureDataAsync(pictureToSubmit);
                    await subTask;
                    if (subTask.IsCompletedSuccessfully)
                    {
                        return(Ok(subTask.Result));
                    }
                    return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
                }
                else
                {
                    return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
                }
            }
            catch
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 2
0
 public async Task <ActionResult <HRSubmitPictureOutputDto> > Put([FromBody] HRSubmitPictureInputDto picture)
 {
     if (picture == null)
     {
         return(new StatusCodeResult(StatusCodes.Status400BadRequest));
     }
     try
     {
         using var taskResult = _birdsSubmissionService.UpdatePictureDataAsync(picture);
         await taskResult;
         if (taskResult.IsCompletedSuccessfully)
         {
             return(Ok(taskResult.Result));
         }
         else
         {
             return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
         }
     }
     catch
     {
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }