Exemplo n.º 1
0
        /// <summary>
        /// Retrieve a list of tuple (DSRecord, Table) attached to a given record (table, id) for the given profile
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="table"></param>
        /// <param name="id"></param>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <param name="profile"></param>
        /// <param name="area"></param>
        /// <param name="deepUpdate"></param>
        /// <param name="recordAlreadyRead"></param>
        /// <param name="informationAlreadyRead"></param>
        /// <returns></returns>
        public override void GetListRecordsConcernedByUpdate(DSCache cache,
                                                             string table,
                                                             int id,
                                                             int customerId,
                                                             int userId,
                                                             UserProfile.EUserProfile profile,
                                                             string area,
                                                             bool deepUpdate,
                                                             DSRecord recordAlreadyRead,
                                                             InformationRecord informationAlreadyRead)
        {
            if (id < 0 || profile == UserProfile.EUserProfile.None || cache.Is(table, id) != null)
            {
                return;
            }

            // Retrieve the current record

            DSRecord currentRecord = null;
            Tuple <DSRecord, InformationRecord> currentRecordFromCache = cache.GetRecord(this, table, id);

            if (currentRecordFromCache == null && recordAlreadyRead == null)
            {
                switch (table)
                {
                case "Customer":
                    currentRecord = Customer.Find(id);
                    break;

                case "Language":
                    currentRecord = Language.Find(id);
                    break;

                case "User":
                    currentRecord = User.Find(id);
                    break;

                case "Module":
                    currentRecord = Module.Find(id);
                    break;

                case "UserModule":
                    currentRecord = UserModule.Find(id);
                    break;

                default:
                    base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
                    return;
                }

                if (currentRecord == null)
                {
                    cache.Set(table, id, null);
                    return;
                }

                currentRecordFromCache = cache.SetRecord(this, table, id, currentRecord, null);
            }
            else if (currentRecordFromCache == null && recordAlreadyRead != null)
            {
                currentRecordFromCache = cache.SetRecord(this, table, id, recordAlreadyRead, informationAlreadyRead);
            }

            if (currentRecordFromCache != null)
            {
                currentRecord = currentRecordFromCache.Item1;
            }

            // Check if the record is concerned by the current update

            if (currentRecord is DSRecordWithCustomerId currentCustomerRecord)
            {
                if (currentCustomerRecord.CustomerId != customerId)
                {
                    cache.Set(table, id, null);
                    return;
                }
            }

            if (currentRecord is CustomerRecord customer)
            {
                cache.Set(table, id, customer.Id != customerId ? null : currentRecord);
                return;
            }

            if (currentRecord as LanguageRecord != null ||
                currentRecord as ModuleRecord != null ||
                currentRecord as UserModuleRecord != null ||
                currentRecord as UserRecord != null)
            {
                cache.Set(table, id, currentRecord);
                return;
            }

            base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
        }