コード例 #1
0
        /// <summary>
        /// Get all Tax value
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result   = new List <TypeViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _TypeRepository.GetAll().Where(m => m.IsActive == true).Select(m => new TypeViewModel
                {
                    ID       = m.ID,
                    TypeName = m.TypeName,
                    IsActive = m.IsActive ?? false
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
コード例 #2
0
ファイル: BookController.cs プロジェクト: keeremcelik/library
        public IActionResult List()
        {
            BookModel model = new BookModel();

            model.BookList   = bookRepository.GetAll().ToList();
            model.AuthorList = authorRepository.GetAll().ToList();
            model.TypeList   = typeRepository.GetAll().ToList();
            return(View(model));
        }
コード例 #3
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString("user") is null)
            {
                Response.Redirect("/admin/login");
            }
            ViewBag.User = HttpContext.Session.GetString("user");
            var types = _repository.GetAll();

            return(View(types));
        }
コード例 #4
0
 public async Task <ICollection <Type> > GetAll(User user)
 {
     try
     {
         return(_typeRepository.GetAll().Where(x => (x.fk_UserId == user.Id || x.fk_UserId == null) && !x.Deleted).ToList());
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #5
0
ファイル: AppQuery.cs プロジェクト: roymclellan/GraphQLTest
        public AppQuery(
            IOwnerRepository ownerRepository,
            IAccountRepository accountRepository,
            ITypeRepository typeRepository)
        {
            Field <ListGraphType <OwnerType> >(
                "owners",
                resolve: context => ownerRepository.GetAll());

            Field <OwnerType>(
                "owner",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "ownerId"
            }),
                resolve: context =>
            {
                if (!int.TryParse(context.GetArgument <string>("ownerId"), out int id))
                {
                    context.Errors.Add(new ExecutionError("Wrong value for Id"));
                    return(null);
                }

                return(ownerRepository.GetById(id));
            }
                );

            Field <ListGraphType <AccountType> >(
                "account",
                resolve: context => accountRepository.GetAll());

            Field <ListGraphType <TypeType> >(
                "type",
                resolve: context => typeRepository.GetAll());
        }
コード例 #6
0
        public IActionResult Index()
        {
            CheckRooms reservation = new CheckRooms()
            {
                RoomTypes = new SelectList(_typeRepository.GetAll(), "TypeId", "TypeName")
            };

            return(View(reservation));
        }
コード例 #7
0
 public Task <IEnumerable <SubscriptionType> > Get()
 {
     try
     {
         return(_typeRepository.GetAll());
     }
     catch (Exception ex)
     {
         _log.LogError(ex.ToString());
         return(null);
     }
 }
コード例 #8
0
    public static ITypeRepository Extend(this ITypeRepository target, ITypeRepository source)
    {
        _ = target ?? throw new ArgumentNullException(nameof(target));
        _ = source ?? throw new ArgumentNullException(nameof(source));

        foreach (var item in source.GetAll() ?? Enumerable.Empty <KeyValuePair <Type, Type> >())
        {
            if (!target.TryGet(item.Key, out _))
            {
                target.Add(item.Key, item.Value);
            }
        }
        return(target);
    }
コード例 #9
0
        public IActionResult PieChart()
        {
            var books = bookRepository.GetAll();
            //PASTA GRAFİĞİ TÜRÜNE GÖRE
            var allCategory             = typeRepository.GetAll();
            List <DataPoint> dataPoints = new List <DataPoint>();

            var readedBook = books.Where(i => i.isReaded == true).Count();

            for (int i = 1; i <= allCategory.Count(); i++)
            {
                var category = typeRepository.GetById(i);
                int book     = books.Where(a => a.isReaded == true).Where(a => a.TypeId == i).Count();
                int rate     = 100 * book / readedBook;
                dataPoints.Add(new DataPoint(category.Name, rate));
            }
            ViewBag.DataPoints = JsonConvert.SerializeObject(dataPoints);
            //PASTA GRAFİĞİ TÜRÜNE GÖRE SON
            return(View());
        }
