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;
                    }
                    syncEmployee.LastUpdated = TempHelper.GetNowTicks();
                    _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> 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;
                }
                syncEmployee.LastUpdated = TempHelper.GetNowTicks();
                _context.Add(syncEmployee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = GetSelectListDepartment(syncEmployee.DepartmentID);
            return(View(syncEmployee));
        }
        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));
        }
Beispiel #4
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));
        }
        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));
        }