Пример #1
0
        public async Task <IActionResult> Create(FieldViewModel model)
        {
            if (ManagedYearPlan == null)
            {
                return(ActionIfNotChoosedManagedYearPlan());
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // check number is unique

            Field field = new Field()
            {
                Name     = model.Name,
                Number   = model.Number,
                YearPlan = ManagedYearPlan,
                Parcels  = model.Parcels.Select(x => new Parcel()
                {
                    Number          = x.Number,
                    CultivatedArea  = x.CultivatedArea,
                    FuelApplication = x.FuelApplication,
                    Operator        = _operatorRepository.GetById(x.OperatorId).Result
                }).ToList()
            };
            await _fieldRepository.Add(field);

            TempData["message"] = "Dodano nowe pole!";
            ModelState.Clear();
            return(RedirectToAction("Create"));
        }
Пример #2
0
        public Field Add(Field Field)
        {
            var field = _fieldRepository.Add(Field);

            _unitOfWork.Commit();

            return(field);
        }
Пример #3
0
 public Field Save(Field fieldOption)
 {
     if (fieldOption.SubCategory != null)
     {
         fieldOption.SubCategory = null;
     }
     return(fieldOption.Id > 0 ? _rep.Update(fieldOption) : _rep.Add(fieldOption));
 }
Пример #4
0
        public IHttpActionResult PostField(Field field)
        {
            if (!ModelState.IsValid)
            {
                return(ApiBadRequest(null, ModelState));
            }

            var fields = _fieldRepository.Add(field);

            return(ApiCreated(field));
        }
        public async Task <IActionResult> Post([FromBody] Field field)
        {
            return(await FunctionWrapper.ExecuteFunction(this, async() =>
            {
                if (string.IsNullOrEmpty(field.Name))
                {
                    throw new System.Exception("Required fields not supplied.");
                }

                return await _fieldRepository.Add(field);
            }));
        }
Пример #6
0
        public void Add(FieldViewModel fieldViewModel)
        {
            var config = _configuration.GetValue <string>("Config:AtletaBase64");

            if (fieldViewModel.Picture == "")
            {
                fieldViewModel.Picture = Divers.Base64ToImage(config, "FIELD");
            }
            else
            {
                fieldViewModel.Picture = Divers.Base64ToImage(fieldViewModel.Picture, "FIELD");
            }

            _fieldRepository.Add(_mapper.Map <Field>(fieldViewModel));
        }
Пример #7
0
        public async Task <bool> Add(Field field)
        {
            if (!ExecuteValidation(new FieldValidation(), field))
            {
                return(false);
            }

            if (_fieldRepository.Find(f => f.Name == field.Name).Result.Any())
            {
                Notify("Já existe outra área com esse nome");
                return(false);
            }

            await _fieldRepository.Add(field);

            return(true);
        }
Пример #8
0
        public IActionResult Create([FromBody] FieldViewModel field)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Field _newField = Mapper.Map <FieldViewModel, Field>(field);

            _newField.DateCreated = DateTime.Now;

            _fieldRepository.Add(_newField);
            _fieldRepository.Commit();

            field = Mapper.Map <Field, FieldViewModel>(_newField);

            CreatedAtRouteResult result = CreatedAtRoute("GetField", new { controller = "Fields", id = field.Id }, field);

            return(result);
        }
Пример #9
0
        public new ValidationResult Add(Field field)
        {
            var validationResult = new ValidationResult();

            if (!field.IsValid())
            {
                validationResult.AddError(field.ValidationResult);
                return(validationResult);
            }

            var validator         = new FieldIsVerifiedForRegistration();
            var validationService = validator.Validate(field);

            if (!validationService.IsValid)
            {
                validationResult.AddError(field.ValidationResult);
                return(validationResult);
            }

            fieldRepository.Add(field);

            return(validationResult);
        }
Пример #10
0
 public void Add(FieldViewModel fieldVm)
 {
     var field = Mapper.Map<FieldViewModel, Field>(fieldVm);
     _fieldRepository.Add(field);
 }
Пример #11
0
 public Field AddField(Field field)
 {
     return(_fieldRep.Add(field));
 }
Пример #12
0
 public void Post([FromBody] Field value)
 {
     _fieldRepository.Add(value);
 }