示例#1
0
        public async Task <UserViewModel> ResetField(UserResetFieldRequest request)
        {
            User user = await userRepository.GetByIdAsync(ObjectId.Parse(request.UserId));

            if (user != null)
            {
                foreach (string item in request.FieldId)
                {
                    FilterDefinitionBuilder <ObjectLevel> finder = Builders <ObjectLevel> .Filter;
                    FilterDefinition <ObjectLevel>        filter = finder.Eq("field_id", item) & finder.Eq("object_id", user.OId);
                    ObjectLevel objectLevel = await objectLevelRepository.FindAsync(filter);

                    if (objectLevel != null)
                    {
                        objectLevel.LevelId      = Constants.LevelConstants.LEVEL_0_ID;
                        objectLevel.Point        = 0;
                        objectLevel.ModifiedDate = DateTime.Now;
                        await objectLevelRepository.UpdateAsync(objectLevel, objectLevel.Id);
                    }
                }

                return(mapper.Map <UserViewModel>(user));
            }
            else
            {
                throw new Exception("Không tìm thấy user. ");
            }
        }
示例#2
0
        public async Task <IEnumerable <ObjectLevelViewModel> > AddObjectLevel(IEnumerable <ObjectLevel> objectLevels)
        {
            List <ObjectLevel> result = new List <ObjectLevel>();

            foreach (ObjectLevel item in objectLevels)
            {
                Level existLevel = await levelRepository.GetByIdAsync(ObjectId.Parse(item.LevelId));

                if (existLevel != null)
                {
                    ObjectLevel model = new ObjectLevel()
                    {
                        LevelId  = item.LevelId,
                        ObjectId = item.ObjectId,
                        FieldId  = item.FieldId,
                        Point    = item.Point
                    };
                    await objectLevelRepository.AddAsync(model);

                    result.Add(model);
                }
            }

            return(mapper.Map <IEnumerable <ObjectLevelViewModel> >(result));
        }
示例#3
0
        public async Task <UserViewModel> AddOrUpdateUserFields(UserAddFieldRequest request)
        {
            User user = await userRepository.GetByIdAsync(ObjectId.Parse(request.UserId));

            if (user != null)
            {
                FilterDefinition <ObjectLevel> buidler = Builders <ObjectLevel> .Filter.Eq("object_id", request.UserId);

                List <ObjectLevel> existObjectLevels = (await objectLevelRepository.FindListAsync(buidler)).ToList();

                foreach (string item in request.FieldId)
                {
                    var existObjectLevel = existObjectLevels.FirstOrDefault(x => x.FieldId == item);
                    if (existObjectLevel != null)
                    {
                        if (existObjectLevel.IsActive == false)
                        {
                            existObjectLevel.IsActive = true;
                        }

                        existObjectLevel.ModifiedDate = DateTime.Now;
                        await objectLevelRepository.UpdateAsync(existObjectLevel, existObjectLevel.Id);
                    }
                    else
                    {
                        ObjectLevel objectLevel = new ObjectLevel()
                        {
                            LevelId  = Constants.LevelConstants.LEVEL_0_ID,
                            FieldId  = item,
                            ObjectId = user.OId,
                            Point    = 0
                        };
                        await objectLevelRepository.AddAsync(objectLevel);
                    }
                }

                foreach (var ex in existObjectLevels)
                {
                    if (request.FieldId.FirstOrDefault(x => x == ex.FieldId) == null)
                    {
                        ex.IsActive     = false;
                        ex.ModifiedDate = DateTime.Now;
                        await objectLevelRepository.UpdateAsync(ex, ex.Id);
                    }
                }
                return(mapper.Map <UserViewModel>(user));
            }
            else
            {
                throw new Exception("Không tìm thấy user");
            }
        }
