public static async Task DeleteDraft(DraftModel item) { using (var db = new DraftDbContext()) { db.Draft.Remove(db.Draft.Find(item.Id)); await db.SaveChangesAsync(); } }
private static async void HandleFailedAsync(int id, Exception e) { using (var db = new DraftDbContext()) { var item = db.Draft.Find(id); item.ErrorMessage = e.Message; db.Draft.Update(item); await db.SaveChangesAsync(); } }
private static async void HandleSuccessAsync(DraftModel item) { if (item.Medias != null && item.Medias.Any()) { foreach (var media in item.Medias) { await media.DeleteFile(); } } using (var db = new DraftDbContext()) { db.Draft.Remove(db.Draft.Find(item.Id)); await db.SaveChangesAsync(); } }
public static async void Add(DraftModel item) { using (var db = new DraftDbContext()) { if (!db.Draft.Any(d => d.Id == item.Id)) { if (item.Medias != null && item.Medias.Any()) { foreach (var media in item.Medias) { await media.SaveToFile(); } } db.Draft.Add(item); //if (item.Medias != null && item.Medias.Any()) // db.MediaData.AddRange(item.Medias); //if (item.ReplyStatus != null) // db.Reply.Add(item.ReplyStatus); await db.SaveChangesAsync(); } } Task.Run(() => HandleDraft(item)); }