Exemple #1
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            DateTime startDate     = DateTime.Parse(Request["uid"], CultureInfo.InvariantCulture);
            DateTime destStartDate = CHelper.GetWeekStartByDate(DTCWeek.SelectedDate);

            if (startDate.Date != destStartDate.Date)
            {
                TimeTrackingEntry[] mas      = TimeTrackingEntry.List(FilterElement.EqualElement("OwnerId", Mediachase.IBN.Business.Security.CurrentUser.UserID), FilterElement.EqualElement("StartDate", startDate));
                List <int>          entryIds = new List <int>();
                foreach (TimeTrackingEntry tte in mas)
                {
                    entryIds.Add((int)tte.PrimaryKeyId.Value);
                }
                if (entryIds.Count > 0)
                {
                    TimeTrackingManager.AddEntries(destStartDate, Mediachase.IBN.Business.Security.CurrentUser.UserID, entryIds);
                }
            }


            // Refresh parent window
            CommandParameters cp = new CommandParameters("MC_TT_CloneWeek");

            Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Deletes the navigation item.
        /// </summary>
        /// <param name="fullId">The full id.</param>
        /// <param name="profileId">The profile id.</param>
        /// <param name="principalId">The principal id.</param>
        public static void DeleteNavigationItem(string fullId, PrimaryKeyId?profileId, PrimaryKeyId?principalId)
        {
            FilterElementCollection filters = new FilterElementCollection();

            filters.Add(new FilterElement(CustomizationItemEntity.FieldXmlFullId, FilterElementType.Like, fullId + "%"));
            filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldStructureType, (int)CustomizationStructureType.NavigationMenu));
            filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldCommandType, (int)ItemCommandType.Add));

            // delete user level only
            if (principalId.HasValue)
            {
                filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldPrincipalId, principalId.Value));
            }
            // delete profile and user level
            else if (profileId.HasValue)
            {
                OrBlockFilterElement block = new OrBlockFilterElement();
                block.ChildElements.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldProfileId, profileId.Value));
                block.ChildElements.Add(FilterElement.IsNotNullElement(CustomizationItemEntity.FieldPrincipalId));
                filters.Add(block);
            }
            // else delete all - we don't use filter in that case

            using (TransactionScope transaction = DataContext.Current.BeginTransaction())
            {
                foreach (EntityObject item in BusinessManager.List(CustomizationItemEntity.ClassName, filters.ToArray()))
                {
                    BusinessManager.Delete(item);
                }

                transaction.Commit();
            }

            ClearCache(profileId, principalId);
        }
Exemple #3
0
        /// <summary>
        /// Gets the week items for user.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public static WeekItemInfo[] GetWeekItemsForUser(DateTime from, DateTime to, int userId)
        {
            List <WeekItemInfo> retVal = new List <WeekItemInfo>();

            // Load User TT blocks
            TimeTrackingBlock[] userBlocks = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", userId),
                                                                    new IntervalFilterElement("StartDate", from, to));

            // Sort Block By Start Date
            Array.Sort <TimeTrackingBlock>(userBlocks, CompareTimeTrackingBlockByStartDate);

            // Create Week Item Info list
            DateTime currentWeekStart = GetRealWeekStart(from);

            // TODO: Current
            while (currentWeekStart < to)
            {
                // Calculate aggregated status of all blocks
                WeekItemStatus status = CalculateWeekStatusByBlocks(currentWeekStart, userBlocks);

                WeekItemInfo item = new WeekItemInfo(currentWeekStart,
                                                     Iso8601WeekNumber.GetWeekNumber(currentWeekStart.AddDays(3)),
                                                     status);

                CalculateDayTotal(currentWeekStart, item, userBlocks);

                retVal.Add(item);

                // Go to next week
                currentWeekStart = currentWeekStart.AddDays(7);
            }

            return(retVal.ToArray());
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_classes.Count <= 0)
            {
                throw new Exception("Classes is required!");
            }

            ddFilter.SelectedIndexChanged += new EventHandler(ddFilter_SelectedIndexChanged);

            if (!IsPostBack)
            {
                BindDropDowns();

                btnNew.Visible    = _isCanCreate;
                tblSelect.Visible = true;
                tblNew.Visible    = false;
            }

            grdMain.ClassName      = ddFilter.SelectedValue;
            grdMain.ViewName       = "";
            grdMain.PlaceName      = _placeName;
            grdMain.ProfileName    = ProfileName;
            grdMain.ShowCheckboxes = _isMultipleSelect;

            FilterElementCollection fec = new FilterElementCollection();

            if (!String.IsNullOrEmpty(Request["filterName"]) && !String.IsNullOrEmpty(Request["filterValue"]))
            {
                FilterElement fe   = FilterElement.EqualElement(Request["filterName"], Request["filterValue"]);
                FilterElement fe1  = FilterElement.IsNullElement(Request["filterName"]);
                FilterElement feOr = new OrBlockFilterElement();
                feOr.ChildElements.Add(fe);
                feOr.ChildElements.Add(fe1);
                fec.Add(feOr);
            }
            else if (!String.IsNullOrEmpty(Request["filterName"]) && String.IsNullOrEmpty(Request["filterValue"]))
            {
                FilterElement fe = FilterElement.IsNullElement(Request["filterName"]);
                fec.Add(fe);
            }

            if (TreeServiceTargetObjectId != PrimaryKeyId.Empty)
            {
                FilterElement fe = new FilterElement(Mediachase.Ibn.Data.Services.TreeService.OutlineNumberFieldName, FilterElementType.NotContains, TreeServiceTargetObjectId.ToString().ToLower());
                fec.Add(fe);
            }
            grdMain.AddFilters = fec;

            ctrlGridEventUpdater.ClassName      = ddFilter.SelectedValue;
            ctrlGridEventUpdater.ViewName       = "";
            ctrlGridEventUpdater.PlaceName      = _placeName;
            ctrlGridEventUpdater.GridId         = grdMain.GridClientContainerId;
            ctrlGridEventUpdater.GridActionMode = Mediachase.UI.Web.Apps.MetaUI.Grid.MetaGridServerEventAction.Mode.ListViewUI;

            //ddFilter.Visible = (_classes.Count > 1);

            BindDataGrid(!Page.IsPostBack);

            BindButtons();
        }
