private HttpResult deleteMetadata <Entity>(MetadataDto dto, string type) where Entity : Metadata, new() { var found = Db.Select <Entity>(e => e.OwnerId == GetCurrentAuthUserId() && e.Id == dto.Id); //TODO - transaction? if (found.Count != 0) { var inProgressTasks = Db.Select <Task>(entity => entity.Status == "in progres"); if (found[0].CanDelete(inProgressTasks)) { Db.DeleteById <Entity>(dto.Id); var S3Object = new S3ObjectMetadata(Environment.GetEnvironmentVariable("S3_BUCKET_NAME"), $"{GetCurrentAuthUserId()}-{type}-{dto.Id}"); S3Object.remove(); } } return(new HttpResult(HttpStatusCode.NoContent, "No content")); }
private HttpResult saveNewMetadata(MetadataDto metadataDto, Metadata metadata) { metadata.IsUploaded = false; metadata.CreatedAt = DateTime.Now; metadata.OwnerId = GetCurrentAuthUserId(); Db.Insert(metadata); var id = (int)Db.GetLastInsertId(); metadataDto.PopulateWith(metadata); metadataDto.Id = id; return(new HttpResult(metadataDto) { StatusCode = HttpStatusCode.Created, Headers = { { HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(id) } } }); }