public async Task <bool> AddAsync(int idStyleSheet, Typepography model)
        {
            try
            {
                if (model == null || idStyleSheet == model.Id)
                {
                    return(false);
                }
                var styleSheet = await _dbContext.StyleSheet.FindAsync(idStyleSheet);

                if (styleSheet == null)
                {
                    return(false);
                }
                model.StyleSheet = styleSheet;

                _dbContext.Add(model);
                var saved = await _dbContext.SaveChangesAsync();

                return(saved == 1);
            }
            catch
            {
                return(false);
            }
        }
        public async Task <bool> UpdateTypepography(int idStyleSheet, Typepography model)
        {
            try
            {
                if (idStyleSheet == model.StyleSheetId)
                {
                    return(false);
                }
                var updateModel = await _dbContext.Typepography
                                  .Where(e => e.StyleSheetId == idStyleSheet && e.Id == model.Id)
                                  .SingleOrDefaultAsync();

                updateModel.Typeface = model.Typeface;
                updateModel.Color    = model.Color;
                updateModel.Text     = model.Text;

                var saved = await _dbContext.SaveChangesAsync();

                return(saved == 1);
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
        public async Task <ActionResult <bool> > Put(int id, [FromBody] Typepography model)
        {
            var saved = await _typepographyService.UpdateTypepography(id, model);

            if (saved == false)
            {
                return(BadRequest());
            }

            return(Ok(saved));
        }
Example #4
0
        public async Task <ActionResult <bool> > Post(int id, [FromBody]  Typepography model)
        {
            var saved = await _typepographyService.AddAsync(id, model);

            if (saved == false)
            {
                return(BadRequest(new { message = "Error: bad request" }));
            }

            return(Ok(saved));
        }
        public async Task <Typepography> GetTypepographyAsync(int idTypepography)
        {
            var typepography = new Typepography();

            try
            {
                typepography = await _dbContext.Typepography
                               .Where(e => e.Id == idTypepography)
                               .SingleOrDefaultAsync();
            }
            catch
            {
                return(null);
            }
            return(typepography);
        }