public async Task <ActionResult <Event> > Put([FromServices] DataBroker Context, int id, Event model)
        {
            try
            {
                var evento = await Context.Events.FirstOrDefaultAsync(x => x.id_event == id);

                if (evento == null)
                {
                    return(Ok("Event not found!"));
                }

                evento.event_name     = model.event_name;
                evento.local          = model.local;
                evento.description    = model.description;
                evento.categories     = model.categories;
                evento.institution_id = model.institution_id;
                evento.event_date     = model.event_date;

                await Context.SaveChangesAsync();

                return(evento);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
        public async Task <ActionResult <Client> > Put([FromServices] DataBroker Context, int id, Client model)
        {
            try
            {
                var cliente = await Context.Clients.FirstOrDefaultAsync(x => x.id == id);

                if (cliente == null)
                {
                    return(Ok("Client not found!"));
                }

                var valid = Validacoes.ValidaCPF(model.cpf);

                if (!valid)
                {
                    return(Ok("CPF is Invalid!"));
                }

                cliente.name       = model.name;
                cliente.cpf        = model.cpf;
                cliente.categories = model.categories;
                cliente.cellphone  = model.cellphone;

                await Context.SaveChangesAsync();

                return(cliente);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
        public async Task <ActionResult <CreditCard> > Put([FromServices] DataBroker Context, int id, CreditCard model)
        {
            try
            {
                var card = await Context.CreditCards.FirstOrDefaultAsync(x => x.card_id == id);

                if (card == null)
                {
                    return(Ok("Client not found!"));
                }

                var valid = Validacoes.ValidaCPF(model.owner_cpf);

                if (!valid)
                {
                    return(Ok("CPF is Invalid!"));
                }

                card.owner_name    = model.owner_name;
                card.owner_cpf     = model.owner_cpf;
                card.card_number   = model.card_number;
                card.cvv           = model.cvv;
                card.card_validity = model.card_validity;

                await Context.SaveChangesAsync();

                return(card);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Institution> > Put([FromServices] DataBroker Context, int id, Institution model)
        {
            try
            {
                var institution = await Context.Institutions.FirstOrDefaultAsync(x => x.id == id);

                if (institution == null)
                {
                    return(Ok("Client not found!"));
                }

                var valid = Validacoes.ValidaCPF(model.cnpj);

                if (!valid)
                {
                    return(Ok("CNPJ is Invalid!"));
                }

                institution.name = model.name;
                institution.cnpj = model.cnpj;
                institution.tipo = model.tipo;

                await Context.SaveChangesAsync();

                return(institution);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <Ticket> > Post([FromServices] DataBroker Context, [FromBody] Ticket model)
        {
            if (ModelState.IsValid)
            {
                Context.Tickets.Add(model);
                await Context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ActionResult <Client> > Post([FromServices] DataBroker Context, [FromBody] Client model)
        {
            var valid = Validacoes.ValidaCPF(model.cpf);

            if (!valid)
            {
                return(Ok("CPF is Invalid!"));
            }

            if (ModelState.IsValid)
            {
                Context.Clients.Add(model);
                await Context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <Institution> > Post([FromServices] DataBroker Context, [FromBody] Institution model)
        {
            var valid = Validacoes.ValidaCNPJ(model.cnpj);

            if (!valid)
            {
                return(Ok("CNPJ is Invalid!"));
            }

            if (ModelState.IsValid)
            {
                Context.Institutions.Add(model);
                await Context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ActionResult <Client> > Delete([FromServices] DataBroker Context, int id)
        {
            try
            {
                var client = await Context.Clients.FirstOrDefaultAsync(x => x.id == id);

                if (client == null)
                {
                    return(Ok("Client not found!"));
                }

                var delete_client = Context.Remove(client);

                await Context.SaveChangesAsync();

                return(client);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <Ticket> > Put([FromServices] DataBroker Context, int id, Ticket model)
        {
            try
            {
                var tickets = await Context.Tickets.FirstOrDefaultAsync(x => x.id_ticket == id);

                if (tickets == null)
                {
                    return(Ok("Ticket not found!"));
                }

                tickets.price    = model.price;
                tickets.type     = model.type;
                tickets.event_id = model.event_id;

                await Context.SaveChangesAsync();

                return(tickets);
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to request on database"));
            }
        }