public override int CreateNewDeal(Deal deal) { deal.ID = base.CreateNewDeal(deal); _dealCache.Add(deal.ID.ToString(), deal); return deal.ID; }
public static void Deal(Deal deal, String actionText, int actionType, int businessValue) { UserActivityPublisher.Publish<TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue) { ContentID = deal.ID.ToString(), Title = deal.Title, SecurityId = String.Format(SecurityDataPattern, (int)EntityType.Opportunity, deal.SecurityId), URL = String.Concat(VirtualPathUtility.ToAbsolute(PathProvider.BaseVirtualPath + "deals.aspx"), String.Format("?id={0}", deal.ID)) }); }
public OpportunityWrapper(Deal deal) : base(deal.ID) { CreateBy = EmployeeWraper.Get(deal.CreateBy); Created = (ApiDateTime)deal.CreateOn; Title = deal.Title; Description = deal.Description; Responsible = EmployeeWraper.Get(deal.ResponsibleID); BidType = deal.BidType; BidValue = deal.BidValue; PerPeriodValue = deal.PerPeriodValue; SuccessProbability = deal.DealMilestoneProbability; ActualCloseDate = (ApiDateTime)deal.ActualCloseDate; ExpectedCloseDate = (ApiDateTime)deal.ExpectedCloseDate; CanEdit = CRMSecurity.CanEdit(deal); }
protected void ExecDealDetailsView(Deal targetDeal) { if (!CRMSecurity.CanAccessTo(targetDeal)) Response.Redirect(PathProvider.StartURL()); var dealActionViewControl = (DealDetailsView)LoadControl(DealDetailsView.Location); dealActionViewControl.TargetDeal = targetDeal; CommonContainerHolder.Controls.Add(dealActionViewControl); var headerTitle = targetDeal.Title.HtmlEncode(); Master.CurrentPageCaption = headerTitle; Master.CommonContainerHeader = Global.RenderItemHeaderWithMenu(headerTitle, EntityType.Opportunity, CRMSecurity.IsPrivate(targetDeal)); Title = HeaderStringHelper.GetPageTitle(headerTitle); }
protected void ExecDealDetailsView(Deal targetDeal) { if (!CRMSecurity.CanAccessTo(targetDeal)) Response.Redirect(PathProvider.StartURL()); var dealActionViewControl = (DealDetailsView) LoadControl(DealDetailsView.Location); dealActionViewControl.TargetDeal = targetDeal; Master.DisabledSidePanel = true; Master.BreadCrumbs.Add(new BreadCrumb { Caption = CRMDealResource.AllDeals, NavigationUrl = "deals.aspx" }); var currentPageTitle = targetDeal.Title; if (targetDeal.ContactID > 0) { var contact = Global.DaoFactory.GetContactDao().GetByID(targetDeal.ContactID); if (contact != null) currentPageTitle = String.Format("{0}: {1}", contact.GetTitle(), targetDeal.Title); } Master.BreadCrumbs.Add(new BreadCrumb { Caption = currentPageTitle }); if (CRMSecurity.IsPrivate(targetDeal)) Master.CommonContainerHeader = Global.RenderPrivateItemHeader(currentPageTitle.HtmlEncode(), EntityType.Opportunity, targetDeal.ID); CommonContainerHolder.Controls.Add(dealActionViewControl); Title = HeaderStringHelper.GetPageTitle(String.Format("{0}: {1}", currentPageTitle.HtmlEncode(), targetDeal.Title.HtmlEncode()), Master.BreadCrumbs); }
public void SendAutoReminderAboutTask(DateTime scheduleDate) { using var scope = _serviceProvider.CreateScope(); var defaultDao = scope.ServiceProvider.GetService <DaoFactory>(); var tenantManager = scope.ServiceProvider.GetService <TenantManager>(); var userManager = scope.ServiceProvider.GetService <UserManager>(); var securityContext = scope.ServiceProvider.GetService <SecurityContext>(); var paymentManager = scope.ServiceProvider.GetService <PaymentManager>(); var logger = scope.ServiceProvider.GetService <IOptionsMonitor <ILog> >().Get("ASC.CRM"); var coreSettings = scope.ServiceProvider.GetService <CoreSettings>(); var execAlert = new List <int>(); foreach (var row in defaultDao.GetTaskDao() .GetInfoForReminder(scheduleDate)) { var tenantId = Convert.ToInt32(row[0]); var taskId = Convert.ToInt32(row[1]); var deadline = Convert.ToDateTime(row[2]); var alertValue = Convert.ToInt32(row[3]); var responsibleID = !string.IsNullOrEmpty(Convert.ToString(row[4])) ? new Guid(Convert.ToString(row[4])) : Guid.Empty; var deadlineReminderDate = deadline.AddMinutes(-alertValue); if (deadlineReminderDate.Subtract(scheduleDate).Minutes > 1) { continue; } execAlert.Add(taskId); var tenant = tenantManager.GetTenant(tenantId); if (tenant == null || tenant.Status != TenantStatus.Active || TariffState.NotPaid <= paymentManager.GetTariff(tenant.TenantId).State) { continue; } try { tenantManager.SetCurrentTenant(tenant); securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem); var user = userManager.GetUsers(responsibleID); if (!(!Constants.LostUser.Equals(user) && user.Status == EmployeeStatus.Active)) { continue; } securityContext.AuthenticateMeWithoutCookie(user.ID); Thread.CurrentThread.CurrentCulture = user.GetCulture(); Thread.CurrentThread.CurrentUICulture = user.GetCulture(); var dao = defaultDao; var task = dao.GetTaskDao().GetByID(taskId); if (task == null) { continue; } ASC.CRM.Core.Entities.Contact taskContact = null; ASC.CRM.Core.Entities.Cases taskCase = null; ASC.CRM.Core.Entities.Deal taskDeal = null; if (task.ContactID > 0) { taskContact = dao.GetContactDao().GetByID(task.ContactID); } if (task.EntityID > 0) { switch (task.EntityType) { case EntityType.Case: taskCase = dao.GetCasesDao().GetByID(task.EntityID); break; case EntityType.Opportunity: taskDeal = dao.GetDealDao().GetByID(task.EntityID); break; } } var listItem = dao.GetListItemDao().GetByID(task.CategoryID); SendTaskReminder(task, listItem != null ? listItem.Title : string.Empty, taskContact, taskCase, taskDeal); } catch (Exception ex) { logger.Error("SendAutoReminderAboutTask, tenant: " + tenant.GetTenantDomain(coreSettings), ex); } } defaultDao.GetTaskDao().ExecAlert(execAlert); }
protected void SaveOrUpdateDeal(Object sender, CommandEventArgs e) { int dealID; var deal = new Deal { Title = Request["nameDeal"], Description = Request["descriptionDeal"], DealMilestoneID = Convert.ToInt32(Request["dealMilestone"]) }; int contactID; if (int.TryParse(Request["selectedContactID"], out contactID)) deal.ContactID = contactID; int probability; if (int.TryParse(Request["probability"], out probability)) deal.DealMilestoneProbability = probability; deal.BidCurrency = Request["bidCurrency"]; if (String.IsNullOrEmpty(deal.BidCurrency)) deal.BidCurrency = Global.TenantSettings.DefaultCurrency.Abbreviation; if (!String.IsNullOrEmpty(Request["bidValue"])) { decimal bidValue; if (!decimal.TryParse(Request["bidValue"], out bidValue)) bidValue = 0; deal.BidValue = bidValue; deal.BidType = (BidType)Enum.Parse(typeof(BidType), Request["bidType"]); if (deal.BidType != BidType.FixedBid) { int perPeriodValue; if (int.TryParse(Request["perPeriodValue"], out perPeriodValue)) deal.PerPeriodValue = perPeriodValue; } } else { deal.BidValue = 0; deal.BidType = BidType.FixedBid; } DateTime expectedCloseDate; if (!DateTime.TryParse(Request["expectedCloseDate"], out expectedCloseDate)) expectedCloseDate = DateTime.MinValue; deal.ExpectedCloseDate = expectedCloseDate; deal.ResponsibleID = new Guid(Request["responsibleID"]); var dealMilestone = Global.DaoFactory.GetDealMilestoneDao().GetByID(deal.DealMilestoneID); if (TargetDeal == null) { if (dealMilestone.Status != DealMilestoneStatus.Open) deal.ActualCloseDate = TenantUtil.DateTimeNow(); dealID = Global.DaoFactory.GetDealDao().CreateNewDeal(deal); deal.ID = dealID; deal.CreateBy = SecurityContext.CurrentAccount.ID; deal.CreateOn = TenantUtil.DateTimeNow(); deal = Global.DaoFactory.GetDealDao().GetByID(dealID); SetPermission(deal); if (deal.ResponsibleID != Guid.Empty && deal.ResponsibleID != SecurityContext.CurrentAccount.ID) NotifyClient.Instance.SendAboutResponsibleForOpportunity(deal); } else { dealID = TargetDeal.ID; deal.ID = TargetDeal.ID; deal.ActualCloseDate = TargetDeal.ActualCloseDate; if (TargetDeal.ResponsibleID != Guid.Empty && TargetDeal.ResponsibleID != deal.ResponsibleID) NotifyClient.Instance.SendAboutResponsibleForOpportunity(deal); if (TargetDeal.DealMilestoneID != deal.DealMilestoneID) deal.ActualCloseDate = dealMilestone.Status != DealMilestoneStatus.Open ? TenantUtil.DateTimeNow() : DateTime.MinValue; Global.DaoFactory.GetDealDao().EditDeal(deal); deal = Global.DaoFactory.GetDealDao().GetByID(dealID); SetPermission(deal); } var dealMembers = !String.IsNullOrEmpty(Request["selectedMembersID"]) ? Request["selectedMembersID"].Split(new[] { ',' }).Select( id => Convert.ToInt32(id)).Where(id => id != deal.ContactID).ToList() : new List<int>(); if (deal.ContactID > 0 && !dealMembers.Contains(deal.ContactID)) dealMembers.Add(deal.ContactID); Global.DaoFactory.GetDealDao().SetMembers(dealID, dealMembers.ToArray()); foreach (var customField in Request.Form.AllKeys) { if (!customField.StartsWith("customField_")) continue; var fieldID = Convert.ToInt32(customField.Split('_')[1]); var fieldValue = Request.Form[customField]; if (String.IsNullOrEmpty(fieldValue) && TargetDeal == null) continue; Global.DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Opportunity, dealID, fieldID, fieldValue); } if (TargetDeal == null && UrlParameters.ContactID != 0) Response.Redirect(String.Format("default.aspx?id={0}#deals", UrlParameters.ContactID)); Response.Redirect(String.Compare(e.CommandArgument.ToString(), "0", true) == 0 ? String.Format("deals.aspx?id={0}", dealID) : "deals.aspx?action=manage"); }
public static bool CanEdit(Deal deal) { return (IsAdmin || deal.ResponsibleID == SecurityContext.CurrentAccount.ID || deal.CreateBy == SecurityContext.CurrentAccount.ID || !CRMSecurity.IsPrivate(deal) || GetAccessSubjectTo(deal).ContainsKey(SecurityContext.CurrentAccount.ID)); }
public static void DemandAccessTo(Deal deal) { if (!CanAccessTo(deal)) throw CreateSecurityException(); }
public static Dictionary<Guid, string> GetAccessSubjectTo(Deal deal) { return GetAccessSubjectTo((ISecurityObjectId)deal); }
public static void MakePublic(Deal deal) { MakePublic((ISecurityObjectId)deal); }
public static bool CanAccessTo(Deal deal) { return CanAccessTo((ISecurityObjectId)deal); }
private void ImportOpportunityData() { var allUsers = ASC.Core.CoreContext.UserManager.GetUsers(EmployeeStatus.All).ToList(); using (var CSVFileStream = _dataStore.GetReadStream("temp", _CSVFileURI)) using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings)) { int currentIndex = 0; var customFieldDao = _daoFactory.GetCustomFieldDao(); var contactDao = _daoFactory.GetContactDao(); var tagDao = _daoFactory.GetTagDao(); var dealDao = _daoFactory.GetDealDao(); var dealMilestoneDao = _daoFactory.GetDealMilestoneDao(); var findedTags = new Dictionary<int, List<String>>(); var findedCustomField = new List<CustomField>(); var findedDeals = new List<Deal>(); var findedDealMembers = new Dictionary<int, List<int>>(); var dealMilestones = dealMilestoneDao.GetAll(); while (csv.ReadNextRecord()) { _columns = csv.GetCurrentRowFields(false); var obj = new Deal(); obj.ID = currentIndex; obj.Title = GetPropertyValue("title"); if (String.IsNullOrEmpty(obj.Title)) continue; obj.Description = GetPropertyValue("description"); var csvResponsibleValue = GetPropertyValue("responsible"); var responsible = allUsers.Where(n => n.DisplayUserName().Equals(csvResponsibleValue)).FirstOrDefault(); if (responsible != null) obj.ResponsibleID = responsible.ID; else obj.ResponsibleID = Constants.LostUser.ID; DateTime actualCloseDate; DateTime expectedCloseDate; if (DateTime.TryParse(GetPropertyValue("actual_close_date"), out actualCloseDate)) obj.ActualCloseDate = actualCloseDate; if (DateTime.TryParse(GetPropertyValue("expected_close_date"), out expectedCloseDate)) obj.ExpectedCloseDate = expectedCloseDate; var currency = CurrencyProvider.Get(GetPropertyValue("bid_currency")); if (currency != null) obj.BidCurrency = currency.Abbreviation; else obj.BidCurrency = Global.TenantSettings.DefaultCurrency.Abbreviation; decimal bidValue; var bidValueStr = GetPropertyValue("bid_amount"); if (Decimal.TryParse(bidValueStr, out bidValue)) obj.BidValue = bidValue; else obj.BidValue = 0; var bidTypeStr = GetPropertyValue("bid_type"); BidType bidType = BidType.FixedBid; if (!String.IsNullOrEmpty(bidTypeStr)) { if (String.Compare(CRMDealResource.BidType_FixedBid, bidTypeStr, true) == 0) bidType = BidType.FixedBid; else if (String.Compare(CRMDealResource.BidType_PerDay, bidTypeStr, true) == 0) bidType = BidType.PerDay; else if (String.Compare(CRMDealResource.BidType_PerHour, bidTypeStr, true) == 0) bidType = BidType.PerHour; else if (String.Compare(CRMDealResource.BidType_PerMonth, bidTypeStr, true) == 0) bidType = BidType.PerMonth; else if (String.Compare(CRMDealResource.BidType_PerWeek, bidTypeStr, true) == 0) bidType = BidType.PerWeek; else if (String.Compare(CRMDealResource.BidType_PerYear, bidTypeStr, true) == 0) bidType = BidType.PerYear; } obj.BidType = bidType; if (obj.BidType != BidType.FixedBid) { int perPeriodValue; if (int.TryParse(GetPropertyValue("per_period_value"), out perPeriodValue)) obj.PerPeriodValue = perPeriodValue; } int probabilityOfWinning; if (int.TryParse(GetPropertyValue("probability_of_winning"), out probabilityOfWinning)) obj.DealMilestoneProbability = probabilityOfWinning; var dealMilestoneTitle = GetPropertyValue("deal_milestone"); var tag = GetPropertyValue("tag"); if (!String.IsNullOrEmpty(tag)) findedTags.Add(obj.ID, tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()); if (String.IsNullOrEmpty(dealMilestoneTitle)) obj.DealMilestoneID = dealMilestones[0].ID; else { var dealMilestone = dealMilestones.Find(item => String.Compare(item.Title, dealMilestoneTitle, true) == 0); if (dealMilestone == null) obj.DealMilestoneID = dealMilestones[0].ID; else obj.DealMilestoneID = dealMilestone.ID; } var contactName = GetPropertyValue("client"); var localMembersDeal = new List<int>(); if (!String.IsNullOrEmpty(contactName)) { var contacts = contactDao.GetContactsByName(contactName); if (contacts.Count > 0) { obj.ContactID = contacts[0].ID; localMembersDeal.Add(obj.ContactID); } } var members = GetPropertyValue("member"); if (!String.IsNullOrEmpty(members)) { var membersList = members.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in membersList) { var findedMember = contactDao.GetContactsByName(item); if (findedMember.Count > 0) localMembersDeal.Add(findedMember[0].ID); } } if (localMembersDeal.Count > 0) findedDealMembers.Add(obj.ID, localMembersDeal); foreach (JProperty jToken in _importSettings.ColumnMapping.Children()) { var propertyValue = GetPropertyValue(jToken.Name); if (String.IsNullOrEmpty(propertyValue)) continue; if (!jToken.Name.StartsWith("customField_")) continue; var fieldID = Convert.ToInt32(jToken.Name.Split(new[] { '_' })[1]); findedCustomField.Add(new CustomField { EntityID = obj.ID, EntityType = EntityType.Opportunity, ID = fieldID, Value = propertyValue }); } Percentage += 1.0 * 100 / (ImportFromCSV.MaxRoxCount * 2); findedDeals.Add(obj); if (currentIndex + 1 > ImportFromCSV.MaxRoxCount) break; currentIndex++; } Percentage = 50; var newDealIDs = dealDao.SaveDealList(findedDeals); Percentage += 12.5; findedCustomField.ForEach(item => item.EntityID = newDealIDs[item.EntityID]); customFieldDao.SaveList(findedCustomField); Percentage += 12.5; foreach (var findedDealMemberKey in findedDealMembers.Keys) { dealDao.SetMembers(newDealIDs[findedDealMemberKey], findedDealMembers[findedDealMemberKey].ToArray()); } Percentage += 12.5; foreach (var findedTagKey in findedTags.Keys) { tagDao.SetTagToEntity(EntityType.Opportunity, newDealIDs[findedTagKey], findedTags[findedTagKey].ToArray()); } if (_importSettings.IsPrivate) findedDeals.ForEach(dealItem => CRMSecurity.SetAccessTo(dealItem, _importSettings.AccessList)); Percentage += 12.5; } Complete(); }
public static void DemandCreateOrUpdate(Deal deal) { if (string.IsNullOrEmpty(deal.Title) || deal.ResponsibleID == Guid.Empty || deal.DealMilestoneID <= 0 || string.IsNullOrEmpty(deal.BidCurrency)) throw new ArgumentException(); var listItem = Global.DaoFactory.GetDealMilestoneDao().GetByID(deal.DealMilestoneID); if (listItem == null) throw new ArgumentException("Deal milestone is not found"); if (deal.ContactID != 0) { var contact = Global.DaoFactory.GetContactDao().GetByID(deal.ContactID); if (contact == null) throw new ArgumentException(); CRMSecurity.DemandAccessTo(contact); } if (string.IsNullOrEmpty(deal.BidCurrency)) { throw new ArgumentException(); } else { if (CurrencyProvider.Get(deal.BidCurrency.ToUpper()) == null) { throw new ArgumentException(); } } }
public static void DemandDelete(Deal deal) { if (!CanDelete(deal)) throw CreateSecurityException(); }
public static void DemandEdit(Deal deal) { if (!CanEdit(deal)) throw CreateSecurityException(); }
public static bool CanDelete(Deal deal) { return CanEdit(deal); }
public override void EditDeal(Deal deal) { ResetCache(deal.ID); base.EditDeal(deal); }
public void SendTaskReminder(Task task, String taskCategoryTitle, Contact taskContact, ASC.CRM.Core.Entities.Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal) { var recipient = ToRecipient(task.ResponsibleID); if (recipient == null) { return; } var deadLineString = task.DeadLine.Hour == 0 && task.DeadLine.Minute == 0 ? task.DeadLine.ToShortDateString() : task.DeadLine.ToString(CultureInfo.InvariantCulture); string taskContactRelativeUrl = null; string taskContactTitle = null; string taskCaseRelativeUrl = null; string taskCaseTitle = null; string taskDealRelativeUrl = null; string taskDealTitle = null; if (taskContact != null) { taskContactRelativeUrl = String.Format("Products/CRM/Default.aspx?id={0}{1}", taskContact.ID, taskContact is Person ? "&type=people" : ""); taskContactTitle = taskContact.GetTitle(); } if (taskCase != null) { taskCaseRelativeUrl = String.Format("Products/CRM/Cases.aspx?id={0}", taskCase.ID); taskCaseTitle = taskCase.Title.HtmlEncode(); } if (taskDeal != null) { taskDealRelativeUrl = String.Format("Products/CRM/Deals.aspx?id={0}", taskDeal.ID); taskDealTitle = taskDeal.Title.HtmlEncode(); } client.SendNoticeToAsync( NotifyConstants.Event_TaskReminder, null, new[] { recipient }, true, new TagValue(NotifyConstants.Tag_EntityTitle, task.Title), new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "TaskDescription", HttpUtility.HtmlEncode(task.Description) }, { "TaskCategory", taskCategoryTitle }, { "ContactRelativeUrl", taskContactRelativeUrl }, { "ContactTitle", taskContactTitle }, { "CaseRelativeUrl", taskCaseRelativeUrl }, { "CaseTitle", taskCaseTitle }, { "DealRelativeUrl", taskDealRelativeUrl }, { "DealTitle", taskDealTitle }, { "DueDate", deadLineString } }) ); }
protected void ExecDealActionView(Deal targetDeal) { var dealActionViewControl = (DealActionView)LoadControl(DealActionView.Location); dealActionViewControl.TargetDeal = targetDeal; CommonContainerHolder.Controls.Add(dealActionViewControl); var headerTitle = targetDeal == null ? CRMDealResource.CreateNewDeal : String.Format(CRMDealResource.EditDealLabel, targetDeal.Title); Master.CurrentPageCaption = headerTitle; Title = HeaderStringHelper.GetPageTitle(headerTitle); }
public static void SetAccessTo(Deal deal, List<Guid> subjectID) { SetAccessTo((ISecurityObjectId)deal, subjectID); }
protected void SaveOrUpdateDeal(Object sender, CommandEventArgs e) { var dao = Global.DaoFactory; int dealID; var _isPrivate = false; var _selectedUsersWithoutCurUsr = new List<Guid>(); #region BaseInfo var deal = new Deal { Title = Request["nameDeal"], Description = Request["descriptionDeal"], DealMilestoneID = Convert.ToInt32(Request["dealMilestone"]) }; int contactID; if (int.TryParse(Request["selectedContactID"], out contactID)) deal.ContactID = contactID; int probability; if (int.TryParse(Request["probability"], out probability)) deal.DealMilestoneProbability = probability; if (deal.DealMilestoneProbability < 0) deal.DealMilestoneProbability = 0; if (deal.DealMilestoneProbability > 100) deal.DealMilestoneProbability = 100; deal.BidCurrency = Request["bidCurrency"]; if (String.IsNullOrEmpty(deal.BidCurrency)) deal.BidCurrency = Global.TenantSettings.DefaultCurrency.Abbreviation; else deal.BidCurrency = deal.BidCurrency.ToUpper(); if (!String.IsNullOrEmpty(Request["bidValue"])) { decimal bidValue; if (!decimal.TryParse(Request["bidValue"], out bidValue)) bidValue = 0; deal.BidValue = bidValue; deal.BidType = (BidType)Enum.Parse(typeof(BidType), Request["bidType"]); if (deal.BidType != BidType.FixedBid) { int perPeriodValue; if (int.TryParse(Request["perPeriodValue"], out perPeriodValue)) deal.PerPeriodValue = perPeriodValue; } } else { deal.BidValue = 0; deal.BidType = BidType.FixedBid; } DateTime expectedCloseDate; if (!DateTime.TryParse(Request["expectedCloseDate"], out expectedCloseDate)) expectedCloseDate = DateTime.MinValue; deal.ExpectedCloseDate = expectedCloseDate; deal.ResponsibleID = new Guid(Request["responsibleID"]); #endregion #region Validation CRMSecurity.DemandCreateOrUpdate(deal); if (HavePermission) { var CurrentAccountID = SecurityContext.CurrentAccount.ID; bool value; if (bool.TryParse(Request.Form["isPrivateDeal"], out value)) { _isPrivate = value; } if (_isPrivate) { _selectedUsersWithoutCurUsr = Request.Form["selectedPrivateUsers"] .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(item => new Guid(item)).Where(i => i != CurrentAccountID).Distinct().ToList(); foreach (var uID in _selectedUsersWithoutCurUsr) { var usr = CoreContext.UserManager.GetUsers(uID); if (usr.IsVisitor()) throw new ArgumentException(); } if (deal.ResponsibleID != CurrentAccountID) { _selectedUsersWithoutCurUsr.Add(deal.ResponsibleID); var responsible = CoreContext.UserManager.GetUsers(deal.ResponsibleID); if (responsible.IsVisitor()) throw new ArgumentException("responsible user cannot be visitor"); } } } #endregion var dealMilestone = dao.GetDealMilestoneDao().GetByID(deal.DealMilestoneID); if (TargetDeal == null) { if (dealMilestone.Status != DealMilestoneStatus.Open) deal.ActualCloseDate = TenantUtil.DateTimeNow(); dealID = dao.GetDealDao().CreateNewDeal(deal); deal.ID = dealID; deal.CreateBy = SecurityContext.CurrentAccount.ID; deal.CreateOn = TenantUtil.DateTimeNow(); deal = dao.GetDealDao().GetByID(dealID); SetPermission(deal, _isPrivate, _selectedUsersWithoutCurUsr); if (deal.ResponsibleID != Guid.Empty && deal.ResponsibleID != SecurityContext.CurrentAccount.ID) { NotifyClient.Instance.SendAboutResponsibleForOpportunity(deal); } MessageService.Send(HttpContext.Current.Request, MessageAction.OpportunityCreated, deal.Title); } else { dealID = TargetDeal.ID; deal.ID = TargetDeal.ID; deal.ActualCloseDate = TargetDeal.ActualCloseDate; if (TargetDeal.ResponsibleID != Guid.Empty && TargetDeal.ResponsibleID != deal.ResponsibleID) NotifyClient.Instance.SendAboutResponsibleForOpportunity(deal); if (TargetDeal.DealMilestoneID != deal.DealMilestoneID) deal.ActualCloseDate = dealMilestone.Status != DealMilestoneStatus.Open ? TenantUtil.DateTimeNow() : DateTime.MinValue; dao.GetDealDao().EditDeal(deal); deal = dao.GetDealDao().GetByID(dealID); SetPermission(deal, _isPrivate, _selectedUsersWithoutCurUsr); MessageService.Send(HttpContext.Current.Request, MessageAction.OpportunityUpdated, deal.Title); } #region Members var dealMembers = !String.IsNullOrEmpty(Request["selectedMembersID"]) ? Request["selectedMembersID"].Split(new[] { ',' }).Select( id => Convert.ToInt32(id)).Where(id => id != deal.ContactID).ToList() : new List<int>(); var dealMembersContacts = dao.GetContactDao().GetContacts(dealMembers.ToArray()).Where(CRMSecurity.CanAccessTo).ToList(); dealMembers = dealMembersContacts.Select(m => m.ID).ToList(); if (deal.ContactID > 0) dealMembers.Add(deal.ContactID); dao.GetDealDao().SetMembers(dealID, dealMembers.ToArray()); #endregion #region CustomFields foreach (var customField in Request.Form.AllKeys) { if (!customField.StartsWith("customField_")) continue; var fieldID = Convert.ToInt32(customField.Split('_')[1]); var fieldValue = Request.Form[customField]; if (String.IsNullOrEmpty(fieldValue) && TargetDeal == null) continue; dao.GetCustomFieldDao().SetFieldValue(EntityType.Opportunity, dealID, fieldID, fieldValue); } #endregion if (TargetDeal == null && UrlParameters.ContactID != 0) Response.Redirect(String.Format("default.aspx?id={0}#deals", UrlParameters.ContactID)); Response.Redirect(String.Compare(e.CommandArgument.ToString(), "0", true) == 0 ? String.Format("deals.aspx?id={0}", dealID) : "deals.aspx?action=manage"); }
public static bool IsPrivate(Deal deal) { return IsPrivate((ISecurityObjectId)deal); }
protected void SetPermission(Deal deal, bool isPrivate, List<Guid> selectedUsersWithoutCurUsr) { if (HavePermission) { var notifyPrivateUsers = false; bool value; if (bool.TryParse(Request.Form["notifyPrivateUsers"], out value)) { notifyPrivateUsers = value; } if (isPrivate) { if (notifyPrivateUsers) Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Opportunity, deal.ID, selectedUsersWithoutCurUsr.ToArray()); selectedUsersWithoutCurUsr.Add(SecurityContext.CurrentAccount.ID); CRMSecurity.SetAccessTo(deal, selectedUsersWithoutCurUsr); } else { CRMSecurity.MakePublic(deal); } } }
public static List<Guid> GetAccessSubjectGuidsTo(Deal deal) { return GetAccessSubjectGuidsTo((ISecurityObjectId)deal); }
private static Deal ToDeal(object[] r) { var deal = new Deal { ID = Convert.ToInt32(r[0]), Title = Convert.ToString(r[1]), Description = Convert.ToString(r[2]), ResponsibleID = new Guid(Convert.ToString(r[3])), CreateBy = new Guid(Convert.ToString(r[4])), CreateOn = Convert.ToDateTime(r[5]), LastModifedBy = new Guid(Convert.ToString(r[6])), LastModifedOn = Convert.ToDateTime(r[7]) }; var contactId = Convert.ToInt32(r[8]); if (!string.IsNullOrEmpty(Convert.ToString(r[9]))) { var isCompany = Convert.ToBoolean(r[9]); if (contactId > 0 && isCompany) { deal.Contact = new Company { ID = Convert.ToInt32(r[10]), About = Convert.ToString(r[11]), CompanyName = Convert.ToString(r[14]), CreateBy = new Guid(Convert.ToString(r[17])), CreateOn = Convert.ToDateTime(r[18]), LastModifedBy = new Guid(Convert.ToString(r[19])), LastModifedOn = Convert.ToDateTime(r[20]) }; } else { deal.Contact = new Person { ID = Convert.ToInt32(r[10]), About = Convert.ToString(r[11]), FirstName = Convert.ToString(r[12]), LastName = Convert.ToString(r[13]), CompanyID = Convert.ToInt32(r[15]), JobTitle = Convert.ToString(r[16]), CreateBy = new Guid(Convert.ToString(r[17])), CreateOn = Convert.ToDateTime(r[18]), LastModifedBy = new Guid(Convert.ToString(r[19])), LastModifedOn = Convert.ToDateTime(r[20]) }; } } return deal; }
public void SendAboutResponsibleForOpportunity(Deal deal) { var recipient = ToRecipient(deal.ResponsibleID); if (recipient == null) return; client.SendNoticeToAsync( NotifyConstants.Event_ResponsibleForOpportunity, null, new[] { recipient }, true, new TagValue(NotifyConstants.Tag_EntityTitle, deal.Title), new TagValue(NotifyConstants.Tag_EntityID, deal.ID), new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "OpportunityDescription", HttpUtility.HtmlEncode(deal.Description) } })); }
public static void SendAutoReminderAboutTask(DateTime scheduleDate) { var execAlert = new List <int>(); var defaultDao = new DaoFactory(Tenant.DEFAULT_TENANT, CRMConstants.StorageModule); foreach (var row in defaultDao.GetTaskDao() .GetInfoForReminder(scheduleDate)) { var tenantId = Convert.ToInt32(row[0]); var taskId = Convert.ToInt32(row[1]); var deadline = Convert.ToDateTime(row[2]); var alertValue = Convert.ToInt32(row[3]); var responsibleID = !string.IsNullOrEmpty(Convert.ToString(row[4])) ? new Guid(Convert.ToString(row[4])) : Guid.Empty; var deadlineReminderDate = deadline.AddMinutes(-alertValue); if (deadlineReminderDate.Subtract(scheduleDate).Minutes > 1) { continue; } execAlert.Add(taskId); var tenant = CoreContext.TenantManager.GetTenant(tenantId); if (tenant == null || tenant.Status != TenantStatus.Active || TariffState.NotPaid <= CoreContext.PaymentManager.GetTariff(tenant.TenantId).State) { continue; } try { CoreContext.TenantManager.SetCurrentTenant(tenant); SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); var user = CoreContext.UserManager.GetUsers(responsibleID); if (!(!Constants.LostUser.Equals(user) && user.Status == EmployeeStatus.Active)) { continue; } SecurityContext.AuthenticateMe(user.ID); Thread.CurrentThread.CurrentCulture = user.GetCulture(); Thread.CurrentThread.CurrentUICulture = user.GetCulture(); var dao = new DaoFactory(tenantId, CRMConstants.StorageModule); var task = dao.GetTaskDao().GetByID(taskId); if (task == null) { continue; } ASC.CRM.Core.Entities.Contact taskContact = null; ASC.CRM.Core.Entities.Cases taskCase = null; ASC.CRM.Core.Entities.Deal taskDeal = null; if (task.ContactID > 0) { taskContact = dao.GetContactDao().GetByID(task.ContactID); } if (task.EntityID > 0) { switch (task.EntityType) { case EntityType.Case: taskCase = dao.GetCasesDao().GetByID(task.EntityID); break; case EntityType.Opportunity: taskDeal = dao.GetDealDao().GetByID(task.EntityID); break; } } var listItem = dao.GetListItemDao().GetByID(task.CategoryID); NotifyClient.Instance.SendTaskReminder(task, listItem != null ? listItem.Title : string.Empty, taskContact, taskCase, taskDeal); } catch (Exception ex) { LogManager.GetLogger("ASC.CRM.Tasks").Error("SendAutoReminderAboutTask, tenant: " + tenant.TenantDomain, ex); } } defaultDao.GetTaskDao().ExecAlert(execAlert); }
private Feed ToFeed(Deal deal) { var itemId = "/products/crm/deals.aspx?id=" + deal.ID + "#profile"; return new Feed(deal.CreateBy, deal.CreateOn) { Item = item, ItemId = deal.ID.ToString(CultureInfo.InvariantCulture), ItemUrl = CommonLinkUtility.ToAbsolute(itemId), Product = Product, Module = Name, Title = deal.Title, Description = Helper.GetHtmlDescription(HttpUtility.HtmlEncode(deal.Description)), AdditionalInfo = deal.Contact.GetTitle(), Keywords = string.Format("{0} {1}", deal.Title, deal.Description), HasPreview = false, CanComment = false, GroupId = GetGroupId(item, deal.CreateBy) }; }
public virtual int CreateNewDeal(Deal deal) { using (var db = GetDb()) { return CreateNewDeal(deal, db); } }
public void SendAboutResponsibleByTask(Task task, String taskCategoryTitle, Contact taskContact, ASC.CRM.Core.Entities.Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal, Hashtable fileListInfoHashtable) { var recipient = ToRecipient(task.ResponsibleID); if (recipient == null) { return; } task.DeadLine = TenantUtil.DateTimeFromUtc(task.DeadLine); var deadLineString = task.DeadLine.Hour == 0 && task.DeadLine.Minute == 0 ? task.DeadLine.ToShortDateString() : task.DeadLine.ToString(); string taskContactRelativeUrl = null; string taskContactTitle = null; string taskCaseRelativeUrl = null; string taskCaseTitle = null; string taskDealRelativeUrl = null; string taskDealTitle = null; if (taskContact != null) { taskContactRelativeUrl = String.Format("products/crm/default.aspx?id={0}{1}", taskContact.ID, taskContact is Person ? "&type=people" : ""); taskContactTitle = taskContact.GetTitle(); } if (taskCase != null) { taskCaseRelativeUrl = String.Format("products/crm/cases.aspx?id={0}", taskCase.ID); taskCaseTitle = taskCase.Title.HtmlEncode(); } if (taskDeal != null) { taskDealRelativeUrl = String.Format("products/crm/deals.aspx?id={0}", taskDeal.ID); taskDealTitle = taskDeal.Title.HtmlEncode(); } client.SendNoticeToAsync( NotifyConstants.Event_ResponsibleForTask, null, new[] { recipient }, true, new TagValue(NotifyConstants.Tag_EntityTitle, task.Title), new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "TaskDescription", HttpUtility.HtmlEncode(task.Description) }, { "Files", fileListInfoHashtable }, { "TaskCategory", taskCategoryTitle }, { "ContactRelativeUrl", taskContactRelativeUrl }, { "ContactTitle", taskContactTitle }, { "CaseRelativeUrl", taskCaseRelativeUrl }, { "CaseTitle", taskCaseTitle }, { "DealRelativeUrl", taskDealRelativeUrl }, { "DealTitle", taskDealTitle }, { "DueDate", deadLineString } }) ); }
private int CreateNewDeal(Deal deal, DbManager db) { if (String.IsNullOrEmpty(deal.Title) || deal.ResponsibleID == Guid.Empty || deal.DealMilestoneID <= 0) throw new ArgumentException(); // Delete relative keys _cache.Insert(_dealCacheKey, String.Empty); var dealID = db.ExecuteScalar<int>( Insert("crm_deal") .InColumnValue("id", 0) .InColumnValue("title", deal.Title) .InColumnValue("description", deal.Description) .InColumnValue("responsible_id", deal.ResponsibleID) .InColumnValue("contact_id", deal.ContactID) .InColumnValue("bid_currency", deal.BidCurrency) .InColumnValue("bid_value", deal.BidValue) .InColumnValue("bid_type", deal.BidType) .InColumnValue("deal_milestone_id", deal.DealMilestoneID) .InColumnValue("deal_milestone_probability", deal.DealMilestoneProbability) .InColumnValue("expected_close_date", TenantUtil.DateTimeToUtc(deal.ExpectedCloseDate)) .InColumnValue("actual_close_date", TenantUtil.DateTimeToUtc(deal.ActualCloseDate)) .InColumnValue("per_period_value", deal.PerPeriodValue) .InColumnValue("create_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow())) .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID) .InColumnValue("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow())) .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID) .Identity(1, 0, true)); // if (deal.ContactID > 0) // AddMember(dealID, deal.ContactID); return dealID; }
protected void SetPermission(Deal deal) { if (CRMSecurity.IsAdmin || deal.CreateBy == SecurityContext.CurrentAccount.ID) { var isPrivate = false; var notifyPrivateUsers = false; bool value; if (bool.TryParse(Request.Form["isPrivateDeal"], out value)) { isPrivate = value; } if (bool.TryParse(Request.Form["notifyPrivateUsers"], out value)) { notifyPrivateUsers = value; } if (isPrivate) { var selectedUsers = Request.Form["selectedPrivateUsers"] .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(item => new Guid(item)).ToList(); var responsibleID = new Guid(Request["responsibleID"]); if (responsibleID != SecurityContext.CurrentAccount.ID) { selectedUsers.Add(responsibleID); } if (notifyPrivateUsers) Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Opportunity, deal.ID, selectedUsers.ToArray()); selectedUsers.Add(SecurityContext.CurrentAccount.ID); CRMSecurity.SetAccessTo(deal, selectedUsers); } else { CRMSecurity.MakePublic(deal); } } }
public virtual void EditDeal(Deal deal) { CRMSecurity.DemandEdit(deal); // var oldDeal = GetByID(deal.ID); // if (oldDeal.ContactID > 0) // RemoveMember(oldDeal.ID, oldDeal.ContactID); // AddMember(deal.ID, deal.ContactID); using (var db = GetDb()) { db.ExecuteNonQuery( Update("crm_deal") .Set("title", deal.Title) .Set("description", deal.Description) .Set("responsible_id", deal.ResponsibleID) .Set("contact_id", deal.ContactID) .Set("bid_currency", deal.BidCurrency) .Set("bid_value", deal.BidValue) .Set("bid_type", deal.BidType) .Set("deal_milestone_id", deal.DealMilestoneID) .Set("deal_milestone_probability", deal.DealMilestoneProbability) .Set("expected_close_date", TenantUtil.DateTimeToUtc(deal.ExpectedCloseDate)) .Set("per_period_value", deal.PerPeriodValue) .Set("actual_close_date", TenantUtil.DateTimeToUtc(deal.ActualCloseDate)) .Set("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow())) .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID) .Where(Exp.Eq("id", deal.ID)) ); } }