Exemplo n.º 1
0
        public IActionResult Post([FromBody] Document document)
        {
            if (document == null)
            {
                return(BadRequest());
            }

            db.CreateDocument(document);
            db.Save();
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Save([FromBody] List <DocumentModel> documents)
        {
            var documentEntities = new List <Document>();


            foreach (var document in documents)
            {
                var base64 = document.ByteArray.Split(',');

                var documentUrl = _fileSaver.Save(document.Name, base64[1]);

                Document documentEntity = new Document
                {
                    Name = document.Name,
                    Url  = documentUrl
                };

                if (document.InstitutionId != null && document.InstitutionId > 0)
                {
                    documentEntity.InstitutionDocumentsMappings = new[] { new InstitutionDocumentsMapping
                                                                          {
                                                                              InstitutionId = document.InstitutionId ?? 0
                                                                          } }
                }
                ;
                else if (document.ContestId != null && document.ContestId > 0)
                {
                    documentEntity.ContestDocumentsMappings = new[] { new ContestDocumentsMapping
                                                                      {
                                                                          InstitutionId = document.ContestId ?? 0
                                                                      } }
                }
                ;
                else if (!string.IsNullOrEmpty(document.UserId))
                {
                    documentEntity.UserDocumentsMappings = new[] { new UserDocumentsMapping
                                                                   {
                                                                       UserId = document.UserId
                                                                   } }
                }
                ;

                documentEntities.Add(documentEntity);

                await _documentsRepository.Save(documentEntity);
            }


            return(Created("/documents/save", documentEntities));
        }
    }