Esempio n. 1
0
        public ResponseBag <int> Create(EPatrimonio entity)
        {
            // Apply the validations rules to entity.
            var validations = _validationInsertFactory.Create();

            foreach (var validation in validations)
            {
                var result = validation.Validate(entity);
                if (!result.IsValid)
                {
                    return(new ResponseBag <int>
                    {
                        Ok = false,
                        Message = string.Join(", ", result.Errors)
                    });
                }
            }

            // Apply the business rules.
            var rules = _bizRulesInsertFactory.Create();

            foreach (var rule in rules)
            {
                rule.Apply(entity);
            }

            // Save the patrimônio in database.
            var affectedRows = _repository.Create(entity);

            return(new ResponseBag <int>
            {
                Ok = true,
                ObjectResponse = affectedRows
            });
        }
        public int Create(EPatrimonio entity)
        {
            using (var command = _connection.CreateCommand())
            {
                command.CommandText = ProceduresConstants.Prc_Patrimonio_Insert;
                command.CommandType = CommandType.StoredProcedure;

                AddParameter(command, "@Nome", entity.Nome, ParameterDirection.Input);
                AddParameter(command, "@MarcaId", entity.Marca.MarcaId, ParameterDirection.Input);
                AddParameter(command, "@Descricao", entity.Descricao, ParameterDirection.Input);
                AddParameter(command, "@NumTombo", entity.NumTombo, ParameterDirection.Input);
                var paramPatrimonioId = AddParameter(command, "@PatrimonioId", entity.PatrimonioId, ParameterDirection.Output);

                try
                {
                    _connection.Open();
                    var affectedRows = command.ExecuteNonQuery();
                    entity.PatrimonioId = Convert.ToInt64(paramPatrimonioId.Value);

                    return(affectedRows);
                }
                finally
                {
                    _connection.Close();
                }
            }
        }
Esempio n. 3
0
        public IActionResult Create([FromBody] EPatrimonio entity)
        {
            if (entity == null)
            {
                entity = new EPatrimonio();
            }
            var response = _service.Create(entity);

            if (!response.Ok)
            {
                return(BadRequest(new { Message = response.Message }));
            }

            return(CreatedAtRoute("GetPatrimonioById", new { Id = entity.PatrimonioId }, entity));
        }
Esempio n. 4
0
        public IActionResult Update([FromRoute] long id, [FromBody] EPatrimonio entity)
        {
            if (entity == null)
            {
                entity = new EPatrimonio();
            }
            entity.PatrimonioId = id;
            var response = _service.Update(entity);

            if (!response.Ok)
            {
                return(BadRequest(new { Message = response.Message }));
            }
            if (response.ObjectResponse == 0)
            {
                return(NotFound());
            }

            return(Accepted());
        }
        public int Update(EPatrimonio entity)
        {
            using (var command = _connection.CreateCommand())
            {
                command.CommandText = ProceduresConstants.Prc_Patrimonio_Update;
                command.CommandType = CommandType.StoredProcedure;

                AddParameter(command, "@PatrimonioId", entity.PatrimonioId, ParameterDirection.Input);
                AddParameter(command, "@Nome", entity.Nome, ParameterDirection.Input);
                AddParameter(command, "@MarcaId", entity.Marca.MarcaId, ParameterDirection.Input);
                AddParameter(command, "@Descricao", entity.Descricao, ParameterDirection.Input);

                try
                {
                    _connection.Open();
                    return(command.ExecuteNonQuery());
                }
                finally
                {
                    _connection.Close();
                }
            }
        }