public async Task <SaveResult> AddAsync(HoSoCongViecResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var add = context.HoSoCongViecs.Create(); add.NgayHetHan = entity.NgayHetHan; add.UserPhuTrachId = entity.UserPhuTrachId; add.UserXuLyId = entity.UserXuLyId; add.LinhVucCongViecId = entity.LinhVucCongViecId; add.NoiDung = entity.NoiDung; add.DanhGiaCongViec = entity.DanhGiaCongViec; add.TrangThaiCongViecId = entity.TrangThaiCongViecId; 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(HoSoCongViecResult entity) { return(await ExecuteDbWithHandle(_logService, async() => { using (var context = new TechOfficeEntities()) { var update = context.HoSoCongViecs.Single(x => x.Id == entity.Id && x.IsDeleted == false); update.NgayHetHan = entity.NgayHetHan; update.UserPhuTrachId = entity.UserPhuTrachId; update.UserXuLyId = entity.UserXuLyId; update.LinhVucCongViecId = entity.LinhVucCongViecId; update.NoiDung = entity.NoiDung; update.DanhGiaCongViec = entity.DanhGiaCongViec; 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; } })); }
public static HoSoCongViecInfo ToDataInfo(this HoSoCongViecResult entity) { return(new HoSoCongViecInfo { Id = entity.Id, NgayHetHan = entity.NgayHetHan, NoiDung = entity.NoiDung, TrangThai = entity.TrangThaiCongViecInfo, }); }
public JsonResult AddRecord(AddCongViecViewModel model) { return(ExecuteWithErrorHandling(() => { var data = new HoSoCongViecResult { CongViecPhoiHopResult = model.UsersPhoiHopId.Select(x => new CongViecPhoiHopResult { UserId = x }), CongViecQuaTrinhXuLyResult = model.QuaTrinhXuLyViewModel.Where(x => x.Gio != 0 && x.Phut != 0) .Select(x => new CongViecQuaTrinhXuLyResult { GioBanHanh = (byte)x.Gio, PhutBanHanh = (byte)x.Phut, NgayBanHanh = x.Ngay, NoiDung = x.NoiDung, NguoiThem = x.NguoiThem, NhacNho = (byte)x.NhacNho, IsDeleted = false }), CongViecVanBanResults = model.VanBanLienQuanViewModel.Where( x => x.CoQuanId.HasValue && x.CoQuanId != 0 && !string.IsNullOrEmpty(x.NoiDung)) .Select(x => new CongViecVanBanResult { SoVanBan = x.SoVanBan, NgayBanHanh = x.Ngay, NoiDung = x.NoiDung, CoQuanId = x.CoQuanId.Value }), NgayHetHan = model.NgayHetHan, NgayTao = model.NgayKhoiTao, LinhVucCongViecId = model.LinhVucCongViecId, UserPhuTrachId = model.UserPhuTrachId, UserXuLyId = model.UserXuLyChinhId, TrangThaiCongViecId = model.TrangThaiCongViecId, NoiDung = model.NoiDungCongViec, CreatedBy = UserName }; return ExecuteResult(() => { var saveResult = HoSoCongViecRepository.AddCongViecWithChildren(data); if (data.Id > 0) { ExecuteTryLogException(() => { MoveFiles(model.Guid, data.Id); }); } return saveResult; }); })); }
public async Task <SaveResult> DeleteAsync(HoSoCongViecResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var hs = context.HoSoCongViecs.Single(x => x.Id == entity.Id && x.IsDeleted == false); hs.IsDeleted = true; hs.LastUpdatedBy = entity.LastUpdatedBy; hs.LastUpdated = DateTime.Now; context.Entry(hs).State = EntityState.Modified; return await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public SaveResult AddCongViecWithChildren(HoSoCongViecResult entity) { return(ExecuteDbWithHandle(_logService, () => { var saveResult = SaveResult.FAILURE; using (var context = new TechOfficeEntities()) { using (var transaction = context.BeginTransaction()) { entity.AddWithChildrenToDb(context); var cv = context.HoSoCongViecs.Local.FirstOrDefault(); saveResult = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; transaction.Commit(); entity.Id = cv != null ? cv.Id : 0; return saveResult; } } })); }
public static HoSoCongViecInfo ToIfNotNullDataInfo(this HoSoCongViecResult entity) { return(entity?.ToDataInfo()); }
public static void AddWithChildrenToDb(this HoSoCongViecResult entity, TechOfficeEntities context) { var hoso = context.HoSoCongViecs.Create(); hoso.NgayHetHan = entity.NgayHetHan; hoso.NgayTao = entity.NgayTao; hoso.UserPhuTrachId = entity.UserPhuTrachId; hoso.UserXuLyId = entity.UserXuLyId; hoso.LinhVucCongViecId = entity.LinhVucCongViecId; hoso.NoiDung = entity.NoiDung; hoso.DanhGiaCongViec = entity.DanhGiaCongViec; hoso.TrangThaiCongViecId = entity.TrangThaiCongViecId; hoso.IsDeleted = entity.IsDeleted; hoso.CreatedBy = entity.CreatedBy; hoso.CreateDate = DateTime.Now; context.Entry(hoso).State = EntityState.Added; foreach (var item in entity.CongViecPhoiHopResult) { var phoiHop = new CongViec_PhoiHop { UserId = item.UserId, HoSoCongViecId = hoso.Id, IsDeleted = false, CreatedBy = hoso.CreatedBy, CreateDate = hoso.CreateDate, }; context.Entry(phoiHop).State = EntityState.Added; } foreach (var item in entity.CongViecQuaTrinhXuLyResult) { var xuly = new CongViec_QuaTrinhXuLy { GioBanHanh = item.GioBanHanh, PhutBanHanh = item.PhutBanHanh, NgayBanHanh = item.NgayBanHanh, NoiDung = item.NoiDung, NguoiThem = item.NguoiThem, NhacNho = item.NhacNho, HoSoCongViecId = hoso.Id, IsDeleted = false, CreatedBy = hoso.CreatedBy, CreateDate = hoso.CreateDate, }; context.Entry(xuly).State = EntityState.Added; } foreach (var item in entity.CongViecVanBanResults) { var vanban = new CongViec_VanBan { HoSoCongViecId = hoso.Id, SoVanBan = item.SoVanBan, NgayBanHanh = item.NgayBanHanh, NoiDung = item.NoiDung, CoQuanId = item.CoQuanId, IsDeleted = false, CreateDate = hoso.CreateDate, CreatedBy = hoso.CreatedBy, }; context.Entry(vanban).State = EntityState.Added; } }