Exemple #1
0
        public BackEnd.Controllers.Response.CadastroPetResponse cadastrarPet(BackEnd.Controllers.Request.CadastroPetRequest request)
        {
            Models.TbPet Pet = new Models.TbPet();

            Pet.NmPet          = request.NomePet;
            Pet.TpPet          = request.TipoPet;
            Pet.DsMedicamentos = request.Medicamentos;
            Pet.DsPeso         = request.Peso;
            Pet.DsPorte        = request.Porte;
            Pet.DsRaca         = request.Raca;
            Pet.DsSexo         = request.Sexo;
            Pet.DtNascimento   = request.Nascimento;
            Pet.IdCliente      = request.IdCliente;

            ctx.Add(Pet);
            ctx.SaveChanges();

            BackEnd.Controllers.Response.CadastroPetResponse response = new BackEnd.Controllers.Response.CadastroPetResponse();

            response.IdCliente    = request.IdCliente;
            response.IdPet        = Pet.IdPet;
            response.Medicamentos = request.Medicamentos;
            response.Nascimento   = request.Nascimento;
            response.NomePet      = request.NomePet;
            response.Peso         = request.Peso;
            response.Porte        = request.Porte;
            response.Raca         = request.Raca;
            response.Sexo         = request.Sexo;
            response.TipoPet      = request.TipoPet;

            return(response);
        }
Exemple #2
0
        public BackEnd.Controllers.Response.CadastroPetResponse CadastrarPet(BackEnd.Controllers.Request.CadastroPetRequest request)
        {
            Database.CadastroPetDatabase database = new Database.CadastroPetDatabase();

            if (string.IsNullOrEmpty(request.NomePet))
            {
                throw new Exception("Nome Inválido");
            }

            if (request.Peso.HasValue == false || request.Peso < 0)
            {
                throw new Exception("Peso Inválido");
            }

            if (string.IsNullOrEmpty(request.Sexo))
            {
                throw new Exception("Sexo Inválido");
            }

            if (string.IsNullOrEmpty(request.Porte))
            {
                throw new Exception("Porte Inválido");
            }

            if (string.IsNullOrEmpty(request.Raca))
            {
                throw new Exception("Raça Inválida");
            }

            if (string.IsNullOrEmpty(request.TipoPet))
            {
                throw new Exception("Tipo de Pet Inválido");
            }

            BackEnd.Controllers.Response.CadastroPetResponse response = database.cadastrarPet(request);

            return(response);
        }
        public ActionResult <BackEnd.Controllers.Response.CadastroPetResponse> SalvarPet(BackEnd.Controllers.Request.CadastroPetRequest request)
        {
            try
            {
                Business.CadastroPetBusiness business = new Business.CadastroPetBusiness();

                BackEnd.Controllers.Response.CadastroPetResponse response = business.CadastrarPet(request);

                return(response);
            }
            catch (System.Exception ex)
            {
                return(new BadRequestObjectResult(
                           new BackEnd.Controllers.Response.ErroResponse(ex, 400)
                           ));
            }
        }