示例#1
0
 public void Add(TEntity obj, bool saveChanges = true)
 {
     dbContext.Add(obj);
     if (saveChanges)
     {
         dbContext.SaveChanges();
     }
 }
示例#2
0
        public async Task AddOrUpdate(HeroAddOrUpdateViewModel model)
        {
            var hero = await dbContext.Heroes.FindAsync(model.Id);

            if (hero != null)
            {
                mapper.Map(model, hero);
                await dbContext.SaveChangesAsync();
            }
            else
            {
                var newHero = mapper.Map <Hero>(model);
                dbContext.Add(newHero);
                await dbContext.SaveChangesAsync();
            }
        }
示例#3
0
        public async Task AddOrUpdate(PostAddOrUpdateViewModel model)
        {
            model.Body = model.Body.Replace("background-color: rgb(255, 255, 255);", "");
            var post = await dbContext.Posts.FindAsync(model.Id);

            if (post != null)
            {
                mapper.Map(model, post);
                await dbContext.SaveChangesAsync();
            }
            else
            {
                var newPost = mapper.Map <Post>(model);
                dbContext.Add(newPost);
                await dbContext.SaveChangesAsync();
            }
        }
示例#4
0
        public void Create(T entity)
        {
            _context.Add(entity);

            Save();
        }