コード例 #1
0
 private void _refreshCache()
 {
     if (!string.IsNullOrEmpty(this.SQLConnectionString))
     {
         _cache = new Dictionary <int, AbsenceStatus>();
         using (SqlConnection connection = new SqlConnection(SQLConnectionString))
         {
             using (SqlCommand sqlCommand = new SqlCommand())
             {
                 sqlCommand.Connection  = connection;
                 sqlCommand.CommandType = CommandType.Text;
                 sqlCommand.CommandText = SelectSQL;
                 sqlCommand.Connection.Open();
                 SqlDataReader dataReader = sqlCommand.ExecuteReader();
                 if (dataReader.HasRows)
                 {
                     while (dataReader.Read())
                     {
                         AbsenceStatus parsedObject = dataReaderToObject(dataReader);
                         if (parsedObject != null)
                         {
                             _cache.Add(parsedObject.ID, parsedObject);
                         }
                     }
                 }
                 sqlCommand.Connection.Close();
             }
         }
     }
     else
     {
         throw new InvalidConnectionStringException("Connection string is empty");
     }
 }
コード例 #2
0
        public IActionResult Update(int id)
        {
            AbsenceStatus absenceStatus = absenceService.GetById(id);

            AbsenceStatusViewModel model = new AbsenceStatusViewModel {
            };

            model.AbsenceType = absenceStatus.AbsenceType;
            model.EndDate     = absenceStatus.EndDate;
            model.Id          = absenceStatus.Id;
            model.StartDate   = absenceStatus.StartDate;
            model.User        = absenceStatus.User;

            AddAbsenceTypesToViewBag();

            return(View(model));
        }
コード例 #3
0
        public IActionResult Update(AbsenceStatusViewModel model)
        {
            AddAbsenceTypesToViewBag();
            if (ModelState.IsValid)
            {
                AbsenceStatus absenceStatus = new AbsenceStatus();
                absenceStatus.AbsenceTypeId = model.AbsenceType.Id;
                absenceStatus.StartDate     = model.StartDate;
                absenceStatus.EndDate       = model.EndDate;
                absenceStatus.Id            = model.Id;
                absenceStatus.UserId        = model.User.Id;

                absenceService.Update(absenceStatus);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #4
0
        public IActionResult Add(AbsenceStatusViewModel model)
        {
            AddUsersToViewBag();
            AddAbsenceTypesToViewBag();
            if (ModelState.IsValid)
            {
                AbsenceStatus absenceStatus = new AbsenceStatus()
                {
                    AbsenceTypeId = model.AbsenceType.Id,
                    EndDate       = model.EndDate,
                    StartDate     = model.StartDate,
                    UserId        = model.User.Id
                };

                absenceService.Add(absenceStatus);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #5
0
 public void Update(AbsenceStatus absenceStatus)
 {
     crudableDAL.Update(absenceStatus);
 }
コード例 #6
0
 public void Remove(AbsenceStatus absenceStatus)
 {
     crudableDAL.Remove(absenceStatus);
 }
コード例 #7
0
 public void Add(AbsenceStatus absenceStatus)
 {
     crudableDAL.Add(absenceStatus);
 }
コード例 #8
0
 public void Update(AbsenceStatus absenceStatus)
 {
     absenceStatusDAL.Update(absenceStatus);
 }
コード例 #9
0
 public void Remove(AbsenceStatus absenceStatus)
 {
     absenceStatusDAL.Remove(absenceStatus);
 }
コード例 #10
0
 public void Add(AbsenceStatus absenceStatus)
 {
     absenceStatusDAL.Add(absenceStatus);
 }
コード例 #11
0
        public static void Sync(ConfigFile configFile, LogDelegate Log)
        {
            ConfigFileSyncPermissionsSection config = configFile.AbsenceStatusPermissions;

            Log("========= ABSENCE STATUSES ========= ");
            if (!config.AllowSync)
            {
                Log("This sync module is disabled in config file - skipping");
                return;
            }
            InternalAbsenceStatusRepository internalRepository = new InternalAbsenceStatusRepository(configFile.DatabaseConnectionString_Internal);
            SLAbsenceStatusRepository       externalRepository = new SLAbsenceStatusRepository(configFile.DatabaseConnectionString_SchoolLogic);

            List <AbsenceStatus> externalObjects = externalRepository.GetAll();

            Log("Found " + internalRepository.GetAllIDs().Count() + " statuses in internal database");
            Log("Found " + externalObjects.Count() + " statuses in external database");

            // Find previously unknown
            // Find objects that need an update
            List <AbsenceStatus> previouslyUnknown = new List <AbsenceStatus>();
            List <AbsenceStatus> needingUpdate     = new List <AbsenceStatus>();
            List <AbsenceStatus> noLongerExistsInExternalSystem = new List <AbsenceStatus>();

            foreach (AbsenceStatus externalObject in externalObjects)
            {
                // Check to see if we know about this school already
                AbsenceStatus internalObject = internalRepository.Get(externalObject.ID);
                if (internalObject == null)
                {
                    previouslyUnknown.Add(externalObject);
                }

                // Check to see if this school requires an update
                if (internalObject != null)
                {
                    UpdateCheck check = internalObject.CheckIfUpdatesAreRequired(externalObject);
                    if ((check == UpdateCheck.UpdatesRequired) || (config.ForceUpdate))
                    {
                        needingUpdate.Add(externalObject);
                    }
                }
            }

            // Find objects that are no longer in the database that could potentially be cleaned up
            if (config.AllowRemovals)
            {
                List <int> foundIDs = externalRepository.GetAllIDs();
                foreach (AbsenceStatus internalObject in internalRepository.GetAll())
                {
                    if (!foundIDs.Contains(internalObject.ID))
                    {
                        noLongerExistsInExternalSystem.Add(internalObject);
                    }
                }
            }

            Log("Found " + previouslyUnknown.Count() + " previously unknown");
            Log("Found " + needingUpdate.Count() + " with updates");
            Log("Found " + noLongerExistsInExternalSystem.Count() + " not in external database");

            // Commit these changes to the database
            if (previouslyUnknown.Count > 0)
            {
                if (config.AllowAdds)
                {
                    Log(" > Adding " + previouslyUnknown.Count() + " new objects");
                    internalRepository.Add(previouslyUnknown);
                }
                else
                {
                    Log(" > Not allowed to add, skipping " + previouslyUnknown.Count() + " adds");
                }
            }


            if (needingUpdate.Count > 0)
            {
                if (config.AllowUpdates)
                {
                    Log(" > Updating " + needingUpdate.Count() + " objects");
                    internalRepository.Update(needingUpdate);
                }
                else
                {
                    Log(" > Not allowed to do updates, skipping " + needingUpdate.Count() + " updates");
                }
            }

            if (noLongerExistsInExternalSystem.Count > 0)
            {
                if (config.AllowRemovals)
                {
                    Log(" > If removals were implemented, we would remove " + noLongerExistsInExternalSystem.Count() + " objects here");
                }
                else
                {
                    Log(" > Not allowed to remove, skipping " + noLongerExistsInExternalSystem.Count() + " removals");
                }
            }
        }