Beispiel #1
0
        public CommandResult Atualizar(AtualizarMaterialCommand command)
        {
            string entityName = "Material";

            try
            {
                command.Validate();
                if (command.Invalid)
                {
                    return(CommandResult.Invalid(command.Notifications.ToNotificationsString()));
                }

                Material material = dataContext.Material.FirstOrDefault(x => x.Cod_Material == command.Cod_Material);

                if (material is null)
                {
                    return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Material)));
                }


                if (dataContext.Material.Any(x => x.Descricao == command.Descricao.ToUpper() && x.Cod_Material != command.Cod_Material))
                {
                    string message = "Já existe outro Material com este nome.";
                    return(CommandResult.Invalid(message));
                }

                material.Atualizar(DataString.FromString(command.Descricao),
                                   command.Volume,
                                   DataString.FromNullableString(command.Material_Coletado),
                                   DataString.FromNullableString(command.Material_Coletado));

                //if (material.HasNotifications)
                //{
                //    return CommandResult.Invalid(material.Notifications.ToNotificationsString());
                //}

                dataContext.SaveChanges();
                return(CommandResult.Valid());
            }
            catch (Exception ex)
            {
                return(CommandResult.Invalid(ex.Message));
            }
        }
 public IActionResult Atualizar(
     [FromServices] IMaterialService service,
     [FromBody] AtualizarMaterialCommand command)
 {
     return(Result(service.Atualizar(command)));
 }