public Deal DeleteDeal(int id) { if (id <= 0) { return(null); } var deal = GetByID(id); if (deal == null) { return(null); } _crmSecurity.DemandDelete(deal); var dbEntity = CrmDbContext.Deals.Find(id); _factoryIndexer.Delete(dbEntity); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "deals.*")); DeleteBatchDealsExecute(new List <Deal>() { deal }); return(deal); }
public virtual Deal DeleteDeal(int dealID) { if (dealID <= 0) { return(null); } var deal = GetByID(dealID); if (deal == null) { return(null); } CRMSecurity.DemandDelete(deal); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "deals.*")); DeleteBatchDealsExecute(new List <Deal>() { deal }); FactoryIndexer <DealsWrapper> .DeleteAsync(deal); return(deal); }
public int GetInvoicesCount( String searchText, InvoiceStatus?status, DateTime issueDateFrom, DateTime issueDateTo, DateTime dueDateFrom, DateTime dueDateTo, EntityType entityType, int entityID, String currency) { var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) + "invoice" + SecurityContext.CurrentAccount.ID.ToString() + searchText; var fromCache = _cache.Get <string>(cacheKey); if (fromCache != null) { return(Convert.ToInt32(fromCache)); } var withParams = hasParams(searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency); var exceptIDs = CRMSecurity.GetPrivateItems(typeof(Invoice)).ToList(); int result; using (var db = GetDb()) { if (withParams) { var whereConditional = WhereConditional(null, exceptIDs, searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency); result = whereConditional != null?db.ExecuteScalar <int>(Query("crm_invoice").Where(whereConditional).SelectCount()) : 0; } else { var countWithoutPrivate = db.ExecuteScalar <int>(Query("crm_invoice").SelectCount()); var privateCount = exceptIDs.Count; if (privateCount > countWithoutPrivate) { _log.ErrorFormat(@"Private invoice count more than all cases. Tenant: {0}. CurrentAccount: {1}", TenantID, SecurityContext.CurrentAccount.ID); privateCount = 0; } result = countWithoutPrivate - privateCount; } } if (result > 0) { _cache.Insert(cacheKey, result, TimeSpan.FromSeconds(30)); } return(result); }
public virtual Invoice DeleteInvoice(int invoiceID) { if (invoiceID <= 0) { return(null); } var invoice = GetByID(invoiceID); if (invoice == null) { return(null); } CRMSecurity.DemandDelete(invoice); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); DeleteBatchInvoicesExecute(new List <Invoice> { invoice }); return(invoice); }
public int GetInvoicesCount( String searchText, InvoiceStatus?status, DateTime issueDateFrom, DateTime issueDateTo, DateTime dueDateFrom, DateTime dueDateTo, EntityType entityType, int entityID, String currency) { var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) + "invoice" + _securityContext.CurrentAccount.ID.ToString() + searchText; var fromCache = _cache.Get <string>(cacheKey); if (fromCache != null) { return(Convert.ToInt32(fromCache)); } var withParams = hasParams(searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency); var exceptIDs = _crmSecurity.GetPrivateItems(typeof(Invoice)).ToList(); int result; if (withParams) { var sqlQuery = GetDbInvoceByFilters(exceptIDs, searchText, status, issueDateFrom, issueDateTo, dueDateFrom, dueDateTo, entityType, entityID, currency); result = sqlQuery != null?sqlQuery.Count() : 0; } else { var countWithoutPrivate = Query(CrmDbContext.Invoices).Count(); var privateCount = exceptIDs.Count; if (privateCount > countWithoutPrivate) { _logger.ErrorFormat(@"Private invoice count more than all cases. Tenant: {0}. CurrentAccount: {1}", TenantID, _securityContext.CurrentAccount.ID); privateCount = 0; } result = countWithoutPrivate - privateCount; } if (result > 0) { _cache.Insert(cacheKey, result.ToString(), TimeSpan.FromSeconds(30)); } return(result); }
public virtual int SaveTask(Task newTask) { _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "tasks.*")); using (var db = GetDb()) { return(SaveTask(newTask, db)); } }
public int CreateCases(String title) { var result = CreateCasesInDb(title); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); return(result); }
/// <summary> /// Test method /// </summary> /// <param name="taskId"></param> /// <param name="lastModifedDate"></param> public void SetTaskLastModifedDate(int taskId, DateTime lastModifedDate) { Db.ExecuteNonQuery( Update("crm_task") .Set("last_modifed_on", TenantUtil.DateTimeToUtc(lastModifedDate)) .Where(Exp.Eq("id", taskId))); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "tasks.*")); }
/// <summary> /// Test method /// </summary> /// <param name="opportunityid"></param> /// <param name="lastModifedDate"></param> public void SetDealLastModifedDate(int opportunityid, DateTime lastModifedDate) { Db.ExecuteNonQuery( Update("crm_deal") .Set("last_modifed_on", TenantUtil.DateTimeToUtc(lastModifedDate)) .Where(Exp.Eq("id", opportunityid))); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "deals.*")); }
public virtual int SaveOrUpdateInvoice(Invoice invoice) { _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); using (var db = GetDb()) { return(SaveOrUpdateInvoice(invoice, db)); } }
/// <summary> /// Test method /// </summary> /// <param name="invoiceId"></param> /// <param name="creationDate"></param> public void SetInvoiceCreationDate(int invoiceId, DateTime creationDate) { Db.ExecuteNonQuery( Update("crm_invoice") .Set("create_on", TenantUtil.DateTimeToUtc(creationDate)) .Where(Exp.Eq("id", invoiceId))); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); }
public int GetInvoiceItemsCount( String searchText, int status, bool?inventoryStock) { var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) + "invoiceItem" + SecurityContext.CurrentAccount.ID.ToString() + searchText; var fromCache = _cache.Get(cacheKey); if (fromCache != null) { return(Convert.ToInt32(fromCache)); } var withParams = !(String.IsNullOrEmpty(searchText) || status != 0 || inventoryStock.HasValue); var exceptIDs = CRMSecurity.GetPrivateItems(typeof(InvoiceItem)).ToList(); int result; using (var db = GetDb()) { if (withParams) { var whereConditional = WhereConditional(exceptIDs, searchText, status, inventoryStock); result = whereConditional != null?db.ExecuteScalar <int>(Query("crm_invoice_item").Where(whereConditional).SelectCount()) : 0; } else { var countWithoutPrivate = db.ExecuteScalar <int>(Query("crm_invoice_item").SelectCount()); var privateCount = exceptIDs.Count; if (privateCount > countWithoutPrivate) { _log.ErrorFormat(@"Private invoice items count more than all cases. Tenant: {0}. CurrentAccount: {1}", TenantID, SecurityContext.CurrentAccount.ID); privateCount = 0; } result = countWithoutPrivate - privateCount; } } if (result > 0) { _cache.Insert(cacheKey, result, new CacheDependency(null, new[] { _invoiceCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(30)); } return(result); }
public virtual int SaveOrUpdateInvoice(Invoice invoice) { _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); var result = SaveOrUpdateInvoiceInDb(invoice); FactoryIndexer <InvoicesWrapper> .IndexAsync(invoice); return(result); }
public virtual Task[] SaveOrUpdateTaskList(List <Task> newTasks) { _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "tasks.*")); var result = new List <Task>(); foreach (var newTask in newTasks) { result.Add(SaveOrUpdateTaskInDb(newTask)); } return(result.ToArray()); }
public virtual int[] SaveCasesList(List <Cases> items) { using (var tx = Db.BeginTransaction()) { var result = items.Select(item => CreateCasesInDb(item.Title)).ToArray(); tx.Commit(); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "cases.*")); return(result); } }
public int SaveOrUpdateInvoice(Invoice invoice) { _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); var result = SaveOrUpdateInvoiceInDb(invoice); _factoryIndexer.Index(Query(CrmDbContext.Invoices).Where(x => x.Id == invoice.ID).Single()); return(result); }
public List<Invoice> DeleteBatchInvoices(int[] invoiceID) { var invoices = GetInvoices(invoiceID).Where(CRMSecurity.CanDelete).ToList(); if (!invoices.Any()) return invoices; // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); DeleteBatchInvoicesExecute(invoices); return invoices; }
public override IEnumerable <VoipPhone> GetNumbers(params object[] ids) { var numbers = cache.Get <List <VoipPhone> >(TenantID.ToString(CultureInfo.InvariantCulture)); if (numbers == null) { numbers = new List <VoipPhone>(base.GetNumbers()); cache.Insert(TenantID.ToString(CultureInfo.InvariantCulture), numbers, DateTime.UtcNow.Add(timeout)); } return(ids.Any() ? numbers.Where(r => ids.Contains(r.Id) || ids.Contains(r.Number)) : numbers); }
/// <summary> /// Test method /// </summary> /// <param name="taskId"></param> /// <param name="creationDate"></param> public void SetTaskCreationDate(int taskId, DateTime creationDate) { using (var db = GetDb()) { db.ExecuteNonQuery( Update("crm_task") .Set("create_on", TenantUtil.DateTimeToUtc(creationDate)) .Where(Exp.Eq("id", taskId))); } // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "tasks.*")); }
/// <summary> /// Test method /// </summary> /// <param name="invoiceId"></param> /// <param name="lastModifedDate"></param> public void SetInvoiceLastModifedDate(int invoiceId, DateTime lastModifedDate) { using (var db = GetDb()) { db.ExecuteNonQuery( Update("crm_invoice") .Set("last_modifed_on", TenantUtil.DateTimeToUtc(lastModifedDate)) .Where(Exp.Eq("id", invoiceId))); } // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); }
/// <summary> /// Test method /// </summary> /// <param name="id"></param> /// <param name="creationDate"></param> public void SetInvoiceCreationDate(int id, DateTime creationDate) { var dbEntity = CrmDbContext.Invoices.Find(id); var entity = _mapper.Map <Invoice>(dbEntity); dbEntity.CreateOn = _tenantUtil.DateTimeToUtc(creationDate); CrmDbContext.SaveChanges(); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); }
public int GetInvoiceItemsCount( String searchText, int status, bool?inventoryStock) { var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) + "invoiceItem" + _securityContext.CurrentAccount.ID.ToString() + searchText; var fromCache = _cache.Get <string>(cacheKey); if (fromCache != null) { return(Convert.ToInt32(fromCache)); } var exceptIDs = _crmSecurity.GetPrivateItems(typeof(InvoiceItem)).ToList(); int result; var withParams = !(String.IsNullOrEmpty(searchText) || status != 0 || inventoryStock.HasValue); if (withParams) { result = GetDbInvoiceItemByFilters(exceptIDs, searchText, status, inventoryStock).Count(); } else { var countWithoutPrivate = Query(CrmDbContext.InvoiceItem).Count(); var privateCount = exceptIDs.Count; if (privateCount > countWithoutPrivate) { _logger.ErrorFormat(@"Private invoice items count more than all cases. Tenant: {0}. CurrentAccount: {1}", TenantID, _securityContext.CurrentAccount.ID); privateCount = 0; } result = countWithoutPrivate - privateCount; } if (result > 0) { _cache.Insert(cacheKey, result.ToString(), TimeSpan.FromSeconds(30)); } return(result); }
private Tag SaveTag(Tag t, Dictionary <string, int> cacheTagId, DateTime createOn) { var cacheTagIdKey = string.Join("/", new[] { TenantID.ToString(), t.Owner.ToString(), t.TagName, ((int)t.TagType).ToString(CultureInfo.InvariantCulture) }); if (!cacheTagId.TryGetValue(cacheTagIdKey, out var id)) { id = FilesDbContext.Tag .Where(r => r.Owner == t.Owner) .Where(r => r.Name == t.TagName) .Where(r => r.Flag == t.TagType) .Select(r => r.Id) .FirstOrDefault(); if (id == 0) { var toAdd = new DbFilesTag { Id = 0, Name = t.TagName, Owner = t.Owner, Flag = t.TagType, TenantId = TenantID }; toAdd = FilesDbContext.Tag.Add(toAdd).Entity; FilesDbContext.SaveChanges(); id = toAdd.Id; } cacheTagId.Add(cacheTagIdKey, id); } t.Id = id; var linkToInsert = new DbFilesTagLink { TenantId = TenantID, TagId = id, EntryId = MappingID(t.EntryId, true).ToString(), EntryType = t.EntryType, CreateBy = AuthContext.CurrentAccount.ID, CreateOn = createOn, TagCount = t.Count }; FilesDbContext.AddOrUpdate(r => r.TagLink, linkToInsert); FilesDbContext.SaveChanges(); return(t); }
public List <Deal> DeleteBatchDeals(List <Deal> deals) { deals = deals.FindAll(CRMSecurity.CanDelete).ToList(); if (!deals.Any()) { return(deals); } // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "deals.*")); DeleteBatchDealsExecute(deals); return(deals); }
public virtual void DeleteTask(int taskID) { var task = GetByID(taskID); if (task == null) { return; } CRMSecurity.DemandEdit(task); Db.ExecuteNonQuery(Delete("crm_task").Where("id", taskID)); _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "tasks.*")); }
public virtual List <Cases> DeleteBatchCases(List <Cases> caseses) { caseses = caseses.FindAll(CRMSecurity.CanDelete).ToList(); if (!caseses.Any()) { return(caseses); } // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); DeleteBatchCasesExecute(caseses); return(caseses); }
/// <summary> /// Test method /// </summary> /// <param name="id"></param> /// <param name="lastModifedDate"></param> public void SetInvoiceLastModifedDate(int id, DateTime lastModifedDate) { var dbEntity = CrmDbContext.Invoices.Find(id); var entity = _mapper.Map <Invoice>(dbEntity); _crmSecurity.DemandAccessTo(entity); dbEntity.LastModifedOn = _tenantUtil.DateTimeToUtc(lastModifedDate); CrmDbContext.SaveChanges(); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); }
public virtual void UpdateCases(Cases cases) { CRMSecurity.DemandEdit(cases); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "invoice.*")); Db.ExecuteNonQuery( Update("crm_case") .Set("title", cases.Title) .Set("is_closed", cases.IsClosed) .Set("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow())) .Set("last_modifed_by", SecurityContext.CurrentAccount.ID) .Where("id", cases.ID) ); }
/// <summary> /// Test method /// </summary> /// <param name="id"></param> /// <param name="lastModifedDate"></param> public void SetDealLastModifedDate(int id, DateTime lastModifedDate) { var dbEntity = CrmDbContext.Deals.Find(id); if (dbEntity.TenantId != TenantID) { throw new ArgumentException(); } dbEntity.LastModifedOn = _tenantUtil.DateTimeToUtc(lastModifedDate); CrmDbContext.SaveChanges(); // Delete relative keys _cache.Remove(new Regex(TenantID.ToString(CultureInfo.InvariantCulture) + "deals.*")); }
public int GetTasksCount( String searchText, Guid responsibleId, int categoryId, bool?isClosed, DateTime fromDate, DateTime toDate, EntityType entityType, int entityId) { int result = 0; var cacheKey = TenantID.ToString(CultureInfo.InvariantCulture) + "tasks" + SecurityContext.CurrentAccount.ID.ToString() + searchText + responsibleId + categoryId + fromDate.ToString(CultureInfo.InvariantCulture) + toDate.ToString(CultureInfo.InvariantCulture) + (int)entityType + entityId; var tasksList = GetCrudeTasks(searchText, responsibleId, categoryId, isClosed, fromDate, toDate, entityType, entityId, 0, 0, null).Where(CRMSecurity.CanAccessTo); result = tasksList.Count(); if (result > 0) { _cache.Insert(cacheKey, result, new CacheDependency(null, new[] { _taskCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1)); } return(result); }