private async Task<ActionResult> ImportTrash(ReviewViewModel viewModel) { System.Diagnostics.Debug.Assert(viewModel != null); var userId = GetUserId(); var mongoDbComponent = new MongoDbComponent(); var collection = mongoDbComponent.MessageFilters; //Pull down the file data. var messageFilter = await collection.FindOneByObjectIdUserIdAsync(viewModel.MessageFilterId, userId); if (messageFilter == null) return new HttpNotFoundResult("Could not find import file."); //Remove it from the MongoDb storage. await collection.RemoveAsync(messageFilter); return RedirectToAction("Import"); }
public async Task<ActionResult> ImportReview(string postAction, ReviewViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!string.Equals(postAction, "trash", StringComparison.OrdinalIgnoreCase) && !string.Equals(postAction, "try another file", StringComparison.OrdinalIgnoreCase)) { return await ImportContinue(viewModel); } else { return await ImportTrash(viewModel); } }
private async Task<ActionResult> ImportContinue(ReviewViewModel viewModel) { System.Diagnostics.Debug.Assert(viewModel != null); var userId = GetUserId(); var mongoDbComponent = new MongoDbComponent(); var collection = mongoDbComponent.MessageFilters; //Pull down the file data. var messageFilter = await collection.FindOneByObjectIdUserIdAsync(viewModel.MessageFilterId, userId); if (messageFilter == null) return new HttpNotFoundResult("Could not find import file."); //Throw the selected entry ids into a hashset. var selectedEntries = viewModel.Entries .Where(o => o.IsSelected) .Select(o => o.EntryId) .ToHashSet(); var context = this.DbContext; bool hasAdded = false; var dateCreatedUtc = DateTime.UtcNow; //Add it to the SQL server collection. var filterComponent = new MessageFilterComponent(); foreach (var item in messageFilter.Entries) { var itemId = filterComponent.GetFilterIdPart(item.IdTag); if (!selectedEntries.Contains(itemId)) continue; context.Filters.Add(new GMailLabelCleanup.Data.Models.Filters.Filter { UserId = userId, ImportId = itemId, Description = filterComponent.CreateDescription(item), DateCreatedUtc = dateCreatedUtc, FilterProperties = item.Properties.Select(o => new FilterProperty { IsIncluded = true, Name = o.Name, Value = o.Value, DateCreatedUtc = dateCreatedUtc }).ToList() }); hasAdded = true; } if (hasAdded) { await context.SaveChangesAsync(); } //Remove it from the MongoDb storage. await collection.RemoveAsync(messageFilter); return RedirectToAction("Index"); }
public async Task<ActionResult> ImportReview(string id) { if (string.IsNullOrEmpty(id)) return new HttpNotFoundResult("Could not find import file."); var userId = GetUserId(); var mongoDbComponent = new MongoDbComponent(); var collection = mongoDbComponent.MessageFilters; //Pull down the file data. var messageFilter = await collection.FindOneByObjectIdUserIdAsync(id, userId); if (messageFilter == null) return new HttpNotFoundResult("Could not find import file."); var filterComponent = new MessageFilterComponent(); var viewModel = new ReviewViewModel { MessageFilterId = messageFilter.Id.ToString(), Entries = messageFilter.Entries.Select(o => new ChooseMessageFilterEntryViewModel { IsSelected = true, EntryId = filterComponent.GetFilterIdPart(o.IdTag), CriteriaProperties = filterComponent.GetCriteriaProperties(o.Properties).ToList(), ActionProperties = filterComponent.GetActionProperties(o.Properties).ToList() }).ToList(), SelectAll = true }; return View(viewModel); }