public void AddField(NewFieldVm newField, int landId, string userId) { var field = _mapper.Map <Field>(newField); field.LandId = landId; field.UserId = userId; _genericRepository.Add <Field>(field); _landRepository.ChangeAcreageOccupied(field.Acreage, landId); }
public IActionResult AddField(NewFieldVm model, int landId) { var land = _landService.GetLandById(landId); if (land.AcreageFree < model.Acreage) { return(RedirectToAction("NoFreeAcreage", new { landName = land.PlotNumber })); } if (ModelState.IsValid) { _fieldService.AddField(model, landId, userId); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult AddField() { var land = _landService.GetAllLandForList(userId); if (land.Count == 0) { return(RedirectToAction("LandDontExist")); } //Dropdown list with plot number var landSelectList = _landService.GetAllLandForSelectList(userId); //Dropdown list with agricultural Class var agrClassSelectList = _agriculturalClassService.GetAllAgriculturalClassForSelectList(); var viewModel = new NewFieldVm() { Lands = landSelectList, AgriculturalClasses = agrClassSelectList }; return(View(viewModel)); }
public void UpdateField(NewFieldVm model) { var field = _mapper.Map <Field>(model); _fieldRepository.UpdateField(field); }