public async Task <RespondModel> InsertAsync(T entity) { var response = new RespondModel(); var dbSet = _appDbContext.Set <T>().Add(entity); await _appDbContext.SaveChangesAsync(); response.data = entity; response.StatusCode = System.Net.HttpStatusCode.OK; return(response); }
/// <summary> Excute sql /// /// </summary> /// <param name="sql"></param> /// <returns></returns> public async Task <RespondModel> ExcuteSqlAsync(string sql) { var respond = new RespondModel(); _appDbContext.Database.ExecuteSqlCommand(sql); await _appDbContext.SaveChangesAsync(); respond.StatusCode = System.Net.HttpStatusCode.OK; return(respond); }
public async Task <RespondModel> InsertAsync(IEnumerable <T> entities) { var response = new RespondModel(); var dbSet = _appDbContext.Set <T>(); foreach (var entity in entities) { dbSet.Add(entity); } await _appDbContext.SaveChangesAsync(); response.StatusCode = System.Net.HttpStatusCode.OK; return(response); }
public async Task <RespondModel> DeleteAsync(T entity) { var response = new RespondModel(); if (entity == null) { response.StatusCode = System.Net.HttpStatusCode.NotFound; return(response); } var dbSet = _appDbContext.Set <T>().Remove(entity); await _appDbContext.SaveChangesAsync(); response.StatusCode = System.Net.HttpStatusCode.OK; return(response); }
public async Task <RespondModel> DeleteAsync(IEnumerable <Guid> ids) { var response = new RespondModel(); if (ids == null || ids.Any()) { response.StatusCode = System.Net.HttpStatusCode.NotFound; } var dbSet = _appDbContext.Set <T>(); dbSet.RemoveRange(Fetch(x => ids.Contains(x.Id))); await _appDbContext.SaveChangesAsync(); response.StatusCode = System.Net.HttpStatusCode.OK; return(response); }
public async Task <RespondModel> DeleteAsync(IEnumerable <T> entities) { var response = new RespondModel(); if (entities == null || entities.Any()) { response.StatusCode = System.Net.HttpStatusCode.NotFound; return(response); } var dbSet = _appDbContext.Set <T>(); foreach (var entity in entities) { dbSet.Remove(entity); } await _appDbContext.SaveChangesAsync(); response.StatusCode = System.Net.HttpStatusCode.OK; return(response); }