public async Task <bool> DeleteMany(DeleteManyModel <int> lstCategoryId) { try { List <Category> lstCategory = new List <Category>(); foreach (var cID in lstCategoryId.ListItem) { var category = await _db.Categories.FindAsync(cID); if (category.Exams != null) { foreach (var exam in category.Exams) { exam.isActive = false; } } category.isActive = false; } await _db.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
public async Task <bool> DeleteMany(DeleteManyModel <int> lstId) { try { foreach (var id in lstId.ListItem) { var q = await _db.Questions.FindAsync(id); if (q.Results != null) { foreach (var record in q.Results) { _db.Results.Remove(record); } } _db.Questions.Remove(q); } await _db.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
public async Task <IActionResult> DeleteMany([FromBody] int[] s) { try { var token = CookieEncoder.DecodeToken(Request.Cookies["access_token_cookie"]); if (s.Length == 0) { return(Json(new { deleteResult = false })); } DeleteManyModel <int> temp = new DeleteManyModel <int>(); temp.ListItem = new List <int>(); temp.ListItem.AddRange(s); var result = await _questionManage.DeleteMany(temp, token); if (result.msg != null) { return(Json(new { deleteResult = false })); } return(Json(new { deleteResult = true })); } catch { //return RedirectToAction("Index"); return(Json(new { deleteResult = false })); } }
public void BulkWrite_with_DeleteMany( [Values(false, true)] bool async) { var subject = CreateSubject(); var model = new DeleteManyModel <B>(_providedFilter); var options = new BulkWriteOptions(); if (async) { subject.BulkWriteAsync(new[] { model }, options, CancellationToken.None); _derivedCollection.Received().BulkWriteAsync( Arg.Is <IEnumerable <WriteModel <B> > >(v => v.OfType <DeleteManyModel <B> >() .Where(m => RenderFilter(m.Filter).Equals(_expectedFilter)).Count() == 1), options, CancellationToken.None); } else { subject.BulkWrite(new[] { model }, options, CancellationToken.None); _derivedCollection.Received().BulkWrite( Arg.Is <IEnumerable <WriteModel <B> > >(v => v.OfType <DeleteManyModel <B> >() .Where(m => RenderFilter(m.Filter).Equals(_expectedFilter)).Count() == 1), options, CancellationToken.None); } }
public void BulkWrite_with_DeleteMany( [Values(false, true)] bool async) { var subject = CreateSubject(); var model = new DeleteManyModel <B>(_providedFilter) { Hint = new BsonDocument("_id", 1) }; var options = new BulkWriteOptions(); if (async) { subject.BulkWriteAsync(new[] { model }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.BulkWriteAsync( It.Is <IEnumerable <WriteModel <B> > >(v => v.OfType <DeleteManyModel <B> >() .Where(m => m.Hint == model.Hint && RenderFilter(m.Filter).Equals(_expectedFilter)).Count() == 1), options, CancellationToken.None), Times.Once); } else { subject.BulkWrite(new[] { model }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.BulkWrite( It.Is <IEnumerable <WriteModel <B> > >(v => v.OfType <DeleteManyModel <B> >() .Where(m => m.Hint == model.Hint && RenderFilter(m.Filter).Equals(_expectedFilter)).Count() == 1), options, CancellationToken.None), Times.Once); } }
public async Task <bool> DeleteMany(DeleteManyModel <int> lstExamId) { try { List <Exam> lstCategory = new List <Exam>(); foreach (var id in lstExamId.ListItem) { var exam = await _db.Exams.FindAsync(id); if (exam.Questions != null) { foreach (var question in exam.Questions) { question.isActive = false; } } exam.isActive = false; } await _db.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
public async Task <bool> DeleteMany(DeleteManyModel <int> lstExamId) { try { List <Exam> lstExam = new List <Exam>(); foreach (var item in lstExamId.ListItem) { var e = await _db.Exams.Where(e => e.ID == item).Include(e => e.Questions).FirstOrDefaultAsync(); if (e.Questions != null) { foreach (var q in e.Questions) { q.isActive = false; } } e.isActive = false; } await _db.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
public override void RemoveSet(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var filter = CreateSetFilter(key); var writeModel = new DeleteManyModel <BsonDocument>(filter); _writeModels.Add(writeModel); }
public override void RemoveHash(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var filter = new BsonDocument(nameof(HashDto.Key), key); var writeModel = new DeleteManyModel <BsonDocument>(filter); _writeModels.Add(writeModel); }
public async Task <IActionResult> AdminDeleteMany(DeleteManyModel <int> lstExamId) { var isDeleted = await _examAdminService.DeleteMany(lstExamId); if (isDeleted) { return(Ok(new ResponseBase <string>() { })); } return(Ok(new ResponseBase <string>() { msg = "Xoá thất bại" })); }
public async Task <IActionResult> AdminDeleteMany(DeleteManyModel <int> lstId) { var ok = await _questionService.DeleteMany(lstId); if (ok) { return(Ok(new ResponseBase <string>() { data = "Xoá thành công " })); } return(Ok(new ResponseBase <string>() { msg = "Xoá thất bại" })); }
public override void RemoveSet(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var filter = new BsonDocument("$and", new BsonArray { new BsonDocument(nameof(KeyJobDto.Key), key), new BsonDocument("_t", nameof(SetDto)) }); var writeModel = new DeleteManyModel <BsonDocument>(filter); _writeModels.Add(writeModel); }
public async Task <IActionResult> DeleteMany(DeleteManyModel <int> lstCategoryId) { var deleteResult = await _categoryService.DeleteMany(lstCategoryId); if (deleteResult) { return(Ok(new ResponseBase <Category>() { })); } else { return(Ok(new ResponseBase <Category>() { msg = "Xoá thất bại" })); } }
public override void RemoveFromList(string key, string value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var filter = new BsonDocument("$and", new BsonArray { new BsonDocument(nameof(ListDto.Item), key), new BsonDocument(nameof(ListDto.Value), value), new BsonDocument("_t", nameof(ListDto)) }); var writeModel = new DeleteManyModel <BsonDocument>(filter); _writeModels.Add(writeModel); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public bool Push(IEnumerable <BsonDocument> objects, bool overwrite = true, string key = "") { // Check that the database is connected if (m_Client.Cluster.Description.State == MongoDB.Driver.Core.Clusters.ClusterState.Disconnected) { return(false); } // Create the bulk query for the object to replace/insert List <WriteModel <BsonDocument> > bulk = new List <WriteModel <BsonDocument> >(); WriteModel <BsonDocument> deletePrevious = new DeleteManyModel <BsonDocument>(Builders <BsonDocument> .Filter.Eq("__Key__", key)); if (overwrite) { bulk.Add(deletePrevious); } foreach (BsonDocument obj in objects) { bulk.Add(new InsertOneModel <BsonDocument>(obj)); } // Send that query BulkWriteOptions bulkOptions = new BulkWriteOptions(); bulkOptions.IsOrdered = true; m_Collection.BulkWrite(bulk, bulkOptions); // Push in the history database as well if (overwrite) { bulk.Remove(deletePrevious); } List <BsonDocument> times = Pull(new List <string> { "{$group: {_id: \"$__Time__\"}}", "{$sort: {_id: -1}}" }); if (times.Count > HistorySize) { bulk.Insert(0, new DeleteManyModel <BsonDocument>(Builders <BsonDocument> .Filter.Lte("__Time__", times[HistorySize]))); } m_History.BulkWrite(bulk, bulkOptions); return(true); }
public override void TrimList(string key, int keepStartingFrom, int keepEndingAt) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var start = keepStartingFrom + 1; var end = keepEndingAt + 1; // get all ids var allIds = _dbContext.JobGraph.OfType <ListDto>() .Find(new BsonDocument()) .Project(doc => doc.Id) .ToList(); // Add LisDto's scheduled for insertion writemodels collection, add it here. allIds .AddRange(_writeModels.OfType <InsertOneModel <BsonDocument> >() .Where(model => ListDtoHasItem(key, model)) .Select(model => model.Document["_id"].AsObjectId)); var toTrim = allIds .OrderByDescending(id => id.Timestamp) .Select((id, i) => new { Index = i + 1, Id = id }) .Where(_ => (_.Index >= start && (_.Index <= end)) == false) .Select(_ => _.Id) .ToList(); var filter = new BsonDocument("$and", new BsonArray { new BsonDocument(nameof(ListDto.Item), key), new BsonDocument("_id", new BsonDocument("$in", new BsonArray(toTrim))), new BsonDocument("_t", nameof(ListDto)) }); var writeModel = new DeleteManyModel <BsonDocument>(filter); _writeModels.Add(writeModel); }
public async Task <ResponseBase <string> > DeleteMany(DeleteManyModel <int> lstId, string accessToken) { if (accessToken != null) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); } var json = JsonConvert.SerializeObject(lstId); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("api/Exams/Admin/DeleteMany", httpContent); if (response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(); ResponseBase <string> deleteResult = JsonConvert.DeserializeObject <ResponseBase <string> >(body); return(deleteResult); } else { return(null); } }
private void RunDeleteCommand(GridFSBucket bucket, BsonDocument command) { var collectionName = command["delete"].AsString; var collection = bucket.Database.GetCollection <BsonDocument>(collectionName); var requests = new List <WriteModel <BsonDocument> >(); foreach (BsonDocument deleteStatement in command["deletes"].AsBsonArray) { var filter = deleteStatement["q"].AsBsonDocument; var limit = deleteStatement["limit"].ToInt32(); WriteModel <BsonDocument> request; if (limit == 1) { request = new DeleteOneModel <BsonDocument>(filter); } else { request = new DeleteManyModel <BsonDocument>(filter); } requests.Add(request); } collection.BulkWrite(requests); }
public IActionResult DeleteReport([FromBody] DeleteManyModel model) { return(_reportService.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteSerialNumber([FromBody] DeleteManyModel model) { return(_serialNumberRuleDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteDuplicateRule([FromBody] DeleteManyModel model) { return(_duplicateRuleDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteDashBoard([FromBody] DeleteManyModel model) { return(_systemFormDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteAttribute([FromBody] DeleteManyModel model) { return(_attributeDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult Post(DeleteManyModel model) { return(_ribbonButtonDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteWebResource([FromBody] DeleteManyModel model) { return(_webResourceDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteRibbonButton([FromBody] DeleteManyModel model) { return(_ribbonButtonDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
private Task RunDeleteCommandAsync(GridFSBucket bucket, BsonDocument command) { var collectionName = command["delete"].AsString; var collection = bucket.Database.GetCollection<BsonDocument>(collectionName); var requests = new List<WriteModel<BsonDocument>>(); foreach (BsonDocument deleteStatement in command["deletes"].AsBsonArray) { var filter = deleteStatement["q"].AsBsonDocument; var limit = deleteStatement["limit"].ToInt32(); WriteModel<BsonDocument> request; if (limit == 1) { request = new DeleteOneModel<BsonDocument>(filter); } else { request = new DeleteManyModel<BsonDocument>(filter); } requests.Add(request); } return collection.BulkWriteAsync(requests); }
public IActionResult DeleteEntityMap([FromBody] DeleteManyModel model) { return(_entityMapDeleter.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult Delete(DeleteManyModel model) { return(_entityDeleter.DeleteById(id: model.RecordId).DeleteResult(T)); }
public IActionResult DeletePrivilege([FromBody] DeleteManyModel model) { return(_privilegeService.DeleteById(model.RecordId).DeleteResult(T)); }
public IActionResult DeleteWorkFlow([FromBody] DeleteManyModel model) { return(_workFlowDeleter.DeleteById(model.RecordId).DeleteResult(T)); }