public async Task <IActionResult> Create([Bind("SynchronizationID,Name")] SyncDepartment syncDepartment) { if (string.IsNullOrEmpty(syncDepartment.SynchronizationID)) { ModelState.AddModelError("SynchronizationID", "SynchronizationID cannot be empty"); } if (ModelState.IsValid) { using (var transaction = _context.Database.BeginTransaction()) { try { syncDepartment.ID = Guid.NewGuid(); CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateDatabaseTimeStamp(syncDepartment, transaction, syncDepartment.SynchronizationID, null); _context.Add(syncDepartment); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(RedirectToAction(nameof(Index))); } return(View(syncDepartment)); }
public IActionResult Index() { try { CustomSyncEngine customSyncEngine = new CustomSyncEngine(databaseContext, syncConfiguration); SyncServer syncServer = new SyncServer(customSyncEngine); IFormFile syncData = Request.Form.Files.FirstOrDefault(); if (syncData == null) { throw new NullReferenceException(nameof(syncData)); } byte[] syncDataBytes = null; using (var memoryStream = new MemoryStream()) { syncData.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); syncDataBytes = new byte[memoryStream.Length]; memoryStream.Read(syncDataBytes, 0, syncDataBytes.Length); } JObject result = syncServer.Process(syncDataBytes); return(Json(result)); } catch (Exception e) { return(Json(SyncServer.JsonErrorResponse(e.Message))); } }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var syncEmployee = await GetDatas().FirstAsync(m => m.ID == id); if (string.IsNullOrEmpty(syncEmployee.SynchronizationID)) { throw new Exception("SynchronizationID cannot be empty"); } using (var transaction = _context.Database.BeginTransaction()) { try { CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreDeleteDatabaseTimeStamp(syncEmployee, transaction, syncEmployee.SynchronizationID, null); _context.Update(syncEmployee); //_context.SyncEmployee.Remove(syncEmployee); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(RedirectToAction(nameof(Index))); }
public DepartmentItemViewModel(INavigation navigation, DatabaseService databaseService, SyncConfiguration syncConfiguration) { this.navigation = navigation; customSyncEngine = new CustomSyncEngine(databaseService, syncConfiguration); transaction = customSyncEngine.Realm.BeginWrite(); synchronizationId = databaseService.GetSynchronizationId(); }
public async Task <IActionResult> Edit(Guid id, [Bind("ID,SynchronizationID,Name")] SyncDepartment syncDepartment) { if (id != syncDepartment.ID) { return(NotFound()); } if (ModelState.IsValid) { try { CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateGlobalTimeStamp(syncDepartment); _context.Update(syncDepartment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SyncDepartmentExists(syncDepartment.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(syncDepartment)); }
public EmployeeItemViewModel(INavigation navigation, DatabaseService databaseService, SyncConfiguration syncConfiguration) { this.navigation = navigation; customSyncEngine = new CustomSyncEngine(databaseService, syncConfiguration); transaction = customSyncEngine.Realm.BeginWrite(); synchronizationId = databaseService.GetSynchronizationId(); IsActiveItems = new List <bool>() { true, false }; DepartmentItems = new List <ReferenceItem>(); DepartmentItems.Add(new ReferenceItem() { Id = Guid.Empty.ToString(), Name = "[None]" }); List <Department> departments = databaseService.GetDepartments().ToList(); for (int i = 0; i < departments.Count; i++) { DepartmentItems.Add(new ReferenceItem() { Id = departments[i].Id, Name = departments[i].Name }); } }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var syncEmployee = await GetDatas().FirstAsync(m => m.ID == id); CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreDeleteGlobalTimeStamp(syncEmployee); _context.Update(syncEmployee); //_context.SyncEmployee.Remove(syncEmployee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("SynchronizationID,Name")] SyncDepartment syncDepartment) { if (ModelState.IsValid) { syncDepartment.ID = Guid.NewGuid(); CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateGlobalTimeStamp(syncDepartment); _context.Add(syncDepartment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(syncDepartment)); }
public async Task <IActionResult> Create([Bind("SynchronizationID,Name,Birthday,NumberOfComputers,SavingAmount,IsActive,DepartmentID")] SyncEmployee syncEmployee) { if (ModelState.IsValid) { syncEmployee.ID = Guid.NewGuid(); if (syncEmployee.DepartmentID == Guid.Empty) { syncEmployee.DepartmentID = null; } CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateGlobalTimeStamp(syncEmployee); _context.Add(syncEmployee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = GetSelectListDepartment(syncEmployee.DepartmentID); return(View(syncEmployee)); }
public async Task <IActionResult> Edit(Guid id, [Bind("ID,SynchronizationID,Name,Birthday,NumberOfComputers,SavingAmount,IsActive,DepartmentID")] SyncEmployee syncEmployee) { if (id != syncEmployee.ID) { return(NotFound()); } if (string.IsNullOrEmpty(syncEmployee.SynchronizationID)) { ModelState.AddModelError("SynchronizationID", "SynchronizationID cannot be empty"); } if (ModelState.IsValid) { using (var transaction = _context.Database.BeginTransaction()) { try { if (syncEmployee.DepartmentID == Guid.Empty) { syncEmployee.DepartmentID = null; } CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateDatabaseTimeStamp(syncEmployee, transaction, syncEmployee.SynchronizationID, null); _context.Update(syncEmployee); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = GetSelectListDepartment(syncEmployee.DepartmentID); return(View(syncEmployee)); }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var syncEmployeeController = new SyncEmployeeController(_context, syncConfiguration); var dependentEmployee = await syncEmployeeController.GetDatas().Where(w => w.DepartmentID == id).FirstOrDefaultAsync(); if (dependentEmployee != null) { throw new Exception($"The data is already used by Employee Name: {dependentEmployee.Name}"); } var syncDepartment = await GetDatas().FirstAsync(m => m.ID == id); CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreDeleteGlobalTimeStamp(syncDepartment); _context.Update(syncDepartment); //_context.Departments.Remove(syncDepartment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(Guid id, [Bind("ID,SynchronizationID,Name,Birthday,NumberOfComputers,SavingAmount,IsActive,DepartmentID")] SyncEmployee syncEmployee) { if (id != syncEmployee.ID) { return(NotFound()); } if (ModelState.IsValid) { try { if (syncEmployee.DepartmentID == Guid.Empty) { syncEmployee.DepartmentID = null; } CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreInsertOrUpdateGlobalTimeStamp(syncEmployee); _context.Update(syncEmployee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SyncEmployeeExists(syncEmployee.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = GetSelectListDepartment(syncEmployee.DepartmentID); return(View(syncEmployee)); }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var syncEmployeeController = new SyncEmployeeController(_context, syncConfiguration); var dependentEmployee = await syncEmployeeController.GetDatas().Where(w => w.DepartmentID == id).FirstOrDefaultAsync(); if (dependentEmployee != null) { throw new Exception($"The data is already used by Employee Name: {dependentEmployee.Name}"); } var syncDepartment = await GetDatas().FirstAsync(m => m.ID == id); if (string.IsNullOrEmpty(syncDepartment.SynchronizationID)) { throw new Exception("SynchronizationID cannot be empty"); } using (var transaction = _context.Database.BeginTransaction()) { try { CustomSyncEngine customSyncEngine = new CustomSyncEngine(_context, syncConfiguration); customSyncEngine.HookPreDeleteDatabaseTimeStamp(syncDepartment, transaction, syncDepartment.SynchronizationID, null); _context.Update(syncDepartment); //_context.Departments.Remove(syncDepartment); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(RedirectToAction(nameof(Index))); }