Ejemplo n.º 1
0
        /// <summary>
        /// Fix spam.
        /// </summary>
        /// <param name="userUid"></param>
        /// <param name="dateTimeNow"></param>
        /// <returns></returns>
        public bool CanAddUserPromocode(Guid userUid, DateTime dateTimeNow)
        {
            var userPromocodes = UsersPromocodes?.FirstOrDefault(p => p.UserId == userUid.ToString());

            return(userPromocodes.IsEmpty() ||
                   userPromocodes !.CanAdd(PromocodeOptions, dateTimeNow));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Added the promocode for user.
        /// </summary>
        /// <param name="userUid"></param>
        /// <param name="dbPromocode"></param>
        public DbDiscount AddUserPromocode(Guid userUid, DbPromocode dbPromocode)
        {
            var uidUser = userUid.ToString();

            var dbUserPromocodes = new DbUserPromocodes
            {
                UserId     = uidUser,
                Promocodes = new List <DbPromocode> {
                    dbPromocode
                }
            };

            if (UsersPromocodes.IsEmpty())
            {
                UsersPromocodes = new List <DbUserPromocodes> {
                    dbUserPromocodes
                };
                return(this);
            }

            var newUserPromocodes = UsersPromocodes.FirstOrDefault(i => i.UserId == uidUser);

            if (newUserPromocodes == null)
            {
                UsersPromocodes.Add(dbUserPromocodes);
                return(this);
            }

            newUserPromocodes.Promocodes.Add(dbPromocode);
            return(this);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets count promocodes.
 /// </summary>
 public int GetCountPromocodes() =>
 UsersPromocodes?.Sum(x => x.Promocodes?.Count ?? 0) ?? 0;
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the user promocodes when they are otherwise return <c>null</c>.
 /// </summary>
 /// <param name="userUid"></param>
 /// <returns></returns>
 public DbUserPromocodes GetDbUserPromocodes(Guid userUid) =>
 UsersPromocodes?.FirstOrDefault(i => i.UserId == userUid.ToString());
Ejemplo n.º 5
0
        /// <summary>
        /// Gets true when promocode deleted marked true otherwise false.
        /// </summary>
        /// <param name="userUid"></param>
        /// <param name="promocodeId"></param>
        /// <returns></returns>
        public bool RemoveUserPromocode(Guid userUid, Guid promocodeId)
        {
            var userPromocodes = UsersPromocodes?.FirstOrDefault(p => p.UserId == userUid.ToString());

            return(userPromocodes != null && userPromocodes.RemovePromocode(promocodeId));
        }