Exemplo n.º 1
0
        public Nutraceutical Register(RegisterNutraceuticalCommand command)
        {
            // Cria a instâcia do usuário
            var domain = new Nutraceutical(command.Name, command.Pharmacology, command.ActionMechanism, command.Indications, command.AgainstIndications, command.AdverseReactions,
                                           command.DrugInteractions, command.DescriptionDosages, command.RecomendedDosages, command.NutraceuticalReferences, command.NutraceuticalType, command.MinDosage,
                                           command.MaxDosage, command.Unity, command.MedicalOnly, command.CommonName);

            // Tenta ações e regras de negócio no domínio
            //domain.Register();

            // Salva as alterações da tabela no contexto do banco de dados
            _repository.Save(domain);

            // Chama o commit
            if (Commit())
            {
                // Dispara o evento de usuário registrado
                DomainEvent.Raise(new OnNutraceuticalRegisteredEvent(domain));

                // Retorna o usuário
                return(domain);
            }

            // Se não comitou, retorna nulo
            return(null);
        }
Exemplo n.º 2
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                NutraceuticalType nutraceuticalType;
                Enum.TryParse(collection["NutraceuticalType"], out nutraceuticalType);

                bool medicalOnly = Convert.ToBoolean(collection["MedicalOnly"].Split(',')[0]);

                var nutraceutical = new RegisterNutraceuticalCommand(collection["Name"], collection["Pharmacology"], collection["ActionMechanism"], collection["Indications"],
                                                                     collection["AgainstIndications"], collection["AdverseReactions"], collection["DrugInteractions"], collection["DescriptionDosages"], collection["RecomendedDosages"],
                                                                     collection["NutraceuticalReferences"], nutraceuticalType,
                                                                     (!string.IsNullOrEmpty(collection["MinDosage"]) ? Convert.ToInt16(collection["MinDosage"]) : Convert.ToInt16("0")),
                                                                     (!string.IsNullOrEmpty(collection["MaxDosage"]) ? Convert.ToInt16(collection["MaxDosage"]) : Convert.ToInt16("0")),
                                                                     collection["Unity"], medicalOnly, collection["CommonName"]);

                _serviceNutraceutical.Register(nutraceutical);

                return(RedirectToAction("Index"));
            }
            catch (Exception msg)
            {
                var mensagemError = msg.Message;
                return(View());
            }
        }