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));
        }
Beispiel #2
0
        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));
        }