public async Task <T> Update(int id, T entity)
        {
            using (CookieShopDbContext context = _contextFactory.CreateDbContext())
            {
                entity.Id = id;
                context.Set <T>().Update(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
        public async Task <T> Create(T entity) //async used for not interfering with the UI
        {
            using (CookieShopDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <T> createdEntity = await context.Set <T>().AddAsync(entity);

                await context.SaveChangesAsync();

                return(createdEntity.Entity);
            }
        }
        public async Task <bool> Delete(int id)
        {
            using (CookieShopDbContext context = _contextFactory.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id);

                context.Set <T>().Remove(entity);
                await context.SaveChangesAsync();

                return(true);
            }
        }