コード例 #1
0
        private IList <Skin> SkinForCreation(string data)
        {
            List <Skin> skins = new List <Skin>();

            if (!string.IsNullOrEmpty(data))
            {
                var splitData = data.Split(new[] { '\r', '\n' }).Where(a => !string.IsNullOrEmpty(a));


                foreach (var item in splitData)
                {
                    var firstIndex = item.IndexOf("_", StringComparison.Ordinal);
                    var end        = item.LastIndexOf(".", StringComparison.Ordinal);
                    var stringData = item.Substring((firstIndex + 1), ((end - firstIndex) - 1));
                    int key        = 0;

                    if (int.TryParse(stringData, out key))
                    {
                        skins.Add(_repoSkin.ReadOne(a => a.Id == key));
                    }
                }
            }

            return(skins);
        }
コード例 #2
0
        public int DeleteChamp(int champId)
        {
            var champ = _champRepositories.ReadOne(a => a.Id == champId);

            champ.IsDeleted = true;

            return(_champRepositories.SaveChanges());
        }
コード例 #3
0
        public void UpdateBalanceUser(string generalUserId, float?balance)
        {
            var user = _userRepositories.ReadOne(a => a.GeneralUserId == generalUserId);

            if (user != null && balance != null)
            {
                user.Balance = balance ?? 0;
                _userRepositories.Update(user);
            }
        }
コード例 #4
0
        public int AssignOrUnassignChamp(int accountId, string champs)
        {
            var chmps = champs.Split(',').Distinct();

            var account = _repoAccount.ReadOne(a => a.Id == accountId);
            var champ   = _champRepositories.Read(a => !a.IsDeleted && chmps.Contains(a.ChampionName), true).ToList();

            account.Champions.Clear();
            account.Champions = champ;

            return(_repoAccount.SaveChanges());
        }
コード例 #5
0
        public int DeleteSkin(int skinId)
        {
            var skin = _skinRepositories.ReadOne(a => a.Id == skinId);

            skin.IsDeleted = true;

            return(_skinRepositories.SaveChanges());
        }
コード例 #6
0
        public string DeleteLuckyItem(int id)
        {
            var img = _luckyWheelItemRepositories.ReadOne(a => a.Id == id).ImageUrl;

            _luckyWheelItemRepositories.Delete(a => a.Id == id);
            _luckyWheelItemRepositories.SaveChanges();

            return(img);
        }
コード例 #7
0
        private IList <Champion> ChampionForCreation(string data)
        {
            List <Champion> champs = new List <Champion>();

            if (!string.IsNullOrEmpty(data))
            {
                var splitData = data.Split(new[] { '\r', '\n' }).Where(a => !string.IsNullOrEmpty(a));

                foreach (var item in splitData)
                {
                    champs.Add(_repoChamp.ReadOne(a => a.ChampionName == item));
                }

                _repoChamp.SaveChanges();
            }


            return(champs);
        }
コード例 #8
0
        public int DeletePageGemById(int pageGemId)
        {
            var imagesDeleted = _pageGemRepositories.ReadOne(a => a.Id == pageGemId);

            _pageGemRepositories.Delete(a => a.Id == pageGemId);
            int result = _pageGemRepositories.SaveChanges();

            if (result > 0)
            {
                FileUlti.DeleteFile(imagesDeleted.ImageUrl);
            }

            return(result);
        }
コード例 #9
0
        public AccountDto Create(AccountDto entity, string champ, string skin)
        {
            var account = Mapper.Map <Account>(entity);

            var result = _repoAccount.Create(account);

            if (_repoAccount.SaveChanges() > 0)
            {
                var accountAdded = _repoAccount.ReadOne(a => a.Id == result.Id);

                accountAdded.Champions = ChampionForCreation(champ);
                accountAdded.Skins     = SkinForCreation(skin);

                _repoAccount.SaveChanges();
                return(Mapper.Map <AccountDto>(result));
            }

            return(null);
        }
コード例 #10
0
        private int ProccessingDataToDb(Dictionary <string, ChampUploadDto> detailsInformation)
        {
            //TODO: Implement for case delete champ or skin if not existed in json file, upda skin problem

            foreach (KeyValuePair <string, ChampUploadDto> champ in detailsInformation)
            {
                Champion champData;
                if (_champRepositories.Read(a => a.Id == champ.Value.key).Any())
                {
                    champData = _champRepositories.ReadOne(a => a.Id == champ.Value.key);
                    champData.ChampionName = champ.Value.name;
                    champData.UpdatedDate  = DateTime.Now;
                    champData.Avatar       = $"../Images/champion/{champ.Key}.png";
                    champData.Skins        = champ.Value.skins.Select(a =>
                    {
                        Skin skinData;
                        if (_repoSkin.Read(b => b.Id == a.id).Any())
                        {
                            skinData             = _repoSkin.ReadOne(b => b.Id == a.id);
                            skinData.Avatar      = $"../Images/skins/championsskin_{a.id}.jpg";
                            skinData.ChampionId  = champ.Value.key;
                            skinData.UpdatedDate = DateTime.Now;
                            skinData.SkinName    = a.name;
                        }
                        else
                        {
                            skinData = new Skin()
                            {
                                Avatar      = $"../Images/skins/championsskin_{a.id}.jpg",
                                ChampionId  = champ.Value.key,
                                CreatedDate = DateTime.Now,
                                SkinName    = a.name,
                                Id          = a.id
                            };
                        }

                        return(skinData);
                    }).ToList();

                    _champRepositories.SaveChanges();
                }
                else
                {
                    champData = new Champion()
                    {
                        ChampionName = champ.Value.name,
                        CreatedDate  = DateTime.Now,
                        Id           = champ.Value.key,
                        Avatar       = $"../Images/champion/{champ.Key}.png",
                        Skins        = champ.Value.skins.Select(a => new Skin()
                        {
                            Avatar      = $"../Images/skins/championsskin_{a.id}.jpg",
                            ChampionId  = champ.Value.key,
                            CreatedDate = DateTime.Now,
                            SkinName    = a.name,
                            Id          = a.id
                        }).ToList()
                    };
                    _champRepositories.Create(champData);
                }
            }
            return(_champRepositories.SaveChanges());
        }