private void InsertOrDeleteThuTucCoQuanThucHien(ThuTucResult entity, TechOfficeEntities context) { if (entity.CoQuanThucHienIds != null && entity.CoQuanThucHienIds.Count() > 0) { //search all thutuc_coquanthuchien by thutucId var searchAll = context.ThuTuc_CoQuanThucHien.Where(x => x.ThuTucId == entity.Id); searchAll.ToList().ForEach(x => { if (!entity.CoQuanThucHienIds.Contains(x.CoQuanId)) { context.Entry(x).State = EntityState.Deleted; } }); entity.CoQuanThucHienIds.ToList().ForEach(x => { if (!searchAll.Select(y => y.CoQuanId).Contains(x))//not exists { //then insert a record var insert = context.ThuTuc_CoQuanThucHien.Create(); insert.ThuTucId = entity.Id; insert.CoQuanId = x; insert.IsDeleted = false; insert.CreateDate = entity.CreateDate; insert.CreatedBy = entity.CreatedBy; context.Entry(insert).State = EntityState.Added; } }); } }
public static ThuTuc AddToDb(this ThuTucResult entity, TechOfficeEntities context) { var thutuc = context.ThuTucs.Create(); thutuc.LoaiThuTucId = entity.LoaiThuTucId; thutuc.NgayBanHanh = entity.NgayBanHanh; thutuc.TenThuTuc = entity.TenThuTuc; thutuc.NoiDung = entity.NoiDung; thutuc.IsDeleted = false; thutuc.CreatedBy = entity.CreatedBy; thutuc.CreateDate = DateTime.Now; context.Entry(thutuc).State = EntityState.Added; foreach (var item in entity.CoQuanThucHienIds) { var thuchien = new ThuTuc_CoQuanThucHien { CoQuanId = item, ThuTucId = thutuc.Id, IsDeleted = false, CreatedBy = thutuc.CreatedBy, CreateDate = thutuc.CreateDate, }; context.Entry(thuchien).State = EntityState.Added; } return(thutuc); }
public SaveResult EditUserWtithRoles(UserResult entity) { return(ExecuteDbWithHandle(_logService, () => { var result = SaveResult.FAILURE; using (var context = new TechOfficeEntities()) { using (var transaction = context.BeginTransaction()) { var update = context.Users.Where(x => x.Id == entity.Id).Single(); update.UserName = entity.UserName; update.IsLocked = entity.IsLocked; update.HoVaTen = entity.HoVaTen; update.ChucVuId = entity.ChucVuId; update.CoQuanId = entity.CoQuanId; update.IsDeleted = entity.IsDeleted; update.LastUpdatedBy = entity.LastUpdatedBy; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; //Remove all roles of user RemoveAllRolesOfUser(context, entity.Id); UserRole role; foreach (var item in entity.UserRoles) { role = context.UserRoles.Create(); role.RoleId = item.RoleInfo.Id; role.UserId = update.Id; role.IsDeleted = entity.IsDeleted; role.CreatedBy = update.CreatedBy; role.CreateDate = update.CreateDate; context.Entry(role).State = EntityState.Added; } result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; transaction.Commit(); } } return result; })); }
public SaveResult AddUserWithRoles(UserResult entity) { return(ExecuteDbWithHandle(_logService, () => { var result = SaveResult.FAILURE; using (var context = new TechOfficeEntities()) { using (var transaction = context.BeginTransaction()) { var add = context.Users.Create(); add.UserName = entity.UserName; add.Password = AppCipher.EncryptCipher(entity.Password); add.IsLocked = entity.IsLocked; add.HoVaTen = entity.HoVaTen; add.ChucVuId = entity.ChucVuId; add.CoQuanId = entity.CoQuanId; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; UserRole role; foreach (var item in entity.UserRoles) { role = context.UserRoles.Create(); role.RoleId = item.RoleInfo.Id; role.UserId = add.Id; role.IsDeleted = entity.IsDeleted; role.CreatedBy = add.CreatedBy; role.CreateDate = add.CreateDate; context.Entry(role).State = EntityState.Added; } result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; transaction.Commit(); } } return result; })); }
public async Task <SaveResult> AddRangeAsync(IEnumerable <CongViecVanBanResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { var add = context.CongViec_VanBan.Create(); add.HoSoCongViecId = entity.HoSoCongViecId; add.NgayBanHanh = entity.NgayBanHanh; add.NoiDung = entity.NoiDung; add.SoVanBan = entity.SoVanBan; add.CoQuanId = entity.CoQuanId; 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 SaveResult AddRange(IEnumerable <HoSoCongViecResult> entities) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { 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 context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
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; } })); }
private void RemoveAllRolesOfUser(TechOfficeEntities context, int userId) { context.UserRoles.Where(x => x.UserId == userId).ToList().ForEach(x => { context.Entry <UserRole>(x).State = EntityState.Deleted; }); }
public SaveResult AddRange(IEnumerable <CongViecQuaTrinhXuLyResult> entities) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { var add = context.CongViec_QuaTrinhXuLy.Create(); add.HoSoCongViecId = entity.HoSoCongViecId; add.GioBanHanh = entity.GioBanHanh; add.PhutBanHanh = entity.PhutBanHanh; add.NgayBanHanh = entity.NgayBanHanh; add.NguoiThem = entity.NguoiThem; add.NhacNho = entity.NhacNho; add.NoiDung = entity.NoiDung; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; } return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> AddRangeAsync(IEnumerable <TapTinThuTucResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { TapTinThuTuc add; foreach (var entity in entities) { add = context.TapTinThuTucs.Create(); add.Url = entity.Url; add.UserUploadId = entity.UserUploadId; add.ThuTucId = entity.ThuTucId; 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> AddAsync(CongViecQuaTrinhXuLyResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var add = context.CongViec_QuaTrinhXuLy.Create(); add.HoSoCongViecId = entity.HoSoCongViecId; add.GioBanHanh = entity.GioBanHanh; add.PhutBanHanh = entity.PhutBanHanh; add.NgayBanHanh = entity.NgayBanHanh; add.NguoiThem = entity.NguoiThem; add.NhacNho = entity.NhacNho; add.NoiDung = entity.NoiDung; 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(CongViecQuaTrinhXuLyResult entity) { return(await ExecuteDbWithHandle(_logService, async() => { using (var context = new TechOfficeEntities()) { var update = context.CongViec_QuaTrinhXuLy .Single(x => x.Id == entity.Id && x.IsDeleted == false); update.GioBanHanh = entity.GioBanHanh; update.PhutBanHanh = entity.PhutBanHanh; update.NgayBanHanh = entity.NgayBanHanh; update.NguoiThem = entity.NguoiThem; update.NhacNho = entity.NhacNho; update.NoiDung = entity.NoiDung; update.HoSoCongViecId = entity.HoSoCongViecId; 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 async Task <SaveResult> AddRangeAsync(IEnumerable <MucDoHoanThanhResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { MucDoHoanThanh add; foreach (var entity in entities) { add = context.MucDoHoanThanhs.Create(); add.Ten = 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; } })); }
/// <summary> /// Adds the range asynchronous. /// </summary> /// <param name="entities">The entities.</param> /// <returns></returns> public async Task <SaveResult> AddRangeAsync(IEnumerable <UserResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { User add; foreach (var entity in entities) { add = context.Users.Create(); add.UserName = entity.UserName; add.Password = AppCipher.EncryptCipher(entity.Password); add.IsLocked = entity.IsLocked; add.HoVaTen = entity.HoVaTen; add.ChucVuId = entity.ChucVuId; add.CoQuanId = entity.CoQuanId; 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 SaveResult AddRange(IEnumerable <TapTinYKienCoQuanResult> entities) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { TapTinYKienCoQuan add; foreach (var entity in entities) { add = context.TapTinYKienCoQuans.Create(); add.Url = entity.Url; add.UserUploadId = entity.UserUploadId; add.YKiencoQuanTacNghiepId = entity.YKienCoQuanId; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; } return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public SaveResult Add(TacNghiepYKienCoQuanResult entity) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var add = context.TacNghiep_YKienCoQuan.Create(); add.NoiDung = entity.NoiDung; add.TacNghiepId = entity.TacNghiepId; add.CoQuanId = entity.CoQuanId; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; var result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; entity.Id = add.Id; return result; } })); }
public async Task <SaveResult> AddRangeAsync(IEnumerable <TacNghiepYKienCoQuanResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { TacNghiep_YKienCoQuan add; foreach (var entity in entities) { add = context.TacNghiep_YKienCoQuan.Create(); add.NoiDung = entity.NoiDung; add.TacNghiepId = entity.TacNghiepId; add.CoQuanId = entity.CoQuanId; 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 SaveResult Update(NewsResult entity) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var update = context.News.FirstOrDefault(x => x.Id == entity.Id); if (update == null) { return SaveResult.FAILURE; } update.Title = entity.Title; update.Content = entity.Content; update.Summary = entity.Summary; update.NewsCategoryId = entity.NewsCategoryId; update.UrlImage = entity.UrlImage; update.IsDeleted = entity.IsDeleted; update.LastUpdatedBy = entity.LastUpdatedBy; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> AddRangeAsync(IEnumerable <NewsResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { var add = context.News.Create(); add.Title = entity.Title; add.Content = entity.Content; add.Summary = entity.Summary; add.UrlImage = entity.UrlImage; add.NewsCategoryId = entity.NewsCategoryId; 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 SaveResult UpdateRange(IEnumerable <CongViecQuaTrinhXuLyResult> entities) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { var update = context.CongViec_QuaTrinhXuLy .Single(x => x.Id == entity.Id && x.IsDeleted == false); update.GioBanHanh = entity.GioBanHanh; update.PhutBanHanh = entity.PhutBanHanh; update.NgayBanHanh = entity.NgayBanHanh; update.NguoiThem = entity.NguoiThem; update.NhacNho = entity.NhacNho; update.NoiDung = entity.NoiDung; update.HoSoCongViecId = entity.HoSoCongViecId; update.IsDeleted = entity.IsDeleted; update.LastUpdatedBy = entity.LastUpdatedBy; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; } return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public SaveResult Add(NewsResult entity) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var add = context.News.Create(); add.Title = entity.Title; add.Content = entity.Content; add.Summary = entity.Summary; add.UrlImage = entity.UrlImage; add.NewsCategoryId = entity.NewsCategoryId; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; var result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; entity.Id = add.Id; return result; } })); }
public SaveResult AddRange(IEnumerable <NhomCoQuanResult> entities) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { NhomCoQuan add; foreach (var entity in entities) { add = context.NhomCoQuans.Create(); add.Ten = 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 context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> AddRangeAsync(IEnumerable <TacNghiepTinhHinhThucHienResult> entities) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { foreach (var entity in entities) { var add = context.TacNghiep_TinhHinhThucHien.Create(); add.ThoiGian = entity.ThoiGian; add.MucDoHoanThanhId = entity.MucDoHoanThanhId; add.TacNghiepId = entity.TacNghiepId; add.CoQuanId = entity.CoQuanId; 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 SaveResult UpdateMucDoHoanThanhForTacNghiep(int id, string userName) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var update = context.TacNghiep_TinhHinhThucHien.Where(x => x.Id == id && x.IsDeleted == false).Single(); if (update.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DANGTHUCHIEN) { update.MucDoHoanThanhId = (int)EnumMucDoHoanThanh.DAHOANHTHANH; update.NgayHoanThanh = DateTime.Now; } else { update.MucDoHoanThanhId = (int)EnumMucDoHoanThanh.DANGTHUCHIEN; update.NgayHoanThanh = null; } update.LastUpdatedBy = userName; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public async Task <SaveResult> UpdateAsync(CoQuanResult entity) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var update = context.CoQuans.FirstOrDefault(x => x.Id == entity.Id && x.IsDeleted == false); if (update == null) { return SaveResult.FAILURE; } update.Ten = entity.Ten; update.MoTa = entity.MoTa; update.NhomCoQuanId = entity.NhomCoQuanId; 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 SaveResult UpdateIncrementMucDoHoanThanh(int tacNghiepId, int coQuanId, string userName, EnumMucDoHoanThanh status) { return(ExecuteDbWithHandle(_logService, () => { using (var context = new TechOfficeEntities()) { var update = context.TacNghiep_TinhHinhThucHien.Where(x => x.TacNghiepId == tacNghiepId && x.CoQuanId == coQuanId && x.IsDeleted == false).FirstOrDefault(); if (update == null)//case not yet record data then insert { update = new TacNghiep_TinhHinhThucHien { CoQuanId = coQuanId, TacNghiepId = tacNghiepId, CreatedBy = userName, CreateDate = DateTime.Now, IsDeleted = false, MucDoHoanThanhId = (int)status, }; context.Entry(update).State = EntityState.Added; } else { if (update.MucDoHoanThanhId <= (int)status) { return SaveResult.SUCCESS; } update.MucDoHoanThanhId = (int)status; update.LastUpdatedBy = userName; update.LastUpdated = DateTime.Now; context.Entry(update).State = EntityState.Modified; } return context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }
public SaveResult AddOrUpdate(int congViecId, IEnumerable <CongViecPhoiHopResult> entities, string userName) { if (entities != null && entities.Any()) { //get all phoi hop by hosocongviecid using (var context = new TechOfficeEntities()) { var listPhoihop = context.CongViec_PhoiHop.Where(x => x.HoSoCongViecId == congViecId).Select(x => new { x.UserId, x.HoSoCongViecId }).ToList(); var listEntities = entities.Select(x => new { x.UserId, x.HoSoCongViecId }); //cac phan tu ton tai trong listPhoiHop nhun ko ton tai trong entites var left = listPhoihop.Except(listEntities); //lay ra cac phan tu ton tain trong entities nhung ko ton tai trong listPhoihop var right = listEntities.Except(listPhoihop); foreach (var item in left) { //remove var remove = context.CongViec_PhoiHop.Where(x => x.HoSoCongViecId == item.HoSoCongViecId && x.UserId == item.UserId).Single(); remove.IsDeleted = true; remove.LastUpdated = DateTime.Now; remove.LastUpdatedBy = userName; context.Entry(remove).State = EntityState.Modified; } foreach (var item in right) { //add var add = context.CongViec_PhoiHop.Create(); add.HoSoCongViecId = item.HoSoCongViecId; add.UserId = item.UserId; add.CreatedBy = userName; add.CreateDate = DateTime.Now; add.IsDeleted = false; context.Entry(add).State = EntityState.Added; } return(context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE); } } return(SaveResult.SUCCESS); }
public static void AddToDb(this LinhVucThuTucResult entity, TechOfficeEntities context) { var add = context.LinhVucThuTucs.Create(); add.Ten = entity.Ten; add.MoTa = entity.MoTa; add.ParentId = entity.ParentId; add.IsDeleted = entity.IsDeleted; add.CreatedBy = entity.CreatedBy; add.CreateDate = DateTime.Now; context.Entry(add).State = EntityState.Added; }
/// <summary> /// Deletes the by asynchronous. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public async Task <SaveResult> DeleteByAsync(int id) { return(await ExecuteDbWithHandleAsync(_logService, async() => { using (var context = new TechOfficeEntities()) { var assembly = context.Users.Single(x => x.Id == id && x.IsDeleted == false); assembly.IsDeleted = true; context.Entry(assembly).State = EntityState.Modified; return await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } })); }