Exemple #5
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters   cp        = (CommandParameters)Element;
                DateTime            startDate = DateTime.Parse(cp.CommandArguments["primaryKeyId"], CultureInfo.InvariantCulture);
                TimeTrackingBlock[] mas       = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", Mediachase.IBN.Business.Security.CurrentUser.UserID), FilterElement.EqualElement("StartDate", startDate));

                using (TransactionScope tran = DataContext.Current.BeginTransaction())
                {
                    foreach (TimeTrackingBlock ttb in mas)
                    {
                        StateMachineService sms = ((BusinessObject)ttb).GetService <StateMachineService>();

                        // process only initial state
                        if (sms.StateMachine.GetStateIndex(sms.CurrentState.Name) == 0)
                        {
                            StateTransition[] availableTransitions = sms.GetNextAvailableTransitions(true);
                            if (availableTransitions.Length > 0)
                            {
                                sms.MakeTransition(availableTransitions[0].Uid);
                                ttb.Save();
                            }
                        }
                    }
                    tran.Commit();
                }

                CHelper.RequireBindGrid();
            }
        }
        /// <summary>
        /// Creates the email delivery provider filters.
        /// </summary>
        /// <returns></returns>
        internal static FilterElement[] CreateIbnClientMessageDeliveryProviderFilters()
        {
            List <FilterElement> retVal = new List <FilterElement>();

            retVal.Add(FilterElement.IsNotNullElement(OutgoingMessageQueueEntity.FieldIbnClientMessageId));
            retVal.Add(FilterElement.EqualElement(OutgoingMessageQueueEntity.FieldIsDelivered, false));

            retVal.Add(new FilterElement("", FilterElementType.Custom,
                                         "[t01].[Modified] < (DATEADD(mi,-(CASE WHEN [t01].[DeliveryAttempts]>5 THEN 30 ELSE [t01].[DeliveryAttempts]*5 END),getutcdate()))"));

            // Check Delivery Constrains Max Delivery Attempts
            if (PortalConfig.MdsMaxDeliveryAttempts > 0)
            {
                retVal.Add(new FilterElement(OutgoingMessageQueueEntity.FieldDeliveryAttempts,
                                             FilterElementType.LessOrEqual,
                                             PortalConfig.MdsMaxDeliveryAttempts));
            }

            // Check Delivery Constrains Delivery Timeout
            if (PortalConfig.MdsDeliveryTimeout > 0)
            {
                retVal.Add(new FilterElement(OutgoingMessageQueueEntity.FieldCreated,
                                             FilterElementType.GreaterOrEqual,
                                             DateTime.UtcNow.AddMinutes(-1 * PortalConfig.MdsDeliveryTimeout)));
            }

            return(retVal.ToArray());
        }
