示例#1
0
        /// <summary>
        /// Updates day slot
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="newOnly"></param>
        /// <returns></returns>
        public virtual async Task <bool> SetDaySlot(Slot1Day slot, bool newOnly)
        {
            if (slot is null)
            {
                throw new ArgumentNullException(nameof(slot));
            }

            try
            {
                var ret = await redisCacheClient.Db0.HashSetAsync($"{configuration["db-prefix"]}{REDIS_KEY_SLOT_OBJECTS_D}", $"{slot.PlaceId}_{slot.Time.Ticks}", slot, newOnly);

                if (newOnly && !ret)
                {
                    throw new Exception(localizer[Repository_RedisRepository_SlotRepository.Error_creating_day_slot].Value);
                }
                await redisCacheClient.Db0.SetAddAsync($"{configuration["db-prefix"]}{REDIS_KEY_SLOT_OBJECTS_D_BY_PLACE}_{slot.PlaceId}", $"{slot.PlaceId}_{slot.Time.Ticks}");

                return(true);
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Decrement registrations for day slot
        /// </summary>
        /// <param name="slotD"></param>
        /// <returns></returns>
        public async Task DecrementRegistrationDaySlot(Slot1Day slotD)
        {
            if (slotD is null)
            {
                throw new ArgumentNullException(nameof(slotD));
            }

            var update = await GetDaySlot(slotD.PlaceId, slotD.Time.Ticks);

            update.Registrations--;
            await SetDaySlot(update, false);
        }
示例#3
0
        /// <summary>
        /// Decrement registrations for day slot
        /// </summary>
        /// <param name="slotD"></param>
        /// <returns></returns>
        public async Task <long> DecrementRegistrationDaySlot(Slot1Day slotD)
        {
            if (slotD is null)
            {
                throw new ArgumentNullException(nameof(slotD));
            }

            var update = await GetDaySlot(slotD.PlaceId, slotD.Time.UtcTicks);

            update.Registrations = await DecrementStats(StatsType.Enum.RegisteredTo, SlotType.Enum.Day, slotD.PlaceId, slotD.Time);
            await SetDaySlot(update, false);

            return(update.Registrations);
        }
示例#4
0
        /// <summary>
        /// Deletes single day slot
        /// </summary>
        /// <param name="slot"></param>
        /// <returns></returns>
        public async override Task <bool> DeleteDaySlot(Slot1Day slot)
        {
            if (slot is null)
            {
                throw new ArgumentNullException(nameof(slot));
            }

            string key = $"{slot.PlaceId}_{slot.Time.UtcTicks}";

            if (dataD.ContainsKey(key))
            {
                dataD.TryRemove(key, out var _);
                return(true);
            }
            return(false);
        }
示例#5
0
        /// <summary>
        /// Set
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="newOnly"></param>
        /// <returns></returns>
        public override async Task <bool> SetDaySlot(Slot1Day slot, bool newOnly)
        {
            if (slot is null)
            {
                throw new ArgumentNullException(nameof(slot));
            }
            string key = $"{slot.PlaceId}_{slot.Time.UtcTicks}";

            if (newOnly)
            {
                if (dataD.ContainsKey(key))
                {
                    throw new Exception("Item already exists");
                }
            }
            dataD[key] = slot;
            return(true);
        }
示例#6
0
        /// <summary>
        /// Deletes day slot
        /// </summary>
        /// <param name="slot"></param>
        /// <returns></returns>
        public virtual async Task <bool> DeleteDaySlot(Slot1Day slot)
        {
            if (slot is null)
            {
                throw new ArgumentNullException(nameof(slot));
            }

            try
            {
                var ret = await redisCacheClient.Db0.HashDeleteAsync($"{configuration["db-prefix"]}{REDIS_KEY_SLOT_OBJECTS_D}", $"{slot.PlaceId}_{slot.Time.Ticks}");

                return(true);
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(false);
            }
        }
示例#7
0
 /// <summary>
 /// Create day slot
 /// </summary>
 /// <param name="slot"></param>
 /// <returns></returns>
 public Task <bool> Add(Slot1Day slot)
 {
     return(SetDaySlot(slot, true));
 }