コード例 #1
0
        public async Task <ActionResult> CreateOrEdit(string id)
        {
            EssentialOilViewModel model;

            // Get EssentialOilViewModel according to whether is edit or create.
            if (!string.IsNullOrEmpty(id))
            {
                // Edit
                var essentialOil = await _essentialOilService.GetByIdAsync(id);

                if (essentialOil == 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));
                }

                model = new EssentialOilViewModel(essentialOil);
            }
            else
            {
                // Create
                model = new EssentialOilViewModel();
            }

            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> EssentialOilDetails(List <SearchEffectItem> searchEffects, string essentialOilId)
        {
            if (string.IsNullOrEmpty(essentialOilId))
            {
                Log.Error("An unexpected error occurred while getting id. No id was set.");
                throw new ArgumentNullException(
                          $"{Resources.Resources.Error_UnexpectedError} {Resources.Resources.Error_TryAgainLater}");
            }

            // Get EssentialOilViewModel.
            var essentialOil = await _essentialOilService.GetByIdAsync(essentialOilId);

            if (essentialOil == null)
            {
                Log.Error(
                    $"An unexpected error occurred while getting id. No entity with id {essentialOilId} could be found.");
                throw new ArgumentNullException(string.Format(Resources.Resources.Error_NoEntityWithIdFound,
                                                              essentialOilId));
            }

            // Get the assigned values for the essential oil.
            essentialOil.Effects = await _essentialOilService.GetAssignedEffectsForEssentialOilAsync(essentialOil.Id);

            essentialOil.Molecules =
                await _essentialOilService.GetAssignedMoleculesForEssentialOilAsync(essentialOil.Id);

            var model = new EssentialOilViewModel(essentialOil);

            // Add searched effects to model, in order to restore them later, if "Zurück" is clicked.
            model.SearchEffects = searchEffects;

            Log.Info("Show EssentialOilDetails");
            // Return PartialView as html.
            return(PartialView("~/Views/SearchEssentialOil/_EssentialOilDetails.cshtml", model));
        }
コード例 #3
0
        public async Task <ActionResult> EssentialOilDetails(string essentialOilId, string searchEssentialOilText)
        {
            if (string.IsNullOrEmpty(essentialOilId))
            {
                _log.LogError("An unexpected error occurred while getting id. No id was set.");
                throw new ArgumentNullException(
                          $"{Resources.Resources.Error_UnexpectedError} {Resources.Resources.Error_TryAgainLater}");
            }

            // Get EssentialOilViewModel.
            var essentialOil = await _essentialOilService.GetByIdAsync(essentialOilId);

            if (essentialOil == null)
            {
                _log.LogError(
                    $"An unexpected error occurred while getting id. No entity with id {essentialOilId} could be found.");
                throw new ArgumentNullException(string.Format(Resources.Resources.Error_NoEntityWithIdFound,
                                                              essentialOilId));
            }

            // Get the assigned values for the essential oil.
            essentialOil.Effects = await _essentialOilService.GetAssignedEffectsForEssentialOilAsync(essentialOil.Id);

            essentialOil.Molecules =
                await _essentialOilService.GetAssignedMoleculesForEssentialOilAsync(essentialOil.Id);

            var model = new EssentialOilViewModel(essentialOil);

            model.SearchEssentialOilText = searchEssentialOilText;


            _log.LogInformation("Show EssentialOilDetails");
            // Return PartialView as html.
            return(PartialView("_EssentialOilDetails", model));
        }