Exemple #7
0
        public static bool DebitGiftCard(string giftCardMetaClass, PrimaryKeyId contactId, string redemtionCode, decimal debitAmount)
        {
            var cards = BusinessManager.List(giftCardMetaClass,
                                             new FilterElement[]
            {
                FilterElement.EqualElement("ContactId", contactId),
                FilterElement.EqualElement("IsActive", true),
                FilterElement.EqualElement("RedemtionCode", redemtionCode)
            });

            if (cards == null || cards.Count() == 0)
            {
                return(false);
            }
            var card = cards[0];

            if ((decimal)card["Balance"] < debitAmount)
            {
                return(false);
            }
            decimal newBalance = (decimal)card["Balance"] - debitAmount;

            card["Balance"] = newBalance;
            if (newBalance == 0)
            {
                card["IsActive"] = false;
            }
            BusinessManager.Update(card);

            return(true);
        }
        private void BindTemplates()
        {
            int projectId = CommonHelper.GetProjectIdByObjectIdObjectType(OwnerId, OwnerTypeId);

            FilterElementCollection filters = new FilterElementCollection();

            filters.Add(FilterElement.EqualElement(WorkflowDefinitionEntity.FieldSupportedIbnObjectTypes, OwnerTypeId));
            if (projectId > 0)
            {
                // O.R. [2010-02-03]: Allow to select non-project templates for a project
                OrBlockFilterElement orBlock = new OrBlockFilterElement();
                orBlock.ChildElements.Add(FilterElement.EqualElement(WorkflowDefinitionEntity.FieldProjectId, projectId));
                orBlock.ChildElements.Add(FilterElement.IsNullElement(WorkflowDefinitionEntity.FieldProjectId));
                filters.Add(orBlock);
            }
            else
            {
                filters.Add(FilterElement.IsNullElement(WorkflowDefinitionEntity.FieldProjectId));
            }

            if (TeplateGroupList.Items.Count > 0)
            {
                filters.Add(FilterElement.EqualElement(WorkflowDefinitionEntity.FieldTemplateGroup, int.Parse(TeplateGroupList.SelectedValue)));
            }

            TemplateList.Items.Clear();
            foreach (WorkflowDefinitionEntity entity in BusinessManager.List(WorkflowDefinitionEntity.ClassName, filters.ToArray()))
            {
                TemplateList.Items.Add(new ListItem(entity.Name, entity.PrimaryKeyId.Value.ToString()));
            }
        }
Exemple #9
0
        /// <summary>
        /// Resets the custom page.
        /// </summary>
        /// <param name="uid">The page uid.</param>
        /// <param name="profileId">The profile id.</param>
        /// <param name="userId">The user id.</param>
        public static void ResetCustomPage(Guid uid, int?profileId, int?userId)
        {
            FilterElementCollection filters = new FilterElementCollection();

            filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUid, uid));

            if (userId.HasValue)                // User layer
            {
                filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUserId, userId.Value));
            }
            else if (profileId.HasValue)                // Profile layer
            {
                filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldProfileId, profileId.Value));
            }
            else             // Site layer
            {
                filters.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId));
                filters.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId));
            }

            foreach (CustomPageEntity page in BusinessManager.List(CustomPageEntity.ClassName, filters.ToArray()))
            {
                if (!page.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName))
                {
                    BusinessManager.Delete(page);
                }
            }
        }
		protected override void PreListInsideTransaction(BusinessContext context)
		{
			base.PreListInsideTransaction(context);

			// OZ 2008-11-11 Fix Contact view for ibn partners
			ListRequest request = (ListRequest)context.Request;

			Guid orgUid, contactUid;

			// Check  

			if (PartnerUtil.GetClientInfo((int)DataContext.Current.CurrentUserId, out orgUid, out contactUid))
			{
				List<FilterElement> filters = new List<FilterElement>(request.Filters);

				// if (OrgUid!=null)   -> View all Contacts with OrgUid only 
				if (orgUid != Guid.Empty)
				{
					filters.Add(FilterElement.EqualElement("OrganizationId", orgUid));
				}
				// if (ContactUid!=null)   -> View Contact with ContactUid only 
				else if (contactUid != Guid.Empty)
				{
					filters.Add(FilterElement.EqualElement("PrimaryKeyId", contactUid));
				}
				// Nothing show
				else
				{
					filters.Add(FilterElement.IsNullElement("PrimaryKeyId"));
				}

				request.Filters = filters.ToArray();
			}
			//
		}
Exemple #11
0
 public static EntityObject[] GetCustomerGiftCards(PrimaryKeyId contactId)
 {
     return(BusinessManager.List(GiftCardMetaClass, new[]
     {
         FilterElement.EqualElement(ContactIdField, contactId)
     }));
 }
