Esempio n. 1
0
        public IHttpActionResult PostFile(FileViewModel fileViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // if ParentId is not a folder
            if (fileViewModel.ParentId != null && !FileRepository.FolderExists(fileViewModel.ParentId.Value))
            {
                return(BadRequest(ModelState));
            }

            var fileEntity = fileViewModel.ToFileEntity();

            fileEntity.SeqNum = fileViewModel.GetNextSeqNumber(FileRepository, fileEntity);

            fileEntity.Type = EntityType.File;
            FileRepository.Create(fileEntity);

            return(CreatedAtRoute("DefaultApi", new { id = fileViewModel.Id }, fileEntity.ToFileViewModel()));
        }