Exemple #1
0
        public async Task <IActionResult> Update(int id, Bakery bakery)
        {
            if (id != bakery.Id)
            {
                return(BadRequest());
            }

            var bakerymodify = await _repository.GetBy(id);

            if (bakerymodify == null)
            {
                return(NotFound());
            }

            try
            {
                //await _repository.Update(bakery);
                _context.Entry(await _context.Bakery.FirstOrDefaultAsync(x => x.Id == id)).CurrentValues.SetValues(bakery);
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(NotFound());
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <bool> Add(T entity)
        {
            try
            {
                _context.Set <T>().Add(entity);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }