public SaveResult Delete(NewsCategoryResult entity) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var cv = context.NewsCategories.Single(x => x.Id == entity.Id && x.IsDeleted == false); cv.IsDeleted = true; cv.LastUpdatedBy = entity.LastUpdatedBy; cv.LastUpdated = DateTime.Now; context.Entry(cv).State = EntityState.Modified; return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> AddAsync(NewsCategoryResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var add = context.NewsCategories.Create(); add.Title = entity.Ten; add.MoTa = entity.MoTa; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; return await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> UpdateAsync(NewsCategoryResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var update = context.NewsCategories.Single(x => x.Id == entity.Id && x.IsDeleted == false); update.Title = entity.Ten; update.MoTa = entity.MoTa; update.IsDeleted = entity.IsDeleted; update.LastUpdatedBy = entity.LastUpdatedBy; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; return await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }