Example #1
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var field = GetDataItemFromSender((Control)sender);

            if (field != null && field.ID != 0)
            {
                var mediaDetailFields = BaseMapper.GetDataModel().Fields.Where(i => i.ID == field.ID);

                foreach (MediaDetailField mediaDetailField in mediaDetailFields)
                {
                    var fieldAssociations = mediaDetailField.FieldAssociations.ToList();

                    foreach (var fieldAssociation in fieldAssociations)
                    {
                        BaseMapper.GetDataModel().FieldAssociations.Remove(fieldAssociation);
                    }

                    BaseMapper.DeleteObjectFromContext(mediaDetailField);
                }

                var returnObj = MediaDetailsMapper.Update(mediaDetail);

                if (!returnObj.IsError)
                {
                    UpdatedFieldsFromObject(new MediaDetailField());
                    BindItemList();
                }
                else
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
            }
        }
        public override void SetValue(object value)
        {
            var field        = GetField();
            var hasDeleted   = false;
            var hasReordered = false;

            if (ItemsToDelete.Text != "" && ItemsToDelete.Text != "[]")
            {
                var deleteIds = StringHelper.JsonToObject <List <long> >(ItemsToDelete.Text);

                foreach (var id in deleteIds)
                {
                    var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id);

                    if (fieldAssociation != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(fieldAssociation.MediaDetail);

                        if (!returnObj.IsError)
                        {
                            BaseMapper.DeleteObjectFromContext(fieldAssociation);
                        }

                        hasDeleted = true;
                    }
                }
            }

            if (ReorderItems.Text != "" && ReorderItems.Text != "[]")
            {
                var reorderedIds = StringHelper.JsonToObject <List <long> >(ReorderItems.Text);

                var index = 0;
                foreach (var id in reorderedIds)
                {
                    if (id == null)
                    {
                        return;
                    }

                    var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id);

                    if (fieldAssociation != null)
                    {
                        fieldAssociation.OrderIndex = index;
                        hasReordered = true;

                        index++;
                    }
                }
            }

            if (hasDeleted || hasReordered)
            {
                var returnObj = BaseMapper.SaveDataModel();
            }


            BindValues();
        }
Example #3
0
        public void UpdateObjectFromFields()
        {
            selectedItem.CanLimitedRolesAccessAllChildPages = CanLimitedRolesAccessAllChildPages.Checked;
            selectedItem.EnforceRoleLimitationsOnFrontEnd   = EnforceRoleLimitationOnFrontEnd.Checked;

            var roles = MultiRoleSelector.GetSelectedRoles();

            if (roles == null)
            {
                return;
            }

            var rolesMedias = selectedItem.Media.RolesMedias.ToList();

            foreach (var roleMedia in rolesMedias)
            {
                BaseMapper.DeleteObjectFromContext(roleMedia);
            }

            foreach (var role in roles)
            {
                var contextRole  = BaseMapper.GetObjectFromContext(role);
                var newMediaRole = new RoleMedia()
                {
                    Media = selectedItem.Media, Role = contextRole, DateCreated = DateTime.Now, DateLastModified = DateTime.Now
                };

                selectedItem.Media.RolesMedias.Add(newMediaRole);
            }
        }
        private void SaveToDB(string value)
        {
            var obj = StringHelper.JsonToObject <List <JsonObj> >(value);

            if (obj == null)
            {
                return;
            }

            var field = GetField();

            var newIds = StringHelper.ObjectToJson(obj.Select(i => i.id).ToList());
            var oldIds = StringHelper.ObjectToJson(field.FieldAssociations.Select(i => i.AssociatedMediaDetailID).ToList());

            if (newIds == oldIds)
            {
                return;
            }

            var fieldAssociations = field.FieldAssociations.ToList();

            foreach (var item in fieldAssociations)
            {
                BaseMapper.DeleteObjectFromContext(item);
            }

            var orderIndex = 0;

            foreach (var item in obj)
            {
                var mediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(item.id);

                if (mediaDetail != null)
                {
                    field.FieldAssociations.Add(new FieldAssociation()
                    {
                        MediaDetail = mediaDetail, MediaDetailField = field, OrderIndex = orderIndex
                    });
                    orderIndex++;
                }
            }

            var returnObj = BaseMapper.GetDataModel().SaveChanges();
        }
Example #5
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var field = GetDataItemFromSender((Control)sender);

            if (field != null && field.ID != 0)
            {
                //TODO: Only un-comment for testing
                var mediaDetailFields = field.MediaDetailFields.ToList();

                foreach (var mediaDetailField in mediaDetailFields)
                {
                    var fieldAssociations = mediaDetailField.FieldAssociations.ToList();
                    foreach (var item in fieldAssociations)
                    {
                        if (!item.MediaDetail.MediaType.ShowInSiteTree)
                        {
                            var media = item.MediaDetail.Media;

                            MediaDetailsMapper.ClearObjectRelations(item.MediaDetail);
                            BaseMapper.DeleteObjectFromContext(item.MediaDetail);
                        }
                    }

                    BaseMapper.DeleteObjectFromContext(mediaDetailField);
                }
                // End of TODO

                BaseMapper.DeleteObjectFromContext(field);

                var returnObj = MediaTypesMapper.Update(mediaType);

                if (!returnObj.IsError)
                {
                    UpdatedFieldsFromObject(new MediaTypeField());
                    Bind();
                }
                else
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
            }
        }