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")); }
public Field Add(Field Field) { var field = _fieldRepository.Add(Field); _unitOfWork.Commit(); return(field); }
public Field Save(Field fieldOption) { if (fieldOption.SubCategory != null) { fieldOption.SubCategory = null; } return(fieldOption.Id > 0 ? _rep.Update(fieldOption) : _rep.Add(fieldOption)); }
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); })); }
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)); }
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); }
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); }
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); }
public void Add(FieldViewModel fieldVm) { var field = Mapper.Map<FieldViewModel, Field>(fieldVm); _fieldRepository.Add(field); }
public Field AddField(Field field) { return(_fieldRep.Add(field)); }
public void Post([FromBody] Field value) { _fieldRepository.Add(value); }