Ejemplo n.º 1
0
        public async Task <ActionResult <AppUserTokenModel> > Update(
            [FromRoute] long id,
            [FromBody] AppUserTokenModel model
            )
        {
            try {
                var userId = this.GetUserId();
                var exists = await userTokenRepo.ExistsAsync(id, userId);

                if (!exists)
                {
                    return(NotFound());
                }
                var user = await userMgr.FindByIdAsync(userId);

                if (user == null)
                {
                    return(BadRequest("Invalid user !"));
                }
                await userTokenRepo.UpdateTokenForUserAsync(id, model, user);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not update token by id {id} with {model.ToJson()} for user {User.Identity.Name} .");
                return(this.InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <AppUserTokenModel> > Create(
            [FromBody] AppUserTokenModel model
            )
        {
            try {
                await repository.SaveAsync(model);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not save {model.ToJson()} to app_user_tokens.");
                return(this.InternalServerError(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <AppUserTokenModel> > Save(
            [FromBody] AppUserTokenModel model
            )
        {
            try {
                var user = await userMgr.FindByIdAsync(this.GetUserId());

                if (user == null)
                {
                    return(BadRequest("Invalid user !"));
                }
                await userTokenRepo.SaveTokenForUserAsync(model, user);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not save token {model.ToJson()} to for user {User.Identity.Name} .");
                return(this.InternalServerError(ex));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <AppUserTokenModel> > Update(
            [FromRoute] long id,
            [FromBody] AppUserTokenModel model
            )
        {
            try {
                var exists = await repository.ExistAsync(id);

                if (!exists)
                {
                    return(NotFound());
                }
                await repository.UpdateAsync(id, model);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not update app_user_tokens by id {id} with {model.ToJson()} .");
                return(this.InternalServerError(ex));
            }
        }