예제 #1
0
        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;
                }
            }));
        }
예제 #2
0
        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;
                }
            }));
        }
예제 #3
0
        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;
                }
            }));
        }