public async Task <JsonResult> GetList() { var mapData = ((JObject)HttpContext.Items["JSON"]).GetValue("MapSpan").ToObject <MapSpan>(); using (var db = new RecordDb()) return(new JsonResult(await db.GetList(mapData, (uint)UserR.Id))); }
public async Task <JsonResult> Description() { var record = ((JObject)HttpContext.Items["JSON"]).GetValue("Record").ToObject <Record>(); record.Path = null; try { using (var db = new RecordDb()) if (record.IsPublic) { await db.GetPublic(record, UserR.Id.Value); } else { await db.GetPaid(record, UserR.Id.Value); } if (record?.Path != null) { record.PhotoPath = null; record.Path = null; return(new JsonResult(record)); } } catch (Exception ex) { } return(null); }
public async Task <JsonResult> Delete() { var rez = false; var record = ((JObject)HttpContext.Items["JSON"]).GetValue("Record").ToObject <Record>(); using (var db = new RecordDb()) rez = await db.Delete(record); var resp = new { Success = rez }; return(new JsonResult(resp)); }
public Record Convert(RecordDb source) { var result = default(Record); if (source != null) { result = new Record { Id = source.Id, DateTimeUtc = source.DateTimeUtc, PersonId = source.PersonId, IsStart = source.IsStart }; } return(result); }
public RecordDb Convert(Record source, string partitionKey, string rowKey) { var result = default(RecordDb); if (source != null) { result = new RecordDb { Id = source.Id, PersonId = source.PersonId, DateTimeUtc = source.DateTimeUtc, IsStart = source.IsStart, PartitionKey = partitionKey, RowKey = rowKey }; } return(result); }
public async Task <FileResult> Liseten() { var record = ((JObject)HttpContext.Items["JSON"]).GetValue("Record").ToObject <Record>(); record.Path = null; using (var db = new RecordDb()) if (record.IsPublic) { await db.GetPublic(record, UserR.Id.Value); } else { await db.GetPaid(record, UserR.Id.Value); } if (record?.Path != null) { FileStream fs = new FileStream(record.Path, FileMode.Open); return(File(fs, "application/mp3", record.Name + ".mp3")); } return(null); }
public async Task <JsonResult> Post() { Record record = null; record = ((JObject)HttpContext.Items["JSON"]).GetValue("Record").ToObject <Record>(); record.User = UserR; if (record.Audio == null || record.Name == null || record.Point == null) //|| (!record.IsPaid && !record.IsAnon && !record.IsPublic) || record.Language == null) { return(null); } var dirPath = Path.Combine(_config.AutioDirectory, $"userPart{UserR.Id / 1000 + 1}", $"user{UserR.Id}", "audio"); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var bytes = Convert.FromBase64String(record.Audio); record.Audio = null; record.Path = Path.Combine(dirPath, $"{UserR.Id}_{DateTime.UtcNow.ToFileTime()}.wav"); try { using (var file = System.IO.File.Create(record.Path)) await file.WriteAsync(bytes); if (record.PhotoPath != null) { dirPath = Path.Combine(_config.PhotoDirectory, $"userPart{UserR.Id / 1000 + 1}", $"user{UserR.Id}", "photo"); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } bytes = Convert.FromBase64String(record.PhotoPath); record.PhotoPath = Path.Combine(dirPath, $"{UserR.Id}_{DateTime.UtcNow.ToFileTime()}.jpg"); using (var file = System.IO.File.Create(record.PhotoPath)) { await file.WriteAsync(bytes); } } bytes = null; using (var db = new RecordDb()) await db.Create(record); } catch { if (System.IO.File.Exists(record.Path)) { System.IO.File.Delete(record.Path); } if (System.IO.File.Exists(record.PhotoPath)) { System.IO.File.Delete(record.PhotoPath); } } record.PhotoPath = null; record.Path = null; if (record.Id != 0) { return(new JsonResult(new { Record = record })); } else { return(new JsonResult(new { Status = "Error" })); } }