/// <summary> /// Initializes a new instance of the <see cref="FieldReadModel"/> class. /// </summary> /// <param name="baseModel"> /// The base model. /// </param> public FieldReadModel(FieldReadModel baseModel) { if (baseModel == null) { throw new ArgumentNullException("baseModel"); } this.Name = baseModel.Name; this.SystemName = baseModel.SystemName; this.SectionName = baseModel.SectionName; this.FieldType = baseModel.FieldType; Ioc.SatisfyImportsOnce(this); }
public IHttpActionResult Validate(DetailsSaveModel item) { if (item == null) { throw new ArgumentNullException("item"); } DetailsModelContainer model; try { model = this.ExtractModelFromRequest(item); } catch (VeyronException ex) { this.Logger.Log(LogSeverity.Error, "Validate", ex); return this.Ok(new DetailsValidateResult { Success = false, Message = ex.Message, DetailsNamespace = item.DetailsNamespace }); } if (model.Model == null) { return this.Ok(new DetailsValidateResult { Success = false, Message = "Item not found. Was it deleted while you were editing it?", DetailsNamespace = model.Namespace }); } try { var result = new DetailsValidateResult { Success = true, DetailsNamespace = model.Namespace }; var businessBase = (IBusinessBase)model.Model; if (!businessBase.IsValid) { foreach (var error in businessBase.GetAllBrokenRules()) { result.BrokenRules.Add(new BrokenRuleModel { FieldName = error.Property, Message = error.Description, Severity = error.Severity }); } } var props = model.Model.GetAllPropertiesForInstance(); foreach (var prop in props.Keys) { var isCalculated = prop.GetCustomAttributes(typeof(CalculatedAttribute), false).Any(); if (isCalculated) { var field = new FieldReadModel(props[prop], prop); result.CalculatedFields.Add(field); } var backColor = FieldReadModel.GetBackColor(props[prop], prop); if (backColor != null) { var field = new FieldBackColorModel { SystemName = prop.Name, BackColor = backColor }; result.FieldsBackColor.Add(field); } var rewriteField = new FieldReadModel(props[prop], prop); if (rewriteField.CanRead) { result.RewriteProperties.Add(rewriteField); } } return this.Ok(result); } catch (VeyronException ex) { this.Logger.Log(LogSeverity.Error, "Validate", ex); return this.Ok(new DetailsValidateResult { Success = false, Message = ex.Message, DetailsNamespace = model.Return(m => m.Namespace, string.Empty) }); } catch (Exception ex) { this.Logger.Log(LogSeverity.Error, "Validate", ex); return this.Ok(new DetailsValidateResult { Success = false, Message = "An error occured. Check log files.", DetailsNamespace = model.Return(m => m.Namespace, string.Empty) }); } }
/// <summary> /// The add field. /// </summary> /// <param name="field"> /// The field. /// </param> public void AddField(FieldReadModel field) { this._fields.Add(field); }
public static DetailsReadModel CreateDetailsReadModel(IEditableRoot model, int childIndex = 0) { if (model == null) { throw new ArgumentNullException("model"); } try { var result = new DetailsReadModel(model.Id, model.ProcessName, model.ProcessDisplayName) { ChildIndex = childIndex }; var props = model.GetAllPropertiesForInstance(); var visibleFields = new HashSet<string>(model.Sections.SelectMany(s => s.Fields).Where(f => !f.IsHidden).Select(f => f.SystemName)); var sections = model.Sections.OrderBy(s => s.Position).Select(s => new SectionReadModel {Name = s.Name}).ToList(); foreach (var prop in props.Keys) { if (!visibleFields.Contains(prop.Name)) { continue; } var field = new FieldReadModel(props[prop], prop); var section = sections.FirstOrDefault(s => s.Name == field.SectionName); if (section == null) { section = new SectionReadModel {Name = field.SectionName}; sections.Add(section); } else { var sect = model.Sections.First(s => s.Name == field.SectionName); field.Position = sect.Fields.First(f => f.SystemName == field.SystemName).Position; } section.AddField(field); } foreach (var section in sections) { section.SortFields(); } result.Sections = sections; var supportStates = model as ISupportStates; if (supportStates != null) { result.CurrentState = Guid.Empty == supportStates.CurrentStateGuid ? null : supportStates.CurrentStateGuid.ToString(); var nextStates = new List<IState>(); if (supportStates.CurrentState.HasValue) { var currentState = supportStates.StateManager.States.FirstOrDefault(s => s.Guid == supportStates.CurrentStateGuid); if (currentState != null) { nextStates.Add(currentState); } } nextStates.AddRange(supportStates.GetNextAvailableStates()); result.NextStates = nextStates.Select(s => new StateReadModel {Id = s.Id, Name = s.Name, Guid = s.Guid}); } result.Title = GetTitle(model); result.BrokenRules = GetBrokenRules(model); //var editableRootType = TheDynamicTypeManager.Value.GetEditableRootType(processName); //return BusinessRules.HasPermission(AuthorizationActions.CreateObject, editableRootType); result.CanAdd = BusinessRules.HasPermission(AuthorizationActions.CreateObject, model); return result; } catch (Exception) { //Logger.Log(LogSeverity.Error, "CreateDetailsReadModel", ex); throw; } }
private List<FieldReadModel> GetFields(IEditableRoot model) { var props = model.GetAllPropertiesForInstance(); var fields = new List<FieldReadModel>(); var displayFields = AnswerDisplayFields.ToDictionary(x => x.FieldName); try { foreach (var prop in props.Keys) { if (!displayFields.ContainsKey(prop.Name)) { continue; } var displayField = displayFields[prop.Name]; var field = new FieldReadModel(props[prop], prop); field.Position = displayField.Position; fields.Add(field); } } catch (Exception ex) { Logger.Log(LogSeverity.Error, GetType().ToString(), ex); } fields = fields.Where(f => !string.IsNullOrEmpty(f.SectionName)).ToList(); return fields; }