public async Task <IActionResult> Get(string id)
 {
     return(await FunctionWrapper.ExecuteFunction(this, async() =>
     {
         return await _fieldRepository.Get(new ObjectId(id));
     }));
 }
 public ActionResult <IEnumerable <FieldModel> > Get([FromQuery] int businessEntityTypeId)
 {
     return(_repository.Get(businessEntityTypeId)
            .Select(f => new FieldModel
     {
         Id = f.Id,
         Name = f.Name
     })
            .ToList());
 }
Ejemplo n.º 3
0
 public void EditFieldState(int fieldId, int campId, bool isEnabled)
 {
     try
     {
         Field field = fieldRepository.Get(fieldId);
         Helper.ThrowIfNull(field, "Datos de cancha inválidos");
         Helper.ThrowIf(field.Camp.Id != campId, "Datos de cancha inválidos");
         field.IsEnabled = isEnabled;
         fieldRepository.SaveOrUpdate(field);
     }
     catch
     {
         throw;
     }
 }
        private async Task <Screen> Hydrate(Screen screen)
        {
            foreach (FieldMetadata fm in screen.Fields)
            {
                var field = await _fieldRepository.Get(fm.Id);

                if (field != null)
                {
                    fm.Name         = field.Name;
                    fm.Type         = field.Type;
                    fm.ValueOptions = field.ValueOptions;
                    fm.DefaultValue = field.DefaultValue;
                }
            }

            return(screen);
        }
Ejemplo n.º 5
0
        public void Delete(EntityDto <int> input)
        {
            var entity = _fieldRepository.Get(input.Id);

            _fieldManager.Delete(entity);
        }
Ejemplo n.º 6
0
        public async Task <FieldDTO> GetById(int id, bool includeDeleted = false)
        {
            var field = await fieldRepository.Get(id, Session, includeDeleted);

            return(field.MapTo <FieldDTO>());
        }
Ejemplo n.º 7
0
        public Task <OperationResult <bool> > Execute(string argsObject)
        {
            return(Task.Run(async() =>
            {
                if (_item == null)
                {
                    return new OperationResult <bool>()
                    {
                        Value = false,
                        ErrorMessage = "Item is required."
                    };
                }

                SetFieldValuePostFunctionArgs args =
                    JsonConvert.DeserializeObject <SetFieldValuePostFunctionArgs>(argsObject);

                if (args == null || args.FieldId == null || args.FieldValue == null)
                {
                    return new OperationResult <bool>()
                    {
                        Value = false,
                        ErrorMessage = "Post-function is not configured correctly."
                    };
                }

                List <FieldValue> fieldValues = _item.FieldValues;

                if (fieldValues == null)
                {
                    fieldValues = new List <FieldValue>();
                }

                // Get field information
                ObjectId fieldId = new ObjectId(args.FieldId);
                var fieldInfo = await _fieldRepository.Get(fieldId);

                // Set field value on item
                var fieldValue = fieldValues.Where(v => v.FieldId == fieldId).FirstOrDefault();

                if (fieldValue == null)
                {   // Add field value to item
                    _item.FieldValues.Add(new FieldValue()
                    {
                        FieldId = fieldId,
                        FieldName = fieldInfo.Name,
                        Value = args.FieldValue
                    });
                }
                else
                {   // Update field value to item
                    fieldValue.FieldName = fieldInfo.Name;
                    fieldValue.Value = args.FieldValue;
                }

                var updateResult = await _itemRepository.Update(_item);

                return new OperationResult <bool>()
                {
                    Value = true
                };
            }));
        }
Ejemplo n.º 8
0
        public Task <OperationResult <bool> > Execute(string argsObject)
        {
            return(Task.Run(async() =>
            {
                if (_item == null)
                {
                    return new OperationResult <bool>()
                    {
                        Value = false,
                        ErrorMessage = "Item is required."
                    };
                }

                List <string> validationErrors = new List <string>();

                FieldRequiredValidationArgs args =
                    JsonConvert.DeserializeObject <FieldRequiredValidationArgs>(argsObject);

                if (args == null || args.RequiredFieldIds == null)
                {
                    return new OperationResult <bool>()
                    {
                        Value = false,
                        ErrorMessage = "Validation is not configured correctly."
                    };
                }

                List <FieldValue> fieldValues = _item.FieldValues;

                if (fieldValues == null)
                {
                    fieldValues = new List <FieldValue>();
                }

                foreach (string requiredFieldId in args.RequiredFieldIds)
                {
                    var fieldValue = fieldValues
                                     .Where(v => v.FieldId == new ObjectId(requiredFieldId)).FirstOrDefault();

                    if (fieldValue == null || string.IsNullOrEmpty(fieldValue.Value))
                    {
                        if (fieldValue == null)
                        {   // Field isn't on the item at all; need to pull info for it
                            var fieldInfo = await _fieldRepository.Get(new ObjectId(requiredFieldId));
                            validationErrors.Add(fieldInfo.Name + " is required");
                        }
                        else
                        {
                            validationErrors.Add(fieldValue.FieldName + " is required");
                        }
                    }
                }

                if (validationErrors.Count == 0)
                {
                    return new OperationResult <bool>()
                    {
                        Value = true
                    };
                }
                else
                {
                    return new OperationResult <bool>()
                    {
                        Value = false,
                        ErrorMessage = string.Join('\n', validationErrors)
                    };
                }
            }));
        }