public (bool isCreated, int notiId) Create(NotificationApiModel notification, List <USER> users) { var newNotification = new NOTIFICATION(); newNotification.CreatedAt = DateTime.Now; newNotification.Module = notification.module; newNotification.ModuleObjectID = notification.moduleObjectId; newNotification.Submodule = notification.subModule; newNotification.SubmoduleObjectID = notification.subModuleObjectId; newNotification.NotificationContent = notification.content; newNotification.NotificationTitle = notification.title; try { db.NOTIFICATIONs.Add(newNotification); foreach (var user in users) { if (user != null) { var userNotification = new USER_NOTIFICATION(); userNotification.IsRead = false; userNotification.NOTIFICATION = newNotification; userNotification.NOTIFICATION = newNotification; userNotification.USER_ID = user.ID; db.USER_NOTIFICATION.Add(userNotification); } } db.SaveChanges(); return(true, newNotification.ID); } catch { throw; } }
public bool AddContact(int accountId, int contactId) { var dbAccount = db.ACCOUNTs.Find(accountId); var dbContact = _contactRepository.GetOne(contactId); if (dbAccount != null && dbContact != null) { dbAccount.CONTACTs.Add(dbContact); db.SaveChanges(); var owner = db.USERs.Find(dbAccount.AccountOwner); var collaborator = db.USERs.Find(dbAccount.AccountCollaborator); var createdUser = db.USERs.Find(dbAccount.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Contact added to account"; notifyModel.content = $"Contact {dbContact.Name} has been added to account {dbAccount.Name}."; notifyModel.module = "accounts"; notifyModel.moduleObjectId = dbAccount.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator, createdUser }); return(true); } else { return(false); } }
public bool AddTag(int id, string tagName) { var dbLead = db.LEADs.Find(id); var dbTag = _tagRepository.GetOneByName(tagName); if (dbLead != null) { if (dbTag != null) { var tagItem = dbLead.TAG_ITEM.Where(c => c.TAG_ID == dbTag.ID).FirstOrDefault(); if (tagItem == null) { var newTagItem = new TAG_ITEM(); newTagItem.TAG_ID = dbTag.ID; newTagItem.LEAD_ID = dbLead.ID; db.TAG_ITEM.Add(newTagItem); db.SaveChanges(); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added to lead"; notifyModel.content = $"Tag '{tagName}' has been added to lead {dbLead.Name}."; notifyModel.module = "leads"; notifyModel.moduleObjectId = dbLead.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { dbLead.Owner }); return(true); } else { return(false); } } else { var newTag = _tagRepository.Create(tagName); var tagItem = new TAG_ITEM(); tagItem.TAG_ID = newTag.ID; tagItem.LEAD_ID = dbLead.ID; db.TAG_ITEM.Add(tagItem); db.SaveChanges(); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added to lead"; notifyModel.content = $"Tag '{tagName}' has been added to lead {dbLead.Name}."; notifyModel.module = "leads"; notifyModel.moduleObjectId = dbLead.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { dbLead.Owner }); return(true); } } else { return(false); } }
public bool RemoveTag(int id, int tagId) { var dbLead = db.LEADs.Find(id); if (dbLead != null) { var tagItem = dbLead.TAG_ITEM.Where(c => c.TAG.ID == tagId).FirstOrDefault(); if (tagItem != null) { var tagName = tagItem.TAG.Name; db.TAG_ITEM.Remove(tagItem); db.SaveChanges(); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag removed"; notifyModel.content = $"Tag '{tagName}' has been removed from lead {dbLead.Name}."; notifyModel.module = "leads"; notifyModel.moduleObjectId = dbLead.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { dbLead.Owner }); return(true); } else { return(false); } } else { return(false); } }
public bool RemoveTag(int id, int tagId) { var dbCampaign = db.CAMPAIGNs.Find(id); if (dbCampaign != null) { var tagItem = dbCampaign.TAG_ITEM.Where(c => c.TAG.ID == tagId).FirstOrDefault(); if (tagItem != null) { var tagName = tagItem.TAG.Name; db.TAG_ITEM.Remove(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag removed"; notifyModel.content = $"Tag {tagName} has been removed from campaign {dbCampaign.Name}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { return(false); } } else { return(false); } }
public bool Delete(int id) { var dbContact = db.CONTACTs.Find(id); if (dbContact != null) { var contactName = dbContact.Name; var owner = db.USERs.Find(dbContact.ContactOwner); var collaborator = db.USERs.Find(dbContact.ContactCollaborator); db.CONTACTs.Remove(dbContact); db.SaveChanges(); var notifyModel = new NotificationApiModel(); notifyModel.title = "Contact deleted"; notifyModel.content = $"Contact {contactName} has been deleted."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator }); return(true); } else { return(false); } }
public bool Delete(int id) { var dbCampaign = db.CAMPAIGNs.Find(id); if (dbCampaign != null) { var campaignName = dbCampaign.Name; var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); db.CAMPAIGNs.Remove(dbCampaign); db.SaveChanges(); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign deleted"; notifyModel.content = $"Campaign {campaignName} has been deleted."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { return(false); } }
public bool Delete(int id, int userId) { var dbLead = db.LEADs.Find(id); var dbUser = db.USERs.Find(userId); if (dbLead != null) { var dbAccount = db.ACCOUNTs.Where(c => c.ConvertFrom == dbLead.ID).ToList(); foreach (var account in dbAccount) { account.ConvertFrom = null; } var owner = dbLead.Owner; var creator = dbLead.CreatedUser; var deletedLead = db.LEADs.Remove(dbLead); db.SaveChanges(); //create a notification var apiModel = new NotificationApiModel(); apiModel.title = "Lead removed"; apiModel.content = $"Lead {deletedLead.Name} removed by user {dbUser.Username}."; apiModel.createdAt = DateTime.Now; NotificationManager.SendNotification(apiModel, new List <USER> { owner, creator, dbUser }); return(true); } else { return(false); } }
public bool Update(int campaignId, CampaignCreateApiModel apiModel, int modifiedUser) { var dbCampaign = db.CAMPAIGNs.Find(campaignId); if (dbCampaign != null) { dbCampaign.ActualCost = apiModel.actualCost; dbCampaign.BudgetedCost = apiModel.budgetedCost; if (apiModel.owner != 0) { dbCampaign.CampaignOwner = apiModel.owner; } if (apiModel.status != 0) { dbCampaign.CAMPAIGN_STATUS_ID = apiModel.status; } if (apiModel.type != 0) { dbCampaign.CAMPAIGN_TYPE_ID = apiModel.type; } dbCampaign.Description = apiModel.description; dbCampaign.EmailTitle = apiModel.emailTitle; dbCampaign.EndDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.endDate); dbCampaign.ExpectedResponse = apiModel.expectedResponse; dbCampaign.ExpectedRevenue = apiModel.expectedRevenue; dbCampaign.Name = apiModel.campaignName; dbCampaign.NumberSent = apiModel.numberSent; dbCampaign.StartDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.startDate); dbCampaign.ModifiedAt = DateTime.Now; dbCampaign.ModifiedBy = modifiedUser; db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var modifyUser = db.USERs.Find(modifiedUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign updated"; notifyModel.content = $"Campaign {dbCampaign.Name} has been updated by {modifyUser?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "campaigns"; notifyModel.moduleObjectId = dbCampaign.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { return(false); } }
public bool Update(int accountId, AccountCreateApiModel apiModel, int modifiedUser) { var dbAccount = db.ACCOUNTs.Find(accountId); if (dbAccount != null) { if (apiModel.owner != 0) { dbAccount.AccountOwner = apiModel.owner; } if (apiModel.collaborator != 0) { dbAccount.AccountCollaborator = apiModel.collaborator; } dbAccount.Name = apiModel.name; dbAccount.Email = apiModel.email; dbAccount.Phone = apiModel.phone; dbAccount.Fax = apiModel.fax; dbAccount.TaxCode = apiModel.taxCode; dbAccount.NoEmployees = apiModel.numberOfEmployees; dbAccount.AnnualRevenue = apiModel.annualRevenue; dbAccount.Website = apiModel.website; dbAccount.BankName = apiModel.bankName; dbAccount.BankAccountName = apiModel.bankAccountName; dbAccount.BankAccount = apiModel.bankAccount; dbAccount.Country = apiModel.country; dbAccount.City = apiModel.city; dbAccount.AddressDetail = apiModel.addressDetail; dbAccount.ModifiedAt = DateTime.Now; dbAccount.ModifiedBy = modifiedUser; db.SaveChanges(); var owner = db.USERs.Find(dbAccount.AccountOwner); var collaborator = db.USERs.Find(dbAccount.AccountCollaborator); var modifyUser = db.USERs.Find(modifiedUser); var creator = db.USERs.Find(dbAccount.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Account updated"; notifyModel.content = $"Account {dbAccount.Name} has been updated by {modifyUser.Username}."; notifyModel.module = "accounts"; notifyModel.moduleObjectId = dbAccount.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator, creator }); return(true); } else { return(false); } }
public bool Create(CampaignCreateApiModel apiModel, int createdUser) { var newCampaign = new CAMPAIGN(); newCampaign.ActualCost = apiModel.actualCost; newCampaign.BudgetedCost = apiModel.budgetedCost; newCampaign.CampaignOwner = apiModel.owner != 0 ? apiModel.owner : createdUser; var dbStatus = db.CAMPAIGN_STATUS.Find(apiModel.status); if (dbStatus != null) { newCampaign.CAMPAIGN_STATUS_ID = apiModel.status; } if (db.CAMPAIGN_TYPE.Find(apiModel.type) != null) { newCampaign.CAMPAIGN_TYPE_ID = apiModel.type; } newCampaign.CreatedAt = DateTime.Now; newCampaign.CreatedBy = createdUser; newCampaign.ModifiedAt = DateTime.Now; newCampaign.Description = apiModel.description; newCampaign.EndDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.endDate); newCampaign.ExpectedResponse = apiModel.expectedResponse; newCampaign.ExpectedRevenue = apiModel.expectedRevenue; newCampaign.Name = apiModel.campaignName; newCampaign.NumberSent = apiModel.numberSent; newCampaign.StartDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.startDate); newCampaign.EmailTitle = apiModel.emailTitle; try { db.CAMPAIGNs.Add(newCampaign); db.SaveChanges(); var owner = db.USERs.Find(newCampaign.CampaignOwner); var creator = db.USERs.Find(createdUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign created"; notifyModel.content = $"Campaign {newCampaign.Name} has been created by {creator?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "campaigns"; notifyModel.moduleObjectId = newCampaign.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } catch { return(false); } }
public static void pushNotification(NotificationApiModel notification, List <int> people) { people = people.Distinct().ToList(); foreach (var person in people) { if (person != 0) { var groupName = person.ToString(); var hubContext = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); hubContext.Clients.Group(groupName).pushNotification(notification); } } }
public bool Create(AccountCreateApiModel apiModel, int createdUser) { var newAccount = new ACCOUNT(); newAccount.AccountOwner = apiModel.owner != 0 ? apiModel.owner : createdUser; newAccount.Name = apiModel.name; newAccount.Email = apiModel.email; newAccount.Phone = apiModel.phone; newAccount.Fax = apiModel.fax; newAccount.TaxCode = apiModel.taxCode; newAccount.NoEmployees = apiModel.numberOfEmployees; newAccount.AnnualRevenue = apiModel.annualRevenue; newAccount.Website = apiModel.website; newAccount.BankName = apiModel.bankName; newAccount.BankAccountName = apiModel.bankAccountName; newAccount.BankAccount = apiModel.bankAccount; newAccount.Country = apiModel.country; newAccount.City = apiModel.city; newAccount.AddressDetail = apiModel.addressDetail; newAccount.CreatedAt = DateTime.Now; newAccount.CreatedBy = createdUser; newAccount.ModifiedAt = DateTime.Now; if (apiModel.collaborator != 0) { newAccount.AccountCollaborator = apiModel.collaborator; } try { db.ACCOUNTs.Add(newAccount); db.SaveChanges(); var owner = db.USERs.Find(newAccount.AccountOwner); var collaborator = db.USERs.Find(newAccount.AccountCollaborator); var creator = db.USERs.Find(createdUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Account assigned"; notifyModel.content = $"Account {newAccount.Name} has been created and assigned to you by {creator?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "accounts"; notifyModel.moduleObjectId = newAccount.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator }); return(true); } catch { return(false); } }
public static void SendNotification(NotificationApiModel apiModel, List <USER> users) { var sendTo = users.Distinct().Where(c => c != null).ToList(); var notiCreated = _notificationRepository.Create(apiModel, sendTo); //send notification if (notiCreated.isCreated) { //send to person who performs the delete apiModel.Info(); apiModel.id = notiCreated.notiId; NotificationHub.pushNotification(apiModel, sendTo.Select(c => c.ID).ToList()); } }
public (bool isAdded, string message) AddLead(int id, int leadId, int modifiedUser) { var dbCampaign = db.CAMPAIGNs.Find(id); if (dbCampaign != null) { var dbLead = db.LEADs.Find(leadId); if (dbLead != null) { var lead = dbCampaign.CAMPAIGN_TARGET.Where(c => c.LEAD_ID == dbLead.ID).FirstOrDefault(); if (lead != null) { return(false, "Duplicate lead"); } else { var newTarget = new CAMPAIGN_TARGET(); newTarget.CAMPAIGN_ID = dbCampaign.ID; newTarget.LEAD_ID = leadId; db.CAMPAIGN_TARGET.Add(newTarget); dbCampaign.ModifiedAt = DateTime.Now; dbCampaign.ModifiedBy = modifiedUser; db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var modifyUser = db.USERs.Find(modifiedUser); var leadAdded = db.LEADs.Find(leadId); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign target added"; notifyModel.content = $"Lead {leadAdded.Name} has been added to campaign {dbCampaign.Name} by {modifyUser.Username}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true, SuccessMessages.LEAD_ADDED); } } else { return(false, "Can't find lead"); } } else { return(false, "Can't find campaign"); } }
public bool DeleteContact(int id, int contactId, int modifiedUser) { var dbCampaign = db.CAMPAIGNs.Find(id); if (dbCampaign != null) { var campaignContact = dbCampaign.CAMPAIGN_TARGET.Where(c => c.CONTACT.ID == contactId).FirstOrDefault(); if (campaignContact != null) { var contactName = campaignContact.CONTACT.Name; db.CAMPAIGN_TARGET.Remove(campaignContact); dbCampaign.ModifiedAt = DateTime.Now; dbCampaign.ModifiedBy = modifiedUser; db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var modifyUser = db.USERs.Find(modifiedUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign target removed"; notifyModel.content = $"Contact {contactName} has been removed from campaign {dbCampaign.Name} by {modifyUser.Username}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { return(false); } } else { return(false); } }
public bool RemoveTag(int id, int tagId) { var dbDeal = db.DEALs.Find(id); if (dbDeal != null) { var tagItem = dbDeal.TAG_ITEM.Where(c => c.TAG.ID == tagId).FirstOrDefault(); if (tagItem != null) { var tagName = tagItem.TAG.Name; db.TAG_ITEM.Remove(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag removed"; notifyModel.content = $"Tag {tagName} has been removed from deal {dbDeal.Name}."; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); NotificationManager.ReloadDashboardSale(); return(true); } else { return(false); } } else { return(false); } }
public bool RemoveTag(int id, int tagId) { var dbContact = db.CONTACTs.Find(id); if (dbContact != null) { var tagItem = dbContact.TAG_ITEM.Where(c => c.TAG.ID == tagId).FirstOrDefault(); if (tagItem != null) { var tagName = tagItem.TAG.Name; db.TAG_ITEM.Remove(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbContact.ContactOwner); var collaborator = db.USERs.Find(dbContact.ContactCollaborator); var createdUser = db.USERs.Find(dbContact.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag removed"; notifyModel.content = $"Tag {tagName} has been removed from contact {dbContact.Name}."; notifyModel.module = "contacts"; notifyModel.moduleObjectId = dbContact.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator, createdUser }); return(true); } else { return(false); } } else { return(false); } }
public bool AddTag(int id, string tagName) { var dbDeal = db.DEALs.Find(id); var dbTag = _tagRepository.GetOneByName(tagName); if (dbDeal != null) { if (dbTag != null) { var tagItem = dbDeal.TAG_ITEM.Where(c => c.TAG_ID == dbTag.ID).FirstOrDefault(); if (tagItem == null) { var newTagItem = new TAG_ITEM(); newTagItem.TAG_ID = dbTag.ID; newTagItem.DEAL_ID = dbDeal.ID; db.TAG_ITEM.Add(newTagItem); db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to deal {dbDeal.Name}."; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); NotificationManager.ReloadDashboardSale(); return(true); } else { return(false); } } else { var newTag = _tagRepository.Create(tagName); var tagItem = new TAG_ITEM(); tagItem.TAG_ID = newTag.ID; tagItem.DEAL_ID = dbDeal.ID; db.TAG_ITEM.Add(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to deal {dbDeal.Name}."; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); NotificationManager.ReloadDashboardSale(); return(true); } } else { return(false); } }
public bool AddCompetitor(int id, CompetitorCreateApiModel apiModel) { var dbDeal = db.DEALs.Find(id); if (dbDeal != null && apiModel != null) { var dbCompetitor = db.COMPETITORs.Find(apiModel.id); if (dbCompetitor != null) { var dealCompetitor = dbDeal.DEAL_COMPETITOR.Where(c => c.COMPETITOR_ID == dbCompetitor.ID).FirstOrDefault(); dbCompetitor.Website = apiModel.website; dbCompetitor.Strengths = apiModel.strengths; dbCompetitor.Weaknesses = apiModel.weaknesses; if (dealCompetitor != null) { dealCompetitor.ThreatLevel = apiModel.threat; dealCompetitor.Suggestions = apiModel.suggestions; } else { var newDealCompetitor = new DEAL_COMPETITOR(); newDealCompetitor.DEAL = dbDeal; newDealCompetitor.COMPETITOR = dbCompetitor; newDealCompetitor.Suggestions = apiModel.suggestions; newDealCompetitor.ThreatLevel = apiModel.threat; db.DEAL_COMPETITOR.Add(newDealCompetitor); } db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Competitor added"; notifyModel.content = $"Competitor {dbCompetitor.Name} has been added to deal {dbDeal.Name}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { var newCompetitor = new COMPETITOR(); newCompetitor.Name = apiModel.name; newCompetitor.Strengths = apiModel.strengths; newCompetitor.Weaknesses = apiModel.weaknesses; newCompetitor.Website = apiModel.website; db.COMPETITORs.Add(newCompetitor); var newDealCompetitor = new DEAL_COMPETITOR(); newDealCompetitor.DEAL_ID = dbDeal.ID; newDealCompetitor.COMPETITOR = newCompetitor; newDealCompetitor.Suggestions = apiModel.suggestions; newDealCompetitor.ThreatLevel = apiModel.threat; db.DEAL_COMPETITOR.Add(newDealCompetitor); db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Competitor added"; notifyModel.content = $"Competitor {newCompetitor.Name} has been added to deal {dbDeal.Name}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } } else { return(false); } }
public bool AddTag(int id, string tagName) { var dbContact = db.CONTACTs.Find(id); var dbTag = _tagRepository.GetOneByName(tagName); if (dbContact != null) { if (dbTag != null) { var tagItem = dbContact.TAG_ITEM.Where(c => c.TAG_ID == dbTag.ID).FirstOrDefault(); if (tagItem == null) { var newTagItem = new TAG_ITEM(); newTagItem.TAG_ID = dbTag.ID; newTagItem.CONTACT_ID = dbContact.ID; db.TAG_ITEM.Add(newTagItem); db.SaveChanges(); var owner = db.USERs.Find(dbContact.ContactOwner); var collaborator = db.USERs.Find(dbContact.ContactCollaborator); var createdUser = db.USERs.Find(dbContact.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to contact {dbContact.Name}."; notifyModel.module = "contacts"; notifyModel.moduleObjectId = dbContact.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator, createdUser }); return(true); } else { return(false); } } else { var newTag = _tagRepository.Create(tagName); var tagItem = new TAG_ITEM(); tagItem.TAG_ID = newTag.ID; tagItem.CONTACT_ID = dbContact.ID; db.TAG_ITEM.Add(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbContact.ContactOwner); var collaborator = db.USERs.Find(dbContact.ContactCollaborator); var createdUser = db.USERs.Find(dbContact.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to contact {dbContact.Name}."; notifyModel.module = "contacts"; notifyModel.moduleObjectId = dbContact.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator, createdUser }); return(true); } } else { return(false); } }
public bool Create(ContactCreateApiModel apiModel, int createdUser) { var newContact = new CONTACT(); newContact.ContactOwner = apiModel.owner != 0 ? apiModel.owner : createdUser; if (apiModel.collaborator != 0) { newContact.ContactCollaborator = apiModel.collaborator; } newContact.Name = apiModel.name; newContact.Email = apiModel.email; newContact.Phone = apiModel.phone; newContact.Mobile = apiModel.mobile; newContact.DepartmentName = apiModel.departmentName; newContact.Birthday = apiModel.birthday; if (apiModel.account != 0) { newContact.ACCOUNT_ID = apiModel.account; } if (apiModel.priority != 0) { newContact.PRIORITY_ID = apiModel.priority; } newContact.NoEmail = apiModel.noEmail; newContact.NoCall = apiModel.noCall; newContact.Skype = apiModel.skype; newContact.AssistantName = apiModel.assistantName; newContact.AssistantPhone = apiModel.assistantPhone; newContact.Country = apiModel.country; newContact.City = apiModel.city; newContact.AddressDetail = apiModel.addressDetail; newContact.CreatedAt = DateTime.Now; newContact.CreatedBy = createdUser; newContact.ModifiedAt = DateTime.Now; try { db.CONTACTs.Add(newContact); db.SaveChanges(); var owner = db.USERs.Find(newContact.ContactOwner); var collaborator = db.USERs.Find(newContact.ContactCollaborator); var creator = db.USERs.Find(createdUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Contact assigned"; notifyModel.content = $"Contact {newContact.Name} has been created and assigned to you by {creator?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "contacts"; notifyModel.moduleObjectId = newContact.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, collaborator }); return(true); } catch { return(false); } }
public bool Update(int contactId, ContactCreateApiModel apiModel, int modifiedUser) { var dbContact = db.CONTACTs.Find(contactId); if (dbContact != null) { if (apiModel.owner != 0) { dbContact.ContactOwner = apiModel.owner; } if (apiModel.collaborator != 0) { dbContact.ContactCollaborator = apiModel.collaborator; } dbContact.Name = apiModel.name; dbContact.Email = apiModel.email; dbContact.Phone = apiModel.phone; dbContact.Mobile = apiModel.mobile; dbContact.DepartmentName = apiModel.departmentName; dbContact.Birthday = apiModel.birthday; if (apiModel.priority != 0) { dbContact.PRIORITY_ID = apiModel.priority; } if (apiModel.account != 0) { dbContact.ACCOUNT_ID = apiModel.account; } dbContact.NoEmail = apiModel.noEmail; dbContact.NoCall = apiModel.noCall; dbContact.Skype = apiModel.skype; dbContact.AssistantName = apiModel.assistantName; dbContact.AssistantPhone = apiModel.assistantPhone; dbContact.Country = apiModel.country; dbContact.City = apiModel.city; dbContact.ModifiedAt = DateTime.Now; dbContact.ModifiedBy = modifiedUser; db.SaveChanges(); var modifyUser = db.USERs.Find(modifiedUser); var collaborator = db.USERs.Find(dbContact.ContactCollaborator); var createdUser = db.USERs.Find(dbContact.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Contact updated"; notifyModel.content = $"Contact {dbContact.Name} has been updated by {modifyUser.Username}."; notifyModel.module = "contacts"; notifyModel.moduleObjectId = dbContact.ID; notifyModel.createdAt = DateTime.Now; notifyModel.module = "contacts"; notifyModel.moduleObjectId = dbContact.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { dbContact.Owner, collaborator, createdUser }); return(true); } else { return(false); } }
public LeadConvertApiModel Convert(int id, int convertUser) { var apiModel = new LeadConvertApiModel(); var dbLead = db.LEADs.Find(id); if (dbLead != null) { if (dbLead.Status != null) { if (dbLead.Status.ID != (int)EnumLeadStatus.CONVERTED) { var newAccount = new ACCOUNT(); var newContact = new CONTACT(); if (!String.IsNullOrEmpty(dbLead.CompanyName)) { newAccount.Name = dbLead.CompanyName; } else { newAccount.Name = dbLead.Name; } newAccount.Website = dbLead.Website; newAccount.Email = dbLead.Email; newAccount.AnnualRevenue = dbLead.AnnualRevenue; newAccount.Country = dbLead.Country; newAccount.City = dbLead.City; newAccount.AddressDetail = dbLead.AddressDetail; newAccount.ConvertFrom = dbLead.ID; newAccount.Avatar = dbLead.Avatar; newAccount.Owner = dbLead.Owner; newAccount.CreatedAt = DateTime.Now; if (convertUser != 0) { newAccount.CreatedBy = convertUser; } newAccount.INDUSTRY = dbLead.INDUSTRY; newAccount.Phone = dbLead.Phone; newAccount.Fax = dbLead.Fax; dbLead.LeadStatus = (int)EnumLeadStatus.CONVERTED; newAccount.NOTEs = dbLead.NOTEs; db.ACCOUNTs.Add(newAccount); newContact.Name = dbLead.Name; newContact.NoCall = dbLead.NoCall; newContact.NoEmail = dbLead.NoEmail; newContact.NOTEs = dbLead.NOTEs; newContact.Phone = dbLead.Phone; newContact.Skype = dbLead.Skype; newContact.City = dbLead.City; newContact.Country = dbLead.Country; newContact.AddressDetail = dbLead.AddressDetail; if (dbLead.Owner != null) { newContact.Owner = dbLead.Owner; } newContact.CreatedAt = DateTime.Now; if (convertUser != 0) { newContact.CreatedBy = convertUser; } newContact.ACCOUNT = newAccount; newContact.Avatar = dbLead.Avatar; db.CONTACTs.Add(newContact); db.SaveChanges(); apiModel.newAccountId = newAccount.ID; var notifyModel = new NotificationApiModel(); notifyModel.title = "Lead converted"; notifyModel.content = $"Lead {dbLead.Name} has been converted to account {newAccount.Name}."; notifyModel.module = "accounts"; notifyModel.moduleObjectId = newAccount.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { dbLead.Owner }); return(apiModel); } else { return(null); } } else { var newAccount = new ACCOUNT(); var newContact = new CONTACT(); newAccount.Name = dbLead.CompanyName; newAccount.Website = dbLead.Website; newAccount.Email = dbLead.Email; newAccount.AnnualRevenue = dbLead.AnnualRevenue; newAccount.Country = dbLead.Country; newAccount.City = dbLead.City; newAccount.AddressDetail = dbLead.AddressDetail; newAccount.ConvertFrom = dbLead.ID; newAccount.Avatar = dbLead.Avatar; newAccount.Owner = dbLead.Owner; newAccount.CreatedAt = DateTime.Now; if (convertUser != 0) { newAccount.CreatedBy = convertUser; } newAccount.INDUSTRY = dbLead.INDUSTRY; newAccount.Phone = dbLead.Phone; newAccount.Fax = dbLead.Fax; dbLead.LeadStatus = (int)EnumLeadStatus.CONVERTED; newAccount.NOTEs = dbLead.NOTEs; db.ACCOUNTs.Add(newAccount); newContact.Name = dbLead.Name; newContact.NoCall = dbLead.NoCall; newContact.NoEmail = dbLead.NoEmail; newContact.NOTEs = dbLead.NOTEs; newContact.Phone = dbLead.Phone; newContact.Skype = dbLead.Skype; newContact.City = dbLead.City; newContact.Country = dbLead.Country; newContact.AddressDetail = dbLead.AddressDetail; if (dbLead.Owner != null) { newContact.Owner = dbLead.Owner; } newContact.CreatedAt = DateTime.Now; if (convertUser != 0) { newContact.CreatedBy = convertUser; } newContact.ACCOUNT = newAccount; newContact.Avatar = dbLead.Avatar; db.CONTACTs.Add(newContact); db.SaveChanges(); apiModel.newAccountId = newAccount.ID; var notifyModel = new NotificationApiModel(); notifyModel.title = "Lead converted"; notifyModel.content = $"Lead {dbLead.Name} has been converted to account {newAccount.Name}."; notifyModel.module = "accounts"; notifyModel.moduleObjectId = newAccount.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { dbLead.Owner }); return(apiModel); } } else { return(null); } }
public bool AddTag(int id, string tagName) { var dbCampaign = db.CAMPAIGNs.Find(id); var dbTag = _tagRepository.GetOneByName(tagName); if (dbCampaign != null) { if (dbTag != null) { var tagItem = dbCampaign.TAG_ITEM.Where(c => c.TAG_ID == dbTag.ID).FirstOrDefault(); if (tagItem == null) { var newTagItem = new TAG_ITEM(); newTagItem.TAG_ID = dbTag.ID; newTagItem.CAMPAIGN_ID = dbCampaign.ID; db.TAG_ITEM.Add(newTagItem); db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to campaign {dbCampaign.Name}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } else { return(false); } } else { var newTag = _tagRepository.Create(tagName); var tagItem = new TAG_ITEM(); tagItem.TAG_ID = newTag.ID; tagItem.CAMPAIGN_ID = dbCampaign.ID; db.TAG_ITEM.Add(tagItem); db.SaveChanges(); var owner = db.USERs.Find(dbCampaign.CampaignOwner); var creator = db.USERs.Find(dbCampaign.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Tag added"; notifyModel.content = $"Tag {tagName} has been added to campaign {dbCampaign.Name}."; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } } else { return(false); } }
public bool ChangeStage(int id, int stageId, int modifiedUser) { var dbDeal = db.DEALs.Find(id); var dbStage = db.STAGEs.Find(stageId); if (dbDeal != null && dbStage != null) { var histories = dbDeal.STAGE_HISTORY.OrderByDescending(sh => sh.ModifiedAt); if (histories.Count() > 0) { var current = histories.FirstOrDefault(); if (current.STAGE.ID == stageId) { return(false); } } dbDeal.ExpectedRevenue = (long)((dbDeal.Amount * dbStage.Probability) / 100); var newStageHistory = new STAGE_HISTORY(); newStageHistory.ModifiedBy = modifiedUser; newStageHistory.ModifiedAt = DateTime.Now; newStageHistory.STAGE_ID = stageId; newStageHistory.DEAL_ID = dbDeal.ID; if (stageId == (int)EnumStage.LOST) { dbDeal.isLost = true; dbDeal.ClosingDate = newStageHistory.ModifiedAt; } else { dbDeal.isLost = false; } if (stageId == (int)EnumStage.WON) { dbDeal.ClosingDate = newStageHistory.ModifiedAt; } db.STAGE_HISTORY.Add(newStageHistory); db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var modifyUser = db.USERs.Find(modifiedUser); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Stage updated"; notifyModel.content = $"Deal {dbDeal.Name}'s stage has been updated by {modifyUser?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); NotificationManager.ReloadDashboardSale(); return(true); } else { return(false); } }
public bool Update(int leadId, LeadCreateApiModel apiModel, int modifiedUser) { var dbLead = db.LEADs.Find(leadId); if (dbLead != null) { dbLead.AddressDetail = apiModel.addressDetail; dbLead.AnnualRevenue = apiModel.annualRevenue; dbLead.City = apiModel.city; dbLead.CompanyName = apiModel.companyName; dbLead.Country = apiModel.country; dbLead.ModifiedBy = modifiedUser; dbLead.ModifiedAt = DateTime.Now; dbLead.Description = apiModel.description; dbLead.Email = apiModel.email; dbLead.Fax = apiModel.fax; if (apiModel.industry != 0) { dbLead.INDUSTRY_ID = apiModel.industry; } if (apiModel.leadSource != 0) { dbLead.LeadSource = apiModel.leadSource; } if (apiModel.priority != 0) { dbLead.PRIORITY_ID = apiModel.priority; } dbLead.Name = apiModel.name; dbLead.NoCall = apiModel.noCall; dbLead.NoEmail = apiModel.noEmail; dbLead.Phone = apiModel.phone; dbLead.Skype = apiModel.skype; if (apiModel.leadStatus != 0) { dbLead.LeadStatus = apiModel.leadStatus; } dbLead.Website = apiModel.website; if (apiModel.owner != 0) { dbLead.LeadOwner = apiModel.owner; } db.SaveChanges(); var owner = db.USERs.Find(dbLead.LeadOwner); var modifyUser = db.USERs.Find(modifiedUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Lead modified"; notifyModel.content = $"Lead {dbLead.Name} has been modified by {modifyUser.Username}."; notifyModel.module = "leads"; notifyModel.moduleObjectId = dbLead.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, modifyUser }); return(true); } else { return(false); } }
public bool Create(LeadCreateApiModel apiModel, int createdUser) { var newLead = new LEAD(); newLead.AddressDetail = apiModel.addressDetail; newLead.AnnualRevenue = apiModel.annualRevenue; newLead.City = apiModel.city; newLead.CompanyName = apiModel.companyName; newLead.Country = apiModel.country; newLead.CreatedAt = DateTime.Now; newLead.CreatedBy = createdUser; newLead.ModifiedAt = DateTime.Now; newLead.Description = apiModel.description; newLead.Email = apiModel.email; newLead.Fax = apiModel.fax; var dbIndustry = db.INDUSTRies.Find(apiModel.industry); if (dbIndustry != null) { newLead.INDUSTRY = dbIndustry; } newLead.LeadOwner = apiModel.owner != 0 ? apiModel.owner : createdUser; var dbLeadSource = db.LEAD_SOURCE.Find(apiModel.leadSource); if (dbLeadSource != null) { newLead.LEAD_SOURCE = dbLeadSource; } var dbLeadStatus = db.LEAD_STATUS.Find(apiModel.leadStatus); if (dbLeadStatus != null) { newLead.Status = dbLeadStatus; } newLead.Name = apiModel.name; newLead.NoCall = apiModel.noCall; newLead.NoEmail = apiModel.noEmail; newLead.Phone = apiModel.phone; var dbPriority = db.PRIORITies.Find(apiModel.priority); if (dbPriority != null) { newLead.PRIORITY_ID = apiModel.priority; } newLead.Skype = apiModel.skype; newLead.Website = apiModel.website; try { db.LEADs.Add(newLead); db.SaveChanges(); var owner = db.USERs.Find(newLead.LeadOwner); var notifyModel = new NotificationApiModel(); notifyModel.title = "Lead assigned"; notifyModel.content = $"Lead {newLead.Name} has been created and assigned to you."; notifyModel.module = "leads"; notifyModel.moduleObjectId = newLead.ID; notifyModel.createdAt = DateTime.Now; NotificationManager.SendNotification(notifyModel, new List <USER> { owner }); return(true); } catch { return(false); } }
internal ApiResultNotificationApiModel(NotificationApiModel data) { Data = data; }
public bool Update(int dealId, DealCreateApiModel apiModel, int modifiedUser) { var dbDeal = db.DEALs.Find(dealId); if (dbDeal != null) { if (apiModel.account != 0) { dbDeal.ACCOUNT_ID = apiModel.account; } dbDeal.Amount = apiModel.amount; if (apiModel.closingDate != null) { dbDeal.ClosingDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.closingDate.Value); } if (apiModel.expectedClosingDate != null) { dbDeal.ExpectedClosingDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.expectedClosingDate.Value); } if (apiModel.contact != 0) { dbDeal.Contact_ID = apiModel.contact; } if (apiModel.owner != 0) { dbDeal.DealOwner = apiModel.owner; } dbDeal.Description = apiModel.description; dbDeal.ExpectedRevenue = apiModel.expectedRevenue; if (apiModel.stage != 0) { var dbStage = db.STAGEs.Find(apiModel.stage); dbDeal.ExpectedRevenue = (long)((apiModel.amount * dbStage.Probability) / 100); var newStageHistory = new STAGE_HISTORY(); newStageHistory.ModifiedBy = modifiedUser; newStageHistory.ModifiedAt = DateTime.Now; newStageHistory.STAGE_ID = apiModel.stage; if (apiModel.stage == (int)EnumStage.LOST) { dbDeal.isLost = true; dbDeal.ClosingDate = newStageHistory.ModifiedAt; } else { dbDeal.isLost = false; } if (apiModel.stage == (int)EnumStage.WON) { dbDeal.ClosingDate = newStageHistory.ModifiedAt; } dbDeal.STAGE_HISTORY.Add(newStageHistory); if (!String.IsNullOrEmpty(apiModel.lostReason)) { //find lost reason var lostReason = db.LOST_REASON.Where(c => c.Reason.ToLower().Contains(apiModel.lostReason.ToLower())).FirstOrDefault(); if (lostReason == null) { var newLostReason = new LOST_REASON(); newLostReason.Reason = apiModel.lostReason; db.LOST_REASON.Add(newLostReason); dbDeal.LOST_REASON = newLostReason; //newLostReason.DEALs.Add(dbDeal); } else { dbDeal.LOST_REASON_ID = lostReason.ID; //lostReason.DEALs.Add(dbDeal); } //dbDeal.LOST_REASON_ID = apiModel.lostReason; } } dbDeal.Name = apiModel.name; if (apiModel.priority != 0) { dbDeal.PRIORITY_ID = apiModel.priority; } if (apiModel.campaign != 0) { dbDeal.CAMPAIGN_ID = apiModel.campaign; } if (apiModel.contact != 0) { dbDeal.Contact_ID = apiModel.contact; } dbDeal.ModifiedAt = DateTime.Now; dbDeal.ModifiedBy = modifiedUser; db.SaveChanges(); var owner = db.USERs.Find(dbDeal.DealOwner); var modifyUser = db.USERs.Find(modifiedUser); var creator = db.USERs.Find(dbDeal.CreatedBy); var notifyModel = new NotificationApiModel(); notifyModel.title = "Deal updated"; notifyModel.content = $"Deal {dbDeal.Name} has been updated by {modifyUser?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "deals"; notifyModel.moduleObjectId = dbDeal.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); NotificationManager.ReloadDashboardSale(); return(true); } else { return(false); } }