Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public UserReactionsPartSettings GetSettingPart(UserReactionsPartSettings Model)
        {
            UserReactionsPartSettings             retval       = new UserReactionsPartSettings();
            IQueryable <UserReactionsTypesRecord> repotypesAll = _repoTypes.Table.Where(z => z.Activating == true && z.TypeName != null).OrderBy(o => o.Priority);

            List <UserReactionsSettingTypesSel> partSelectedAll = repotypesAll.Select(r => new UserReactionsSettingTypesSel {
                Id            = r.Id,
                nameReaction  = r.TypeName,
                checkReaction = false
            }).ToList();

            List <UserReactionsSettingTypesSel> viewmodel;
            List <UserReactionsSettingTypesSel> TypeReactionsPartsModel = new List <UserReactionsSettingTypesSel>();

            TypeReactionsPartsModel = Model.TypeReactionsPartsSelected;

            if (TypeReactionsPartsModel.Count() == 0)
            {
                viewmodel = partSelectedAll;
            }
            else
            {
                viewmodel = Model.TypeReactionsPartsSelected.Except(partSelectedAll).ToList();
            }

            retval.TypeReactionsPartsSelected = viewmodel;
            retval.Filtering           = Model.Filtering;
            retval.UserChoiceBehaviour = Model.UserChoiceBehaviour;
            return(retval);
        }
        public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "UserReactionsPart")
            {
                yield break;
            }
            var model = new UserReactionsPartSettings();


            updateModel.TryUpdateModel(model, "UserReactionsPartSettings", null, null);
            if (model.TypeReactionsPartsSelected != null)
            {
                string jsonTypeReactions = new JavaScriptSerializer().Serialize(model.TypeReactionsPartsSelected.ToArray());
                builder.WithSetting("UserReactionsPartSettings.Filtering", ((bool)model.Filtering).ToString());
                builder.WithSetting("UserReactionsPartSettings.TypeReactionsPartsSelected", jsonTypeReactions);
                builder.WithSetting("UserReactionsPartSettings.UserChoiceBehaviour", ((UserChoiceBehaviourValues)model.UserChoiceBehaviour).ToString());
            }

            yield return(DefinitionTemplate(model));
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public List <UserReactionsVM> GetTot(UserReactionsPart part)
        {
            //Part
            IList <UserReactionsVM> viewmodel = new List <UserReactionsVM>();
            //settings type
            List <UserReactionsVM> listType = new List <UserReactionsVM>();

            // if content does not exist return an empty list
            if (part == null)
            {
                return(listType);
            }

            /////////////////////
            //reaction type settings
            UserReactionsPartSettings settings = part.TypePartDefinition.Settings.GetModel <UserReactionsPartSettings>();
            bool FilterApplied = settings.Filtering;

            List <UserReactionsSettingTypesSel> SettingType = new List <UserReactionsSettingTypesSel>();

            if (part.Settings.Count > 0)
            {
                SettingType = new JavaScriptSerializer().Deserialize <List <UserReactionsSettingTypesSel> >(part.Settings["UserReactionsPartSettings.TypeReactionsPartsSelected"]);
            }
            /////////////////////////////////////////////////

            //Reactions type
            // Prendi i valori delle reactions type
            if (FilterApplied == false)
            {
                listType = GetTypesTableFiltered()
                           .Select(x => new UserReactionsVM {
                    Id            = part.Id,
                    Quantity      = 0,
                    TypeName      = x.TypeName,
                    TypeId        = x.Id,
                    OrderPriority = x.Priority,
                    Activating    = x.Activating,
                }).ToList();
            }
            else
            {
                // prendi i valori filtrati
                listType = GetTypesTableFilteredByTypeReactions(SettingType)
                           .Select(x => new UserReactionsVM {
                    Id            = part.Id,
                    Quantity      = 0,
                    TypeName      = x.TypeName,
                    TypeId        = x.Id,
                    OrderPriority = x.Priority,
                    Activating    = x.Activating
                }).ToList();
            }

            /////////////////////////////////////////////////////////////////
            //Part type
            viewmodel = part.Reactions.Select(s => new UserReactionsVM {
                Id            = s.Id,
                Quantity      = s.Quantity,
                TypeName      = s.UserReactionsTypesRecord.TypeName,
                TypeId        = s.UserReactionsTypesRecord.Id,
                OrderPriority = s.UserReactionsTypesRecord.Priority,
                Activating    = s.UserReactionsTypesRecord.Activating,
            }).ToList();

            List <UserReactionsVM> retData = new List <UserReactionsVM>();

            foreach (UserReactionsVM itemTypeReactions in listType)
            {
                UserReactionsVM totItem   = itemTypeReactions;
                UserReactionsVM viewModel = viewmodel.FirstOrDefault(z => z.TypeId.Equals(itemTypeReactions.TypeId));

                if (viewModel != null)
                {
                    totItem.Quantity = viewModel.Quantity;
                }
                retData.Add(totItem);
            }

            return(retData);
        }