Exemplo n.º 1
0
        public async Task <ActionResult <AppModel> > PutApp([FromRoute, Required] int appId,
                                                            [FromBody, Required] CreateAppModel createApp)
        {
            string error = _authService.CheckId(User.Identity.Name, appId);

            if (error != null)
            {
                return(BadRequest(ErrorModel.IdErrorModel(error)));
            }

            var adminId = _backOfficeContext.Admins.FirstOrDefault(a => a.Name == User.Identity.Name)?.Id;
            var resApp  = _backOfficeContext.Apps.FirstOrDefault(a => (a.Id == appId) && (a.AdminId == adminId));

            resApp.Name = createApp.Name;
            await _backOfficeContext.SaveChangesAsync();

            return(Ok(new AppModel(resApp.Id, resApp.Name)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <AppModel> > PostApp([FromBody, Required] CreateAppModel createApp)
        {
            string error = _authService.CheckId(User.Identity.Name);

            if (error != null)
            {
                return(BadRequest(ErrorModel.IdErrorModel(error)));
            }

            var adminId = _backOfficeContext.Admins.FirstOrDefault(a => a.Name == User.Identity.Name)?.Id;
            // ReSharper disable once PossibleInvalidOperationException
            var app = new App()
            {
                Name = createApp.Name, AdminId = (int)adminId
            };
            var resApp = (await _backOfficeContext.Apps.AddAsync(app)).Entity;
            await _backOfficeContext.SaveChangesAsync();

            return(Ok(new AppModel(resApp.Id, resApp.Name)));
        }