Ejemplo n.º 1
0
        public void DeleteTheftMethod(TheftMethod theftMethod)
        {
            if (theftMethod == null)
            {
                throw new ArgumentNullException(nameof(theftMethod));
            }

            if (!theftMethod.IsPersisted)
            {
                throw new ArgumentException("theftMethod is not persisted, so cannot delete!");
            }

            lock (theftMethod)
            {
                Controller.Instance.Repository.DeleteTheftMethod(theftMethod.Id);

                // theft-methods are cached in a single collection, so just drop the whole lot from the cache.
                Controller.Instance.CacheManager.Remove("TheftMethods");
            }
        }
Ejemplo n.º 2
0
        public void UpdateTheftMethod(TheftMethod theftMethod)
        {
            if (theftMethod == null)
            {
                throw new ArgumentNullException(nameof(theftMethod));
            }

            if (!theftMethod.IsValid())
            {
                throw new ArgumentException("theftMethod is invalid!");
            }

            lock (theftMethod)
            {
                var            isNew = false;
                DB_TheftMethod dbTheftMethod;
                if (theftMethod.IsPersisted)
                {
                    dbTheftMethod = Controller.Instance.Repository.GetTheftMethod(theftMethod.Id);
                }
                else
                {
                    dbTheftMethod = new DB_TheftMethod();
                    isNew         = true;
                }

                dbTheftMethod.Name = theftMethod.Name;
                Controller.Instance.Repository.UpdateTheftMethod(dbTheftMethod);

                if (!isNew)
                {
                    return;
                }
                theftMethod.Id          = dbTheftMethod.ID;
                theftMethod.IsPersisted = true;
                Controller.Instance.CacheManager.Remove("TheftMethods");
            }
        }