public FieldOption Save(FieldOption fieldOption) { if (fieldOption.Field != null) { fieldOption.Field = null; } return(fieldOption.Id > 0 ? _rep.Update(fieldOption) : _rep.Add(fieldOption)); }
public async Task <Field> Add(Field field) { try { if (string.IsNullOrEmpty(field.Name)) { throw new ApplicationException("Name field is required."); } if (field.ValueOptions != null && (field.Type == FieldTypes.SingleSelectList || field.Type == FieldTypes.MultiSelectList || field.Type == FieldTypes.CheckboxList || field.Type == FieldTypes.RadioList)) { List <FieldOption> options = new List <FieldOption>(); foreach (FieldOption opt in field.ValueOptions) { if (string.IsNullOrEmpty(opt.Name)) { continue; } options.Add(await _fieldOptionRepository.Add(new FieldOption() { FieldId = field.Id, Name = opt.Name })); } field.ValueOptions = options; } await _context.Fields.InsertOneAsync(field); return(await Get(field.Id)); } catch (Exception ex) { throw ex; } }