Example #1
0
        //[Authorize(Roles = "usuario")]
        public async Task <ActionResult <HistoricPassword> > Put(
            int id,
            [FromServices] DataContext context,
            [FromBody] HistoricPassword model,
            [FromServices] IHistoricPasswordService historicPasswordService)
        {
            var historicPassword = await historicPasswordService.GetHistoricPassword(context, id);

            if (historicPassword == null)
            {
                return(NotFound(new { historicPassword = "******" }));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var putHistoricPassword = await historicPasswordService.PutHistoricPassword(context, model);

            if (putHistoricPassword != null)
            {
                return(Ok(model));
            }

            return(BadRequest(new { historicPassword = "******" }));
        }
Example #2
0
        //[Authorize(Roles ="admin")]
        public async Task <ActionResult <List <HistoricPassword> > > Get(
            [FromServices] DataContext contexto,
            [FromServices] IHistoricPasswordService historicPasswordService
            )
        {
            var historicPasswords = await historicPasswordService.GetAllHistoricPassword(contexto);

            if (historicPasswords == null)
            {
                return(NotFound(new { historicPassword = "******" }));
            }
            return(Ok(historicPasswords));
        }
Example #3
0
        //[Authorize(Roles = "usuario")]
        public async Task <ActionResult <HistoricPassword> > GetById(
            int id,
            [FromServices] DataContext context,
            [FromServices] IHistoricPasswordService historicPasswordService
            )
        {
            var historicPassword = await historicPasswordService.GetHistoricPassword(context, id);

            if (historicPassword == null)
            {
                return(NotFound(new { historicPassword = "******" }));
            }

            return(Ok(historicPassword));
        }
Example #4
0
        //[AllowAnonymous]
        public async Task <ActionResult <HistoricPassword> > Post(
            [FromBody] HistoricPassword model,
            [FromServices] DataContext context,
            [FromServices] IHistoricPasswordService historicPasswordService
            )
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var postHistoricPassword = await historicPasswordService.PostHistoricPassword(context, model);

            if (postHistoricPassword == null)
            {
                return(BadRequest(new { historicPassword = "******" }));
            }
            return(Ok(model));
        }
Example #5
0
        //[Authorize(Roles = "admin")]
        public async Task <ActionResult <HistoricPassword> > Delete(
            int id,
            [FromServices] DataContext context,
            [FromServices] IHistoricPasswordService historicPasswordService
            )
        {
            var historicPassword = await historicPasswordService.GetHistoricPassword(context, id);

            if (historicPassword == null)
            {
                return(NotFound(new { historicPassword = "******" }));
            }

            var deleteHistoricPassword = await historicPasswordService.DeleteHistoricPassword(context, historicPassword);

            if (deleteHistoricPassword.okHistoricPassword)
            {
                return(Ok(deleteHistoricPassword));
            }
            return(BadRequest(deleteHistoricPassword));
        }