示例#1
0
        public async Task <LootTemplateVM> GetLootTemplateVMById(int?id)
        {
            LootTemplateVM _LootTemplate = new LootTemplateVM();

            LootTemplate lootTemplate = await _context.LootTemplates
                                        .Include(d => d.RuleSet)
                                        .Include(d => d.LootTemplateRandomizationEngines)
                                        .Where(x => x.LootTemplateId == id && x.IsDeleted != true)
                                        .FirstOrDefaultAsync();

            if (lootTemplate == null)
            {
                return(null);
            }
            else
            {
                _LootTemplate = new LootTemplateVM()
                {
                    Description    = lootTemplate.Description,
                    gmOnly         = lootTemplate.gmOnly,
                    ImageUrl       = lootTemplate.ImageUrl,
                    LootTemplateId = lootTemplate.LootTemplateId,
                    Metatags       = lootTemplate.Metatags,
                    Name           = lootTemplate.Name,
                    RuleSet        = lootTemplate.RuleSet,
                    RuleSetId      = lootTemplate.RuleSetId,
                    IsDeleted      = lootTemplate.IsDeleted,
                    LootTemplateRandomizationEngines = lootTemplate.LootTemplateRandomizationEngines,
                    //LootTemplateRandomizationSearch = lootTemplate.sea
                };

                if (_LootTemplate.LootTemplateRandomizationEngines != null)
                {
                    _LootTemplate.LootTemplateRandomizationEngines = lootTemplate.LootTemplateRandomizationEngines.Where(z => z.IsDeleted != true).ToList();
                    if (_LootTemplate.LootTemplateRandomizationEngines.Count > 0)
                    {
                        foreach (var item in _LootTemplate.LootTemplateRandomizationEngines)
                        {
                            item.ItemMaster = _context.ItemMasters.Where(x => x.ItemMasterId == item.ItemMasterId && x.IsDeleted != true).FirstOrDefault();
                        }
                    }
                }
                _LootTemplate.LootTemplateRandomizationSearch = _context.LootTemplateRandomizationSearch
                                                                .Where(search => search.LootTemplateId == _LootTemplate.LootTemplateId)
                                                                .Select(search => new LootTemplateRandomizationSearch
                {
                    LootTemplateId        = search.LootTemplateId,
                    Quantity              = search.Quantity,
                    QuantityString        = search.QuantityString,
                    String                = search.String,
                    ItemRecord            = search.ItemRecord,
                    IsAnd                 = search.IsAnd,
                    SortOrder             = search.SortOrder,
                    IsDeleted             = false,
                    RandomizationSearchId = search.RandomizationSearchId,
                    Fields                = _context.RandomizationSearchFields.Where(t => t.RandomizationSearchId == search.RandomizationSearchId).ToList()
                }).ToListAsync().Result;


                //_LootTemplate.LootTemplateRandomizationSearch =_context.LootTemplateRandomizationSearch.Include(y => y.Fields).Where(x => x.LootTemplateId == _LootTemplate.LootTemplateId).ToListAsync().Result;
                //_LootTemplate.LootTemplateCurrency = this._lootTemplateCurrencyService.GetByLootTemplateId(_LootTemplate.LootTemplateId).Result;
            }

            return(_LootTemplate);
        }