Exemple #12
0
        private void BindDataGrid(bool dataBind)
        {
            _isFilterSet = false;
            _filterText  = String.Empty;

            //добавляем к фильтру выбраное значение из левой панели, если включена группировка
            #region GroupItem
            if (_isGroupSet)
            {
                string groupCurrent = lvp.GroupByFieldName;
                if (!String.IsNullOrEmpty(groupCurrent) && mc.Fields.Contains(groupCurrent) && groupList.Items.Count > 0 && groupList.SelectedValue != null)
                {
                    FilterElementCollection fec = new FilterElementCollection();
                    fec.Add(FilterElement.EqualElement(groupCurrent, groupList.SelectedValue));
                    grdMain.AddFilters = fec;
                }
            }
            #endregion

            grdMain.SearchKeyword = txtSearch.Text;

            if (dataBind)
            {
                grdMain.DataBind();
            }
        }
Exemple #13
0
        public override void DataBind()
        {
            if (DataItem != null)
            {
                CalendarEventEntity     ceo = (CalendarEventEntity)DataItem;
                FilterElementCollection fec = new FilterElementCollection();
                FilterElement           fe  = FilterElement.EqualElement("EventId", ((VirtualEventId)ceo.PrimaryKeyId).RealEventId);
                fec.Add(fe);
                fe = FilterElement.EqualElement("PrincipalId", Mediachase.IBN.Business.Security.CurrentUser.UserID);
                fec.Add(fe);

                EntityObject[] list = BusinessManager.List(CalendarEventResourceEntity.ClassName, fec.ToArray());
                if (list.Length > 0)
                {
                    CalendarEventResourceEntity cero = (CalendarEventResourceEntity)list[0];
                    _resId = cero.PrimaryKeyId.Value;
                    if (cero.Status.HasValue)
                    {
                        if (cero.Status.Value == (int)eResourceStatus.Accepted)
                        {
                            btnAccept.Disabled = true;
                        }
                        if (cero.Status.Value == (int)eResourceStatus.Tentative)
                        {
                            btnTentative.Disabled = true;
                        }
                        if (cero.Status.Value == (int)eResourceStatus.Declined)
                        {
                            btnDecline.Disabled = true;
                        }
                    }
                }
            }
            base.DataBind();
        }
        public static CustomerContact GetOwner(string marketId, out bool foundOne)
        {
            //ToDo: create the field in BF for the contact
            // ...may not need the "out-part"
            FilterElementCollection fc = new FilterElementCollection
            {
                FilterElement.EqualElement("MarketToOwn", marketId)
            };

            EntityObject[] result = BusinessManager.List(CustomerContact.ClassName, fc.ToArray(), null);

            if (result != null)
            {
                if (result.Count() == 1)
                {
                    // got the contact
                    foundOne = true;
                    return((CustomerContact)result.FirstOrDefault());
                }
                else
                {
                }        // could be several owners, need some action
            }
            else
            {
            }        // empty

            foundOne = false;
            return(null);
        }
Exemple #15
0
        private FilterElementCollection GetFilters()
        {
            FilterElementCollection coll = new FilterElementCollection();

            if (!String.IsNullOrEmpty(ClassName))
            {
                if (ObjectId == null)
                {
                    throw new ArgumentNullException("QueryString:ObjectId");
                }

                //Profile level
                if (String.Compare(ClassName, CustomizationProfileEntity.ClassName, true) == 0)
                {
                    // ProfileId is null OR ProfileId = value
                    OrBlockFilterElement orBlock = new OrBlockFilterElement();
                    orBlock.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId));
                    orBlock.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldProfileId, ObjectId));

                    coll.Add(orBlock);
                    coll.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId));
                }

                //User level
                if (String.Compare(ClassName, "Principal", true) == 0)
                {
                    int profileId = ProfileManager.GetProfileIdByUser();

                    // ProfileId is null AND UserId is null
                    AndBlockFilterElement andBlock1 = new AndBlockFilterElement();
                    andBlock1.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId));
                    andBlock1.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId));

                    // ProfileId = value AND UserId is null
                    AndBlockFilterElement andBlock2 = new AndBlockFilterElement();
                    andBlock2.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldProfileId, profileId));
                    andBlock2.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId));

                    // ProfileId is null AND UserId = value
                    AndBlockFilterElement andBlock3 = new AndBlockFilterElement();
                    andBlock3.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId));
                    andBlock3.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldUserId, ObjectId));

                    OrBlockFilterElement orBlock = new OrBlockFilterElement();
                    orBlock.ChildElements.Add(andBlock1);
                    orBlock.ChildElements.Add(andBlock2);
                    orBlock.ChildElements.Add(andBlock3);

                    coll.Add(orBlock);
                }
            }
            else
            {
                //Site level
                coll.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId));
                coll.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId));
            }
            return(coll);
        }
