/// <summary> /// Gets the AssignEssentialOilEffectViewModel. /// </summary> /// <author>Anna Krebs</author> /// <param name="id"></param> /// <returns></returns> private async Task <AssignEssentialOilEffectViewModel> GetEssentialOilEffectViewModel(string id) { var effect = await _effectService.GetByIdAsync(id); if (effect == null) { Log.Error($"An unexpected error occurred while getting id. No entity with id {id} could be found."); throw new ArgumentNullException(string.Format(Resources.Resources.Error_NoEntityWithIdFound, id)); } // Get values from database. var essentialOils = await _essentialOilService.GetAllAsync(new EssentialOilFilter()); var essentialOilEffects = await _essentialOilEffectService.GetAllAsync(new EssentialOilEffectFilter { EffectId = id }); IList <AssignValueViewModel> assignValueViewModels = new List <AssignValueViewModel>(); // Create list of essential oils for view. foreach (var essentialOil in essentialOils) { var assignValueViewModel = new AssignValueViewModel(null, null, essentialOil); foreach (var essentialOilEffect in essentialOilEffects) { // Map values from database to model. if (assignValueViewModel.AssignedValueId == essentialOilEffect.EssentialOilId) { assignValueViewModel.EffectDegree = essentialOilEffect.EffectDegree; } } assignValueViewModels.Add(assignValueViewModel); } var model = new AssignEssentialOilEffectViewModel(null, effect, assignValueViewModels, null); Log.Info($"Get AssignEssentialOilEffectViewModel for effect with id {id}"); return(model); }
public async Task <ActionResult> Index(string lastEditedEssentialOilId) { var filter = new EssentialOilFilter(); // Get all essential oils from database. var essentialOils = await _essentialOilService.GetAllAsync(filter); IList <EssentialOilViewModel> essentialOilViewModels = new List <EssentialOilViewModel>(); // Create list of essential oils for view. foreach (var essentialOil in essentialOils) { essentialOilViewModels.Add(new EssentialOilViewModel(essentialOil)); } // Create view model for Index view. var essentialOilViewModelIndex = new EssentialOilViewModelIndex(essentialOilViewModels); // Set value to where to scroll to. essentialOilViewModelIndex.LastEditedEssentialOilId = lastEditedEssentialOilId; return(View(essentialOilViewModelIndex)); }
public async Task <JsonResult> GetEssentialOilNames() { //return new JsonResult("{name : test}"); try { var filter = new EssentialOilFilter(); // Get all essential oils from database. var essentialOils = await _essentialOilService.GetAllAsync(filter); // Create array of essential oil names. var essentialOilNames = essentialOils.Select(e => e.Name).ToArray(); _log.LogInformation($"Essential oil names '{string.Join(", ", essentialOilNames)}' where loaded."); // TODO: check this //return new JsonResult { Data = essentialOilNames, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(new JsonResult(essentialOilNames)); } catch (Exception e) { return(new JsonResult(new { e.Message, e.StackTrace })); } }