Example #1
0
        /// <summary>
        ///     Inserts all assigned molecules for essential oil in database.
        /// </summary>
        /// <author>Anna Krebs</author>
        /// <param name="model"></param>
        /// <param name="assignValueViewModel"></param>
        /// <returns></returns>
        private async Task <ValidationResultList> AssignMoleculeToEssentialOil(AssignMoleculeViewModel model,
                                                                               AssignValueViewModel assignValueViewModel)
        {
            var validationResult = new ValidationResultList();

            // Only assign, if MoleculePercentage was assigned.
            if (assignValueViewModel.MoleculePercentage.HasValue && assignValueViewModel.MoleculePercentage.Value > 0)
            {
                var essentialOilMolecule = new EssentialOilMolecule();

                // Map view model to entity.
                essentialOilMolecule.EssentialOilId     = model.EssentialOilId;
                essentialOilMolecule.MoleculeId         = assignValueViewModel.AssignedValueId;
                essentialOilMolecule.MoleculePercentage = assignValueViewModel.MoleculePercentage.Value;

                validationResult = await _essentialOilMoleculeService.InsertAsync(essentialOilMolecule);

                Log.Info(
                    $"Assign molecule with id {assignValueViewModel.AssignedValueId} to essential oil with id {model.EssentialOilId}");
            }

            return(validationResult);
        }