Exemple #16
0
 /// <summary>
 /// Removes all workflow participants.
 /// </summary>
 /// <param name="workflowInstanceId">The workflow instance id.</param>
 private void RemoveAllWorkflowParticipants(Guid workflowInstanceId)
 {
     WorkflowParticipantRow[] oldParticipants = WorkflowParticipantRow.List(FilterElement.EqualElement(WorkflowParticipantRow.ColumnWorkflowInstanceId, workflowInstanceId));
     foreach (WorkflowParticipantRow oldParticipant in oldParticipants)
     {
         oldParticipant.Delete();
     }
 }
Exemple #17
0
        /// <summary>
        /// Resets the user settings by profile.
        /// </summary>
        /// <param name="uid">The page uid.</param>
        /// <param name="profileId">The profile id.</param>
        public static void ResetUserSettingsByProfile(Guid uid, int profileId)
        {
            List <string> users = new List <string>();

            if (profileId > 0)
            {
                FilterElementCollection fec = new FilterElementCollection();
                fec.Add(FilterElement.EqualElement(CustomizationProfileUserEntity.FieldProfileId, profileId));

                foreach (CustomizationProfileUserEntity entity in BusinessManager.List(CustomizationProfileUserEntity.ClassName, fec.ToArray()))
                {
                    users.Add(entity.PrincipalId.ToString());
                }
            }
            else             // default profile
            {
                // 1. Get list all users
                using (IDataReader reader = Mediachase.IBN.Business.User.GetListAll())
                {
                    while (reader.Read())
                    {
                        users.Add(reader["UserId"].ToString());
                    }
                }

                // 2. Exclude users with non-default profile
                EntityObject[] entityList = BusinessManager.List(CustomizationProfileUserEntity.ClassName, (new FilterElementCollection()).ToArray());
                foreach (CustomizationProfileUserEntity puEntity in entityList)
                {
                    users.Remove(puEntity.PrincipalId.ToString());
                }
            }

            // O.R. [2010-10-05]. Don't process profile without users
            if (users.Count > 0)
            {
                // Remove CustomPages for all users in Profile
                FilterElementCollection filters = new FilterElementCollection();
                filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUid, uid));

                OrBlockFilterElement orBlock = new OrBlockFilterElement();
                foreach (string userId in users)
                {
                    orBlock.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldUserId, userId));
                }
                filters.Add(orBlock);

                // Skip CustomPageNormalizationPlugin
                ListRequest request = new ListRequest(CustomPageEntity.ClassName, filters.ToArray());
                request.Parameters.Add("CustomPageNormalizationPlugin", false);
                ListResponse response = (ListResponse)BusinessManager.Execute(request);

                foreach (EntityObject page in response.EntityObjects)
                {
                    BusinessManager.Delete(page);
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Lists the specified folder id.
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        /// <returns></returns>
        public static ListInfo[] List(int folderId)
        {
            FilterElement listSequrityFilterElement = new FilterElement(
                "ListInfoId",
                FilterElementType.In,
                new SelectCommandBuilderParameter("SELECT ListId FROM LISTINFO_SECURITY_ALL WHERE PrincipalId = @UserId AND AllowLevel >= 1", SqlHelper.SqlParameter("@UserId", SqlDbType.Int, Security.CurrentUserId)));

            return(List(FilterElement.EqualElement("FolderId", folderId), listSequrityFilterElement));
        }
Exemple #19
0
        /// <summary>
        /// Lists the specified folder.
        /// </summary>
        /// <param name="folder">ListFolder.</param>
        /// <returns></returns>
        public static ListPublication[] List(MetaObject folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }

            return(List(FilterElement.EqualElement("FolderId", folder.PrimaryKeyId.Value)));
        }
Exemple #20
0
 public static EntityObject[] GetClientGiftCards(string giftCardMetaClass, PrimaryKeyId contactId)
 {
     return(BusinessManager.List(giftCardMetaClass,
                                 new FilterElement[]
     {
         FilterElement.EqualElement("ContactId", contactId),
         FilterElement.EqualElement("IsActive", true)
     }));
 }