示例#4
0
        public async Task <ObjectLevelViewModel> AddPoint(AddPointRequest request)
        {
            string      objectLevelId = request.ObjectLevelId;
            int         point         = request.Point;
            ObjectLevel objectLevel   = await objectLevelRepository.GetByIdAsync(ObjectId.Parse(objectLevelId));

            if (objectLevel != null)
            {
                objectLevel.Point += point;
                if (objectLevel.Point < LevelPoint.Level1)
                {
                    objectLevel.LevelId = levelRepository.GetAll().FirstOrDefault(x => x.Order == 0)?.OId;
                }
                else if (objectLevel.Point < LevelPoint.Level2)
                {
                    objectLevel.LevelId = levelRepository.GetAll().FirstOrDefault(x => x.Order == 1)?.OId;
                }
                else if (objectLevel.Point < LevelPoint.Level3)
                {
                    objectLevel.LevelId = levelRepository.GetAll().FirstOrDefault(x => x.Order == 2)?.OId;
                }
                else if (objectLevel.Point < LevelPoint.Level4)
                {
                    objectLevel.LevelId = levelRepository.GetAll().FirstOrDefault(x => x.Order == 3)?.OId;
                }
                else
                {
                    objectLevel.LevelId = levelRepository.GetAll().FirstOrDefault(x => x.Order == 4)?.OId;
                }

                await objectLevelRepository.UpdateAsync(objectLevel, objectLevel.Id);

                return(mapper.Map <ObjectLevelViewModel>(objectLevel));
            }
            else
            {
                throw new Exception("Không tìm thấy Object Level. ");
            }
        }
示例#5
0
    private Sprite GetSpriteByObjectLevel(ObjectLevel level)
    {
        switch (level)
        {
        case ObjectLevel.none:
            return(noneIcon);

        case ObjectLevel.bronze:
            return(bronzeIcon);

        case ObjectLevel.silver:
            return(silverIcon);

        case ObjectLevel.gold:
            return(goldIcon);

        case ObjectLevel.platinum:
            return(platinumIcon);

        default:
            return(null);
        }
    }
示例#6
0
        /// <summary>
        /// Parse
        /// </summary>
        /// <param name="names">the names</param>
        /// <param name="objectLevel">target objectlevel.</param>
        /// <returns>the SqlName chain</returns>
        public static SqlName Parse(string names, ObjectLevel objectLevel)
        {
            if (string.IsNullOrEmpty(names))
            {
                return(null);
            }
            var parts = new List <string>();
            int state = 0;
            int start = 0;
            int stop  = 0;

            for (int idx = 0, l = names.Length; idx <= l; idx++)
            {
                bool eos = (idx >= l);
                char c;
                if (eos)
                {
                    c = '\0';
                }
                else
                {
                    c = names[idx];
                }
                if (c == '[')
                {
                    state = 1;
                    stop  = start = idx + 1;
                    continue;
                }
                if (c == ']')
                {
                    if (state == 1)
                    {
                        stop  = idx;
                        state = 2;
                    }
                    continue;
                }
                if (((c == '.') && ((state == 0) || (state == 2))) || eos)
                {
                    if (state == 0)
                    {
                        // ab.c
                        // 012345
                        // 0 2
                        parts.Add(names.Substring(start, idx - start).Trim());
                    }
                    else if (start == stop)
                    {
                        parts.Add(names.Substring(start, idx - start));
                    }
                    else
                    {
                        // [ab].c
                        // 012345
                        //  1 3
                        parts.Add(names.Substring(start, stop - start));
                        state = 0;
                    }
                    stop = start = idx + 1;
                    continue;
                }
            }
            if (parts.Count == 0)
            {
                return(null);
            }
            else
            {
                if (objectLevel == ObjectLevel.Unknown)
                {
                    SqlName result = null;
                    for (int idx = 0; idx < parts.Count; idx++)
                    {
                        result = new SqlName(result, parts[idx], ObjectLevel.Unknown);
                    }
                    return(result);
                }
                else
                {
                    SqlName result = null;
                    for (int idx = 0; idx < parts.Count; idx++)
                    {
                        var ol      = (int)objectLevel - idx + parts.Count - 1;
                        var validol = ((((int)ObjectLevel.Child) <= ol) && (ol <= ((int)ObjectLevel.Server)))
                                ? ((ObjectLevel)ol)
                                : ObjectLevel.Unknown;
                        result = new SqlName(result, parts[idx], validol);
                    }
                    return(result);
                }
            }
        }