Ejemplo n.º 1
0
        public void GetSubCotegaryExecute()
        {
            var obj = new SubCategoryRequest()
            {
                CatId = CatId
            };

            UserDialogs.Instance.ShowLoading("Requesting..");
            userManager.getSubCategory(obj, () =>
            {
                var subCategoryResponse = userManager.SubCategoryResponse;
                if (subCategoryResponse.StatusCode == 200)
                {
                    UserDialogs.Instance.HideLoading();
                    Recipes = new List <Recipe>(subCategoryResponse.Recipes);
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync(new SubCategoryView());
                    });
                }
            },
                                       (requestFailedReason) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                    UserDialogs.Instance.Alert(requestFailedReason?.Message == null?"Network Error": requestFailedReason.Message, null, "OK");
                });
            });
        }
Ejemplo n.º 2
0
        public async void getSubCategory(SubCategoryRequest commonRequest, Action success, Action <SubCategoryResponse> failed)
        {
            bool IsNetwork = true;//await DependencyService.Get<IMediaService>().CheckNewworkConnectivity();

            if (IsNetwork)
            {
                string para = "catId=" + commonRequest.CatId;
                var    url  = string.Format("{0}getRecipesByCat.php?" + para, _settingsManager.ApiHost);

                await Task.Run(() =>
                {
                    Dictionary <string, string> head = GetHeaders();
                    var result = _apiProvider.Get <SubCategoryResponse, SubCategoryRequest>(url, null).Result;
                    if (result.IsSuccessful)
                    {
                        if (success != null)
                        {
                            subCategoryResponse = result.Result;
                            success.Invoke();
                        }
                    }
                    else
                    {
                        failed.Invoke(result.Result);
                    }
                });
            }
            else
            {
                UserDialogs.Instance.HideLoading();
                UserDialogs.Instance.Alert(error, null, "OK");
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateSubCategory([FromBody] SubCategoryRequest request, [FromRoute] Guid subcategoryId)
        {
            var subCategory = await _repo.getSubCategoryAsync(subcategoryId);

            subCategory.Name = request.Name;



            var result = await _repo.updateSubCategoryAsync(subCategory);

            if (result)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddSubCategory([FromBody] SubCategoryRequest request)
        {
            var subCategory = _mapper.Map <SubCategory>(request);

            subCategory.Id = Guid.NewGuid();

            var result = await _repo.addSubCategoryAsync(subCategory);

            var baseUrl  = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var location = baseUrl + RoutesAPI.SubCategory.getSubCategory.Replace("{subcategoryId}", subCategory.Id.ToString());


            if (result)
            {
                return(Created(location, _mapper.Map <SubCategoryResponse>(subCategory)));
            }
            return(BadRequest());
        }