コード例 #1
0
        public IActionResult Custom()
        {
            var profile = GetProfile();
            var model   = new SettingsCustom
            {
                Profile      = GetProfile(),
                CustomFields = GetProfileCustomFields(profile.Id)
            };

            return(View(_theme + "Custom.cshtml", model));
        }
コード例 #2
0
        public IActionResult Custom(SettingsCustom model)
        {
            model.Profile = GetProfile();

            var updated  = new List <string>();
            var dbFields = _db.CustomFields.Find(f => f.CustomType == CustomType.Profile && f.ParentId == model.Profile.Id);

            // update existing DB fields
            if (dbFields != null && dbFields.Count() > 0)
            {
                foreach (var field in dbFields)
                {
                    if (model.CustomFields.ContainsKey(field.CustomKey))
                    {
                        field.CustomValue = model.CustomFields[field.CustomKey];
                        updated.Add(field.CustomKey);
                    }
                }
            }
            _db.Complete();

            // add new DB entries
            foreach (var item in model.CustomFields)
            {
                if (!updated.Contains(item.Key))
                {
                    _db.CustomFields.Add(new CustomField {
                        CustomKey   = item.Key,
                        CustomValue = item.Value,
                        Title       = item.Key,
                        CustomType  = CustomType.Profile,
                        ParentId    = model.Profile.Id
                    });
                }
            }
            _db.Complete();

            ViewBag.Message = "Updated";
            return(View(_theme + "Custom.cshtml", model));
        }