public virtual void Save(IUnitOfWork unitOfWork) { var settings = unitOfWork.Settings.Where(w => w.Type == _name).ToList(); foreach (var propertyInfo in _properties) { object propertyValue = propertyInfo.GetValue(this, null); string value = (propertyValue == null) ? null : propertyValue.ToString(); var setting = settings.SingleOrDefault(s => s.Name == propertyInfo.Name); if (setting != null) { setting.Value = value; } else { var newSetting = new Options() { Name = propertyInfo.Name, Type = _name, Value = value, }; unitOfWork.Settings.Add(newSetting); } } }
public ActionResult Index(FormCollection collection) { foreach (var item in collection.AllKeys) { Options _entity = svc.GetByName(item); if (_entity == null) { //new option,save Options new_option = new Options(); new_option.Name = item; new_option.Value = collection[item]; new_option.Type = "GeneralSettings"; svc.Save(new_option); } else { _entity.Value = collection[item]; _entity.Type = "GeneralSettings"; svc.Update(_entity); } } return View(LoadOptions()); }