public IHttpActionResult GetField(int id) { var field = _fieldRepository.GetById(id); if (field == null) { return(ApiNotFound()); } return(ApiOk(field)); }
public void Process(ObjectLevel source, ObjectLevelViewModel destination, ResolutionContext context) { try { var level = levelRepository.GetById(ObjectId.Parse(source.LevelId)); if (level == null) { throw new Exception("Id level không hợp lệ. "); } var field = fieldRepository.GetById(ObjectId.Parse(source.FieldId)); if (field == null) { throw new Exception("Id field không hợp lệ. "); } destination.LevelName = level.Name; destination.LevelDescription = level.Description; destination.FieldName = field.Value; } catch (Exception e) { Console.WriteLine(e); } }
public async Task <IActionResult> Index(CropPlanViewModel model) { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } if (model.Fields == null) { return(RedirectToAction("Index")); } if (!ModelState.IsValid) { return(View(model)); } foreach (var item in model.Fields) { var field = await _fieldRepository.GetById(item.Id); var plant = await _plantRepository.GetById(item.PlantId); field.Plant = plant; field.PlantVariety = item.PlantVariety; await _fieldRepository.Update(field); } TempData["message"] = "Pomyślnie zapisano zmiany"; return(RedirectToAction("Index")); }
public IEnumerable <FieldEntity> GetSkillParents(int skillId) { var skill = skillRepository.GetById(skillId).ToBllSkill(); var skillParents = new List <FieldEntity>(); var field = fieldRepository.GetById(skill.FieldId).ToBllField(); skillParents.Add(field); while (field.ParentId != null) { field = fieldRepository.GetById(field.ParentId.GetValueOrDefault()).ToBllField(); skillParents.Add(field); } return(skillParents); }
public async Task <IActionResult> Edit(Guid id) { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } // check id passed is that same // check number is unique if (id == null) { return(NotFound()); } var field = await _fieldRepository.GetById(id); if (field == null) { return(NotFound()); } var operators = ManagedYearPlan.Operators; var model = new FieldViewModel() { Id = field.Id, Name = field.Name, Number = field.Number, Parcels = field.Parcels.Select(x => new ParcelViewModel() { Number = x.Number, CultivatedArea = x.CultivatedArea, FuelApplication = x.FuelApplication, OperatorId = x.Operator != null ? x.Operator.Id : Guid.NewGuid(), }).ToList() }; var operatorSelectList = ManagedYearPlan.Operators.Select(x => new SelectListItem() { Text = x.GetName, Value = x.Id.ToString(), }); ViewBag.OperatorSelectList = operatorSelectList; return(View(model)); }
public void Process(FieldGroup source, FieldGroupViewModel destination, ResolutionContext context) { try { destination.Fields = new List <Field>(); foreach (var id in source.FieldId) { var field = fieldRepository.GetById(ObjectId.Parse(id)); if (field != null) { destination.Fields.Add(field); } } } catch (Exception e) { Console.WriteLine(e); } }
public async Task <IActionResult> Create(IList <AddTreatmentViewModel> model) { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } if (!ModelState.IsValid) { var kinds = await _treatmentKindRepository.GetAll(); var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan); var fertilizers = await _fertilizerRepository.GetAll(); var KindList = new SelectList(kinds, "Id", "Name"); var FieldList = new SelectList(fields, "Id", "Name"); var FertilizerList = new SelectList(fertilizers, "Id", "Name"); ViewBag.Kinds = KindList; ViewBag.Fields = FieldList; ViewBag.Fertilizers = FertilizerList; return(View(model)); } var treatments = model.Select((x) => new Treatment { Date = x.Date, Notes = x.Notes, DosePerHa = x.DosePerHa, Composition = x.SprayingAgents, ReasonForUse = x.ReasonForUse, Field = _fieldRepository.GetById(x.FieldId).Result, Fertilizer = _fertilizerRepository.GetById(x.FertilizerId).Result, TreatmentKind = _treatmentKindRepository.GetById(x.TreatmentKindId).Result }); await _treatmentRepository.AddRange(treatments); TempData["message"] = "Pomyślnie dodano nowe zabiegi"; return(RedirectToAction("Index")); }
public Field Get(int id) { return(_fieldRepository.GetById(id)); }
public FieldEntity GetField(int id) { return(fieldRepository.GetById(id) ?.ToBllField()); }
public async Task <FieldViewModel> GetById(int id) { return(_mapper.Map <FieldViewModel>(await _fieldRepository.GetById(id))); }