示例#2
0
        public List <LootTemplateVM> SP_GetLootTemplateByRuleSetId(int rulesetId, int page, int pageSize)
        {
            List <LootTemplateVM> _lootTemplateList = new List <LootTemplateVM>();
            RuleSet ruleset = new RuleSet();

            short  num = 0;
            string connectionString = _configuration.GetSection("ConnectionStrings").GetSection("DefaultConnection").Value;

            SqlConnection  connection = new SqlConnection(connectionString);
            SqlCommand     command    = new SqlCommand();
            SqlDataAdapter adapter    = new SqlDataAdapter();
            DataSet        ds         = new DataSet();

            try
            {
                connection.Open();
                command = new SqlCommand("LootTemplate_GetByRulesetID", connection);

                // Add the parameters for the SelectCommand.
                command.Parameters.AddWithValue("@RulesetID", rulesetId);
                command.Parameters.AddWithValue("@page", page);
                command.Parameters.AddWithValue("@size", pageSize);
                command.CommandType = CommandType.StoredProcedure;

                adapter.SelectCommand = command;

                adapter.Fill(ds);
                command.Dispose();
                connection.Close();
            }
            catch (Exception ex)
            {
                command.Dispose();
                connection.Close();
            }

            if (ds.Tables[1].Rows.Count > 0)
            {
                ruleset = _repo.GetRuleset(ds.Tables[1], num);
            }

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    LootTemplateVM _LootTemplate = new LootTemplateVM();
                    _LootTemplate.Name           = row["Name"] == DBNull.Value ? null : row["Name"].ToString();
                    _LootTemplate.Metatags       = row["Metatags"] == DBNull.Value ? null : row["Metatags"].ToString();
                    _LootTemplate.Description    = row["Description"] == DBNull.Value ? null : row["Description"].ToString();
                    _LootTemplate.gmOnly         = row["gmOnly"] == DBNull.Value ? null : row["gmOnly"].ToString();
                    _LootTemplate.ImageUrl       = row["ImageUrl"] == DBNull.Value ? null : row["ImageUrl"].ToString();
                    _LootTemplate.IsDeleted      = row["IsDeleted"] == DBNull.Value ? false : Convert.ToBoolean(row["IsDeleted"]);
                    _LootTemplate.LootTemplateId = row["LootTemplateId"] == DBNull.Value ? 0 : Convert.ToInt32(row["LootTemplateId"].ToString());
                    _LootTemplate.RuleSetId      = row["RuleSetId"] == DBNull.Value ? 0 : Convert.ToInt32(row["RuleSetId"].ToString());
                    _LootTemplate.Mode           = row["Mode"] == DBNull.Value ? null : row["Mode"].ToString();
                    _LootTemplate.RuleSet        = ruleset;

                    _LootTemplate.LootTemplateRandomizationEngines = new List <LootTemplateRandomizationEngine>();
                    if (ds.Tables[2].Rows.Count > 0)
                    {
                        foreach (DataRow RErow in ds.Tables[2].Rows)
                        {
                            int LT_ID = RErow["LootTemplateId"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["LootTemplateId"]);
                            if (LT_ID == _LootTemplate.LootTemplateId)
                            {
                                LootTemplateRandomizationEngine RE = new LootTemplateRandomizationEngine();
                                RE.RandomizationEngineId = RErow["RandomizationEngineId"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["RandomizationEngineId"]);
                                RE.Qty            = RErow["Qty"] == DBNull.Value ? string.Empty : RErow["Qty"].ToString();
                                RE.Percentage     = RErow["Percentage"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["Percentage"]);
                                RE.SortOrder      = RErow["SortOrder"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["SortOrder"]);
                                RE.ItemMasterId   = RErow["ItemMasterId"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["ItemMasterId"]);
                                RE.IsOr           = RErow["IsOr"] == DBNull.Value ? false : Convert.ToBoolean(RErow["IsOr"]);
                                RE.IsDeleted      = RErow["IsDeleted"] == DBNull.Value ? false : Convert.ToBoolean(RErow["IsDeleted"]);
                                RE.QuantityString = RErow["QuantityString"] == DBNull.Value ? string.Empty : RErow["QuantityString"].ToString();
                                RE.LootTemplateId = LT_ID;
                                RE.ItemMaster     = new ItemMaster()
                                {
                                    ItemMasterId = RErow["ItemMasterId"] == DBNull.Value ? 0 : Convert.ToInt32(RErow["ItemMasterId"]),
                                    ItemName     = RErow["ItemName"] == DBNull.Value ? null : RErow["ItemName"].ToString(),
                                    ItemImage    = RErow["ItemImage"] == DBNull.Value ? null : RErow["ItemImage"].ToString()
                                };
                                _LootTemplate.LootTemplateRandomizationEngines.Add(RE);
                            }
                        }
                    }
                    _LootTemplate.LootTemplateRandomizationSearch = _context.LootTemplateRandomizationSearch
                                                                    .Where(search => search.LootTemplateId == _LootTemplate.LootTemplateId)
                                                                    .Select(search => new LootTemplateRandomizationSearch
                    {
                        LootTemplateId        = search.LootTemplateId,
                        Quantity              = search.Quantity,
                        QuantityString        = search.QuantityString,
                        String                = search.String,
                        ItemRecord            = search.ItemRecord,
                        IsAnd                 = search.IsAnd,
                        SortOrder             = search.SortOrder,
                        IsDeleted             = false,
                        RandomizationSearchId = search.RandomizationSearchId,
                        Fields                = _context.RandomizationSearchFields.Where(t => t.RandomizationSearchId == search.RandomizationSearchId).ToList()
                    }).ToListAsync().Result;


                    //_LootTemplate.LootTemplateRandomizationSearch =_context.LootTemplateRandomizationSearch.Include(y => y.Fields).Where(x => x.LootTemplateId == _LootTemplate.LootTemplateId).ToListAsync().Result;
                    _LootTemplate.LootTemplateCurrency = this._lootTemplateCurrencyService.GetByLootTemplateId(_LootTemplate.LootTemplateId).Result;

                    _lootTemplateList.Add(_LootTemplate);
                }
            }
            return(_lootTemplateList);
        }