コード例 #10
0
        public async Task SeedsAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_apiUrl);

                var types = _typeRepository.GetAll();

                List <TypeAdvantage> typeAdvantages = new List <TypeAdvantage>();

                foreach (var type in types)
                {
                    List <TypeAdvantage> typeAdvantagesByType = new List <TypeAdvantage>();
                    var errorCount     = 0;
                    var serviceSuccess = false;
                    HttpResponseMessage results;
                    do
                    {
                        var responseTask = client.GetAsync(string.Concat("type/", type.Name.ToLower()));
                        responseTask.Wait();
                        results        = responseTask.Result;
                        serviceSuccess = results.IsSuccessStatusCode;
                        errorCount++;
                        if (errorCount == 3)
                        {
                            throw new PokeApiException();
                        }
                    } while (!serviceSuccess);
                    string apiResponse = await results.Content.ReadAsStringAsync();

                    var json            = JObject.Parse(apiResponse);
                    var damageRelations = json["damage_relations"];
                    var doubleDamageTo  = damageRelations["double_damage_to"];
                    var halfDamageTo    = damageRelations["half_damage_to"];
                    var noDamageTo      = damageRelations["no_damage_to"];

                    foreach (var typeDoubleDamageTo in doubleDamageTo)
                    {
                        var name            = typeDoubleDamageTo["name"].ToString();
                        var idDefensiveType = types.First(x => x.Name.ToLower() == name.ToLower()).Id;
                        typeAdvantagesByType.Add(new TypeAdvantage(idAttackingType: type.Id, idDefensiveType: idDefensiveType, effect: 2));
                    }

                    foreach (var typeHaldDamageTo in halfDamageTo)
                    {
                        var name            = typeHaldDamageTo["name"].ToString();
                        var idDefensiveType = types.First(x => x.Name.ToLower() == name.ToLower()).Id;
                        typeAdvantagesByType.Add(new TypeAdvantage(idAttackingType: type.Id, idDefensiveType: idDefensiveType, effect: 0.5m));
                    }

                    foreach (var typeNoDamageTo in noDamageTo)
                    {
                        var name            = typeNoDamageTo["name"].ToString();
                        var idDefensiveType = types.First(x => x.Name.ToLower() == name.ToLower()).Id;
                        typeAdvantagesByType.Add(new TypeAdvantage(idAttackingType: type.Id, idDefensiveType: idDefensiveType, effect: 0m));
                    }

                    var neutralDamageTo = types.Where(x => !typeAdvantagesByType.Exists(y => x.Id == y.IdDefensiveType));

                    foreach (var defendingType in neutralDamageTo)
                    {
                        typeAdvantagesByType.Add(new TypeAdvantage(idAttackingType: type.Id, idDefensiveType: defendingType.Id, effect: 1m));
                    }

                    typeAdvantages.AddRange(typeAdvantagesByType);
                }

                foreach (var typeAdvantage in typeAdvantages)
                {
                    _typeAdvantageRepository.Create(typeAdvantage);
                }
            }
        }
コード例 #11
0
        public async Task SeedsAsync(int initialIndex)
        {
            int pokemonNationalNumb = initialIndex;

            try {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(_apiUrl);
                    var allTypes = _typeRepository.GetAll();

                    for (int i = initialIndex; i <= 807; i++)
                    {
                        pokemonNationalNumb = i;
                        HttpResponseMessage results;
                        bool responseSuccess = false;
                        int  errorCount      = 0;
                        do
                        {
                            var responseTask = client.GetAsync(string.Concat("pokemon/", i));
                            responseTask.Wait();
                            results         = responseTask.Result;
                            responseSuccess = results.IsSuccessStatusCode;
                            if (!responseSuccess)
                            {
                                errorCount++;
                            }
                            if (errorCount == 3)
                            {
                                throw new PokeApiException();
                            }
                        } while(!responseSuccess);
                        string apiResponse = await results.Content.ReadAsStringAsync();

                        var json       = JObject.Parse(apiResponse);
                        var name       = json["forms"][0]["name"].ToString();
                        var stats      = json["stats"];
                        var types      = json["types"];
                        var firstType  = allTypes.FirstOrDefault(x => x.Name.ToLower() == types[0]["type"]["name"].ToString().ToLower());
                        var secondType = new Models.Type();

                        var pokemonSpecies = new Pokemon_Species()
                        {
                            National_Numb   = i,
                            Name            = name,
                            Base_Hp         = (int)stats[5]["base_stat"],
                            Base_Attack     = (int)stats[4]["base_stat"],
                            Base_Defense    = (int)stats[3]["base_stat"],
                            Base_Sp_Attack  = (int)stats[2]["base_stat"],
                            Base_Sp_Defense = (int)stats[1]["base_stat"],
                            Base_Speed      = (int)stats[0]["base_stat"],
                            First_Type_Id   = firstType.Id,
                        };

                        if (types.Count() > 1)
                        {
                            secondType = allTypes.FirstOrDefault(x => x.Name.ToLower() == types[1]["type"]["name"].ToString().ToLower());
                            pokemonSpecies.Second_Type_Id = secondType.Id;
                        }
                        _pokemonRepository.Create(pokemonSpecies);
                    }
                }
            }
            catch (Exception ex)
            {
                using (var logger = LoggerDomain.GetLog(_connectionString))
                {
                    logger.Error(string.Format("Error at pokemonSpecies {0} - Exception Message: ", pokemonNationalNumb, ex.Message));
                    throw ex;
                }
            }
        }
コード例 #12
0
 public IActionResult List()
 {
     return(View(typeRepository.GetAll()));
 }
コード例 #13
0
ファイル: TypeController.cs プロジェクト: urke/WebApi
 public IEnumerable <Models.Type> Get()
 {
     return(_typeRepository.GetAll());
 }
コード例 #14
0
        public IList <TypeViewModel> GetAll()
        {
            IList <Type> types = _typeRepository.GetAll().ToList();

            return(this.GenerateTypeViewModels(types));
        }
コード例 #15
0
        public void Should_GetAll_Return_all_indexes_Types()
        {
            IEnumerable <Type> _types = _typeRepository.GetAll();

            Assert.IsTrue(_types.Count() > 0);
        }
コード例 #16
0
 public IEnumerable <TypeEntity> Get()
 {
     return(_typeRepository.GetAll());
 }
コード例 #17
0
        public async Task SeedsAsync(int initialIndex)
        {
            var typeLists = _typeRepository.GetAll();
            int moveIndex = initialIndex;

            try {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(_apiUrl);
                    for (int i = initialIndex; i <= 728; i++)
                    {
                        moveIndex = i;
                        HttpResponseMessage results;
                        bool responseSuccess = false;
                        int  errorCount      = 0;
                        do
                        {
                            var responseTask = client.GetAsync(string.Concat("move/", i));
                            responseTask.Wait();
                            results         = responseTask.Result;
                            responseSuccess = results.IsSuccessStatusCode;
                            if (!responseSuccess)
                            {
                                errorCount++;
                            }
                            if (errorCount == 3)
                            {
                                throw new PokeApiException();
                            }
                        } while (responseSuccess == false);

                        string apiResponse = await results.Content.ReadAsStringAsync();

                        var json               = JObject.Parse(apiResponse);
                        var name               = json["names"][2]["name"].ToString();
                        var basePowerString    = json["power"].ToString();
                        var moveTypeString     = json["type"]["name"].ToString();
                        var moveCategoryString = json["damage_class"]["name"].ToString();

                        var basePower    = basePowerString.ToDecimal();
                        var moveType     = typeLists.FirstOrDefault(x => x.Name.ToLower() == moveTypeString);
                        var moveCategory = (MoveCategoryEnum)typeof(MoveCategoryEnum).GetEnumByDescription(moveCategoryString);

                        if (moveCategory == MoveCategoryEnum.Status)
                        {
                            continue;
                        }

                        var move = new Moves()
                        {
                            Name          = name,
                            Base_Power    = basePower,
                            Move_Category = moveCategory,
                            Id_Type       = moveType.Id
                        };

                        _moveRepository.Create(move);
                    }
                }
            }
            catch (Exception ex) {
                using (var logger = LoggerDomain.GetLog(_connectionString))
                {
                    logger.Error(string.Format("Error at pokemonSpecies {0} - Exception Message: ", moveIndex, ex.Message));
                    throw ex;
                }
            }
        }
コード例 #18
0
        public IActionResult GetTypes()
        {
            var types = _typeRepository.GetAll();

            return(new OkObjectResult(types));
        }
コード例 #19
0
 public IEnumerable <TypeDTO> GetAll()
 {
     return(_typeRepository.GetAll());
 }
コード例 #20
0
 public IViewComponentResult Invoke()
 {
     ViewBag.SelectedType = RouteData?.Values["id"];
     return(View(_repository.GetAll()));
 }