Exemple #21
0
 public EntityObject GetTheGiftCard()
 {
     return(BusinessManager.List
                ("TrainingGiftCard", new[] {
         FilterElement.EqualElement("ContactId"
                                    , CustomerContext.Current.CurrentContactId)
     }, null)                   //
            .FirstOrDefault()); // demo/lab ... could change the sort-null to a "new empty", both cannot be null
 }
        /// <summary>
        /// Gets the files.
        /// </summary>
        /// <param name="structureName">Name of the structure.</param>
        /// <param name="searchPattern">The search pattern.</param>
        /// <param name="selectors">The selectors (4st argument - profileId, 5nd argument - principalId).</param>
        /// <returns></returns>
        public override FileDescriptor[] GetFiles(string structureName, string searchPattern, Selector[] selectors)
        {
            List <FileDescriptor> files = new List <FileDescriptor>();

            if (string.Compare(structureName, "Navigation", StringComparison.OrdinalIgnoreCase) == 0 &&
                string.Compare(searchPattern, "*.xml", StringComparison.OrdinalIgnoreCase) == 0)
            {
                FilterElementCollection filters;
                EntityObject[]          items;
                PrimaryKeyId            profileId   = PrimaryKeyId.Empty;
                PrimaryKeyId            principalId = PrimaryKeyId.Empty;

                // 1. Global Layer
                filters = new FilterElementCollection();
                filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldStructureType, (int)CustomizationStructureType.NavigationMenu));
                filters.Add(FilterElement.IsNullElement(CustomizationItemEntity.FieldProfileId));
                filters.Add(FilterElement.IsNullElement(CustomizationItemEntity.FieldPrincipalId));

                items = BusinessManager.List(CustomizationItemEntity.ClassName, filters.ToArray());
                ProcessItems(items, files, NavigationManager.CustomizationLayerGlobal);

                // 2. Profile Layer
                if (selectors != null && selectors.Length != 0 && selectors[0].Items.Count > 3 && !string.IsNullOrEmpty(selectors[0].Items[3]))
                {
                    string profileSelector = selectors[0].Items[3];
                    if (PrimaryKeyId.TryParse(profileSelector, out profileId))
                    {
                        filters = new FilterElementCollection();
                        filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldStructureType, (int)CustomizationStructureType.NavigationMenu));
                        filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldProfileId, profileId));
                        filters.Add(FilterElement.IsNullElement(CustomizationItemEntity.FieldPrincipalId));

                        items = BusinessManager.List(CustomizationItemEntity.ClassName, filters.ToArray());
                        ProcessItems(items, files, NavigationManager.CustomizationLayerProfile);
                    }
                }

                // 3. User Layer
                if (selectors != null && selectors.Length != 0 && selectors[0].Items.Count > 4 && !string.IsNullOrEmpty(selectors[0].Items[4]))
                {
                    string principalSelector = selectors[0].Items[4];
                    if (PrimaryKeyId.TryParse(principalSelector, out principalId))
                    {
                        filters = new FilterElementCollection();
                        filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldStructureType, (int)CustomizationStructureType.NavigationMenu));
                        filters.Add(FilterElement.IsNullElement(CustomizationItemEntity.FieldProfileId));
                        filters.Add(FilterElement.EqualElement(CustomizationItemEntity.FieldPrincipalId, principalId));

                        items = BusinessManager.List(CustomizationItemEntity.ClassName, filters.ToArray());
                        ProcessItems(items, files, NavigationManager.CustomizationLayerUser);
                    }
                }
            }

            return(files.ToArray());
        }
        protected override void  PreDeleteInsideTransaction(BusinessContext context)
        {
            // Call Base method
            base.PreDeleteInsideTransaction(context);

            #region Delete Assigned Addresses
            EntityObject[] addresses = BusinessManager.List(AddressEntity.GetAssignedMetaClassName(),
                                                            new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

            foreach (AddressEntity address in addresses)
            {
                DeleteRequest request = new DeleteRequest(address);
                request.Parameters.Add(AddressRequestParameters.Delete_SkipDefaultAddressCheck, null);

                BusinessManager.Execute(request);
            }
            #endregion

            #region Process RelatedContactAction
            // Read RelatedContactAction from request parameters
            RelatedContactAction relContactAction = context.Request.Parameters.GetValue <RelatedContactAction>(OrganizationRequestParameters.Delete_RelatedContactAction, RelatedContactAction.None);

            switch (relContactAction)
            {
            // Detach all assigned contacts
            case RelatedContactAction.Detach:
                EntityObject[] detachedContacts = BusinessManager.List(ContactEntity.GetAssignedMetaClassName(),
                                                                       new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

                foreach (ContactEntity contact in detachedContacts)
                {
                    contact.OrganizationId = null;

                    BusinessManager.Update(contact);
                }
                break;

            // Delete all assigned actions
            case RelatedContactAction.Delete:
                EntityObject[] deletedContacts = BusinessManager.List(ContactEntity.GetAssignedMetaClassName(),
                                                                      new FilterElement[] { FilterElement.EqualElement("OrganizationId", context.GetTargetPrimaryKeyId()) });

                foreach (ContactEntity contact in deletedContacts)
                {
                    BusinessManager.Execute(new DeleteRequest(contact));
                }
                break;
            }
            #endregion

            #region Remove references from IBN 4.7 objects
            SqlHelper.ExecuteNonQuery(SqlContext.Current, System.Data.CommandType.StoredProcedure,
                                      "bus_cls_Organization_Delete",
                                      SqlHelper.SqlParameter("@OrgUid", SqlDbType.UniqueIdentifier, context.GetTargetPrimaryKeyId().Value));
            #endregion
        }
Exemple #24
0
        public bool IsEnable(object Sender, object Element)
        {
            bool retval = false;

            if (HttpContext.Current.Items.Contains("OwnerTypeId") && HttpContext.Current.Items.Contains("OwnerId"))
            {
                int ownerTypeId = (int)HttpContext.Current.Items["OwnerTypeId"];
                int ownerId     = (int)HttpContext.Current.Items["OwnerId"];

                bool canUpdate = false;
                if (ownerTypeId == (int)ObjectTypes.Document)
                {
                    canUpdate = Document.CanUpdate(ownerId);
                }
                else if (ownerTypeId == (int)ObjectTypes.Task)
                {
                    canUpdate = Task.CanUpdate(ownerId);
                }
                else if (ownerTypeId == (int)ObjectTypes.ToDo)
                {
                    canUpdate = ToDo.CanUpdate(ownerId);
                }
                else if (ownerTypeId == (int)ObjectTypes.Issue)
                {
                    canUpdate = Incident.CanUpdate(ownerId);
                }

                if (canUpdate)
                {
                    int projectId = CommonHelper.GetProjectIdByObjectIdObjectType(ownerId, ownerTypeId);

                    FilterElementCollection filters = new FilterElementCollection();
                    filters.Add(FilterElement.EqualElement(WorkflowDefinitionEntity.FieldSupportedIbnObjectTypes, ownerTypeId));
                    if (projectId > 0)
                    {
                        // O.R. [2010-02-03]: Allow to select non-project templates for a project
                        OrBlockFilterElement orBlock = new OrBlockFilterElement();
                        orBlock.ChildElements.Add(FilterElement.EqualElement(WorkflowDefinitionEntity.FieldProjectId, projectId));
                        orBlock.ChildElements.Add(FilterElement.IsNullElement(WorkflowDefinitionEntity.FieldProjectId));
                        filters.Add(orBlock);
                    }
                    else
                    {
                        filters.Add(FilterElement.IsNullElement(WorkflowDefinitionEntity.FieldProjectId));
                    }

                    EntityObject[] items = BusinessManager.List(WorkflowDefinitionEntity.ClassName, filters.ToArray());
                    if (items != null && items.Length > 0)
                    {
                        retval = true;
                    }
                }
            }

            return(retval);
        }
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;
                string[]          selectedElements = EntityGrid.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);

                if (selectedElements != null && selectedElements.Length > 0)
                {
                    int          errorCount      = 0;
                    string       bridgeClassName = CHelper.GetFromContext("ReferenceNN_BridgeClassName").ToString();
                    string       field1Name      = CHelper.GetFromContext("ReferenceNN_Field1Name").ToString();
                    string       field2Name      = CHelper.GetFromContext("ReferenceNN_Field2Name").ToString();
                    PrimaryKeyId field1Value     = PrimaryKeyId.Parse(CHelper.GetFromContext("ReferenceNN_Field1Value").ToString());
                    using (TransactionScope tran = DataContext.Current.BeginTransaction())
                    {
                        foreach (string elem in selectedElements)
                        {
                            string[]     parts     = elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
                            string       id        = parts[0];
                            PrimaryKeyId key       = PrimaryKeyId.Parse(id);
                            string       className = parts[1];

                            FilterElementCollection fec = new FilterElementCollection();
                            fec.Add(FilterElement.EqualElement(field1Name, field1Value));
                            fec.Add(FilterElement.EqualElement(field2Name, key));
                            EntityObject[] list = BusinessManager.List(bridgeClassName, fec.ToArray());
                            if (list.Length > 0)
                            {
                                foreach (EntityObject eo in list)
                                {
                                    try
                                    {
                                        BusinessManager.Delete(bridgeClassName, eo.PrimaryKeyId.Value);
                                    }
                                    catch (Exception ex)
                                    {
                                        CHelper.GenerateErrorReport(ex);
                                        errorCount++;
                                    }
                                }
                            }
                        }

                        tran.Commit();
                    }

                    if (errorCount > 0)
                    {
                        ((CommandManager)Sender).InfoMessage = CHelper.GetResFileString("{IbnFramework.Common:NotAllSelectedItemsWereProcessed}");
                    }
                }
            }
            CHelper.RequireDataBind();
        }
Exemple #26
0
        protected override void PreDeleteInsideTransaction(BusinessContext context)
        {
            base.PreDeleteInsideTransaction(context);

            // Delete ACL
            foreach (mcweb_ReportAceRow row in mcweb_ReportAceRow.List(
                         FilterElement.EqualElement(mcweb_ReportAceRow.Columns.ReportId, (Guid)context.Request.Target.PrimaryKeyId.Value)))
            {
                row.Delete();
            }
        }
Exemple #27
0
        public override void DataBind()
        {
            CHelper.AddToContext(_httpContextClassNameKey, ClassName);
            CHelper.AddToContext(_httpContextFilterFieldNameKey, FilterFieldName);
            CHelper.AddToContext(_httpContextFilterFieldValueKey, Request["ObjectId"]);

            if (String.IsNullOrEmpty(ProfileName))
            {
                MetaClass         mc   = Mediachase.Ibn.Core.MetaDataWrapper.GetMetaClassByName(ClassName);
                ListViewProfile[] list = ListViewProfile.GetSystemProfiles(ClassName, PlaceName);
                if (list.Length == 0)
                {
                    list = ListViewProfile.GetSystemProfiles(ClassName, "EntityList");
                    if (list.Length == 0)
                    {
                        list = ListViewProfile.GetSystemProfiles(ClassName, String.Empty);
                        if (list.Length == 0)
                        {
                            ListViewProfile lvp = new ListViewProfile();
                            lvp.Id       = Guid.NewGuid().ToString();
                            lvp.IsPublic = true;
                            lvp.IsSystem = true;
                            lvp.Name     = CHelper.GetResFileString(mc.FriendlyName);
                            lvp.ColumnsUI.Add(new ColumnProperties(mc.TitleFieldName, "150px", String.Empty));
                            lvp.FieldSet.Add(mc.TitleFieldName);
                            lvp.Filters = new FilterElementCollection();
                            ListViewProfile.SaveSystemProfile(ClassName, PlaceName, Mediachase.Ibn.Data.Services.Security.CurrentUserId, lvp);
                            list = ListViewProfile.GetSystemProfiles(ClassName, String.Empty);
                        }
                    }
                }
                ProfileName = list[0].Id;
            }
            grdMain.ClassName      = ClassName;
            grdMain.ViewName       = ViewName;
            grdMain.PlaceName      = PlaceName;
            grdMain.ProfileName    = ProfileName;
            grdMain.ShowCheckboxes = ShowCheckBoxes;
            FilterElementCollection fec = new FilterElementCollection();

            fec.Add(FilterElement.EqualElement(FilterFieldName, Request["ObjectId"]));
            grdMain.AddFilters = fec;
            grdMain.DataBind();

            ctrlGridEventUpdater.ClassName = ClassName;
            ctrlGridEventUpdater.ViewName  = ViewName;
            ctrlGridEventUpdater.PlaceName = PlaceName;
            ctrlGridEventUpdater.GridId    = grdMain.GridClientContainerId;

            MainMetaToolbar.ClassName = ClassName;
            MainMetaToolbar.ViewName  = ViewName;
            MainMetaToolbar.PlaceName = PlaceName;
            MainMetaToolbar.DataBind();
        }
Exemple #28
0
        protected override void OnDeleting()
        {
            // Remove Assigned Entry
            TimeTrackingEntry[] entryList = TimeTrackingEntry.List(FilterElement.EqualElement("ParentBlockId", this.PrimaryKeyId.Value));

            foreach (TimeTrackingEntry entry in entryList)
            {
                entry.Delete();
            }

            base.OnDeleting();
        }
Exemple #29
0
        /// <summary>
        /// Gets the min start date.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public static DateTime GetTimeTrackingBlockMinStartDate(int userId)
        {
            TimeTrackingBlock[] userBlocks = TimeTrackingBlock.List(
                new FilterElementCollection(FilterElement.EqualElement("OwnerId", userId)),
                new SortingElementCollection(SortingElement.Ascending("StartDate")), 0, 1);

            if (userBlocks.Length > 0)
            {
                return(userBlocks[0].StartDate);
            }

            return(DateTime.Now.AddDays(-210));
        }
Exemple #30
0
 private void BindUsers()
 {
     ddUser.Items.Clear();
     if (tdWeek.Visible || WeekerDiv.Visible)
     {
         ddUser.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));
     }
     Principal[] mas = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
     foreach (Principal pl in mas)
     {
         ddUser.Items.Add(new ListItem(pl.Name, pl.PrimaryKeyId.ToString()));
     }
 }