Пример #1
0
        private async Task GetPosts()
        {
            using (UserDialogs.Instance.Loading(AppConstant.PleaseWait))
            {
                var response = await ApiCallHelper.GetAllPosts();

                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var imageData = JsonConvert.DeserializeObject <ResponseObject <List <Post> > >(response.Content);
                        if (imageData != null)
                        {
                            if (imageData.StatusCode == HttpStatusCode.BadRequest)
                            {
                                return;
                            }
                            else
                            {
                                Images = new ObservableCollection <Post>(imageData.Response);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private async Task <List <SelectListItem> > GetRestaurants()
        {
            var json = JsonConvert.SerializeObject(new RestaurantDTO
            {
                PagingArgs = Common.Models.PagingArgs.NoPaging
            });
            var apiHelper = new ApiCallHelper <RestaurantDTO>(this.clientFactory)
            {
                ControllerName = "Restaurant"
            };
            var entities = await apiHelper.GetListAsync(json);

            for (var i = 0; i < entities.Data.Count; i++)
            {
                entities.Data[i].PictureUrl = $"{AppSettings.ApiUrl}Picture?file={entities.Data[i].PictureUrl}&folder=restaurant";
            }

            return(entities.Data.Select(x =>
            {
                return new SelectListItem
                {
                    Value = $"{x.Id}",
                    Text = $"{x.Name}"
                };
            }).ToList());
        }
Пример #3
0
        private async Task DownLoadPost(Post post)
        {
            var result = await ApiCallHelper.DownLoadPost(post);

            var msg = string.Empty;

            if (result == HttpStatusCode.Created)
            {
                msg = "Post saved successfully";
            }
            else if (result == HttpStatusCode.Found)
            {
                msg = "Post already exists";
            }
            if (string.IsNullOrWhiteSpace(msg) == false)
            {
                var toastConfig = new ToastConfig(msg)
                {
                    BackgroundColor  = Color.Green,
                    MessageTextColor = Color.White,
                    Position         = ToastPosition.Top
                };
                UserDialogs.Instance.Toast(toastConfig);
            }
        }
Пример #4
0
        private async void Upload()
        {
            var response = await ApiCallHelper.UploadPost(new Post { id = AppConstant.UserId.ToString(), file = _imageSource, latitude = Latitude.ToString(), longitude = Longitude.ToString() });

            if (response != null)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var userDetails = JsonConvert.DeserializeObject <ResponseObject <string> >(response.Content);
                    if (userDetails != null)
                    {
                        if (userDetails.StatusCode == HttpStatusCode.BadRequest)
                        {
                            await DisplayAlert(AppConstant.ErrorHeading, userDetails.ErrorMessage, AppConstant.ErrorAcceptance);

                            return;
                        }
                        else
                        {
                            await Navigation.PushAsync(new PostList(string.Empty));

                            return;
                        }
                    }
                }
            }
        }
Пример #5
0
 private void GetOfflineSavedPosts()
 {
     using (UserDialogs.Instance.Loading(AppConstant.PleaseWait))
     {
         var result = ApiCallHelper.GetOfflineSavedPosts();
         if (result != null)
         {
             Images = new ObservableCollection <Post>(result);
         }
     }
 }
Пример #6
0
        private async void UploadPost()
        {
            if (AppConstant.UserId <= 0)
            {
                await DisplayAlert(AppConstant.ErrorHeading, "Login required for upload post", AppConstant.ErrorAcceptance);

                return;
            }
            using (UserDialogs.Instance.Loading(AppConstant.PleaseWait))
            {
                if (await GeoLocation())
                {
                    var response = await ApiCallHelper.UploadPost(new Post { id = AppConstant.UserId.ToString(), file = _imageSource, latitude = Latitude.ToString(), longitude = Longitude.ToString() });

                    if (response != null)
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            var userDetails = JsonConvert.DeserializeObject <ResponseObject <string> >(response.Content);
                            if (userDetails != null)
                            {
                                if (userDetails.StatusCode == HttpStatusCode.BadRequest)
                                {
                                    return;
                                }
                                else
                                {
                                    await Navigation.PushAsync(new PostList(string.Empty));

                                    return;
                                }
                            }
                        }
                    }
                    await DisplayAlert(AppConstant.ErrorHeading, AppConstant.InvalidCredentialsErrorMessage, AppConstant.ErrorAcceptance);

                    return;
                }
                else if (Longitude <= 0 && Latitude <= 0)
                {
                    await DisplayAlert(AppConstant.ErrorHeading, "Location not found please try agin later", AppConstant.ErrorAcceptance);

                    return;
                }
            }
        }
Пример #7
0
        private async Task <List <SelectListItem> > GetCustomers()
        {
            var json = JsonConvert.SerializeObject(new CustomerDTO
            {
                PagingArgs = Common.Models.PagingArgs.NoPaging
            });
            var apiHelper = new ApiCallHelper <CustomerDTO>(this.clientFactory)
            {
                ControllerName = "Customer"
            };
            var entities = await apiHelper.GetListAsync(json);

            return(entities.Data?.Select(x =>
            {
                return new SelectListItem
                {
                    Value = $"{x.Id}",
                    Text = $"{x.Name} {x.Phone}"
                };
            }).ToList());
        }
Пример #8
0
        public ActionResult Validate <T>(Result <T> result, ApiCallHelper <T> apiCallHelper, object model)
        {
            if (!result.Succeeded)
            {
                if (apiCallHelper.ValidationErrors?.Count > 0)
                {
                    foreach (var validation in apiCallHelper.ValidationErrors)
                    {
                        ModelState.AddModelError(validation.Property, validation.Error);
                    }
                }

                return(this.View(model));
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            return(this.RedirectToAction("Index"));
        }
Пример #9
0
        private async Task <List <ProductModel> > GetProducts()
        {
            var json = JsonConvert.SerializeObject(new ProductDTO
            {
                PagingArgs = Common.Models.PagingArgs.NoPaging
            });
            var apiHelper = new ApiCallHelper <ProductDTO>(this.clientFactory)
            {
                ControllerName = "Product"
            };
            var entities = await apiHelper.GetListAsync(json);

            if (entities.Data.Any())
            {
                for (var i = 0; i < entities.Data.Count; i++)
                {
                    entities.Data[i].PictureUrl = $"{AppSettings.ApiUrl}Picture?file={entities.Data[i].PictureUrl}&folder=Product";
                }
            }

            return(entities.Data.Select(x =>
            {
                return new ProductModel
                {
                    Id = x.Id,
                    DateCreated = x.DateCreated,
                    Description = x.Description,
                    HasOffer = x.OfferEndDate.HasValue ? true : false,
                    IsActive = x.IsActive,
                    OfferEndDate = x.OfferEndDate,
                    OfferPrice = x.OfferPrice,
                    Name = x.Name,
                    Price = x.Price,
                    PictureUrl = x.PictureUrl,
                    Special = x.Special
                };
            }).ToList());
        }
Пример #10
0
        private async Task ValidateAndSaveCredentials(string email, string password)
        {
            AppConstant.LoginUser = null;
            using (UserDialogs.Instance.Loading(AppConstant.PleaseWait))
            {
                var response = await ApiCallHelper.ValidateUser(new LoginRequest { Email = email, Password = password });

                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var userDetails = JsonConvert.DeserializeObject <ResponseObject <User> >(response.Content);
                        if (userDetails != null)
                        {
                            if (userDetails.StatusCode == HttpStatusCode.BadRequest)
                            {
                                return;
                            }
                            else
                            {
                                var userId = userDetails.Response.id;
                                //Plugin.Settings.UserProfileSettings = (loggedInSwitch.IsToggled ? JsonConvert.SerializeObject(new LoginRequest { Email = email, Password = password, UserId = userId, Provider = AuthenticatorProvider.NSL }) : string.Empty);
                                AppConstant.UserId = userId;
                                //AppConstant.Provider = AuthenticatorProvider.NSL.ToString();
                                await Navigation.PushAsync(new MasterDrawerPage());

                                return;
                            }
                        }
                    }
                }
                await DisplayAlert(AppConstant.ErrorHeading, AppConstant.InvalidCredentialsErrorMessage, AppConstant.ErrorAcceptance);

                return;
            }
        }
Пример #11
0
 public OrdersController(IHttpClientFactory clientFactory)
     : base(clientFactory)
 {
     this.apiCallHelper = new ApiCallHelper <OrderDTO>(this.clientFactory);
     this.apiCallHelper.ControllerName = "Order";
 }
Пример #12
0
 public ProductController(IHttpClientFactory clientFactory)
     : base(clientFactory)
 {
     this.apiCallHelper = new ApiCallHelper <ProductDTO>(this.clientFactory);
     this.apiCallHelper.ControllerName = "Product";
 }
Пример #13
0
        public async Task <ResponseDto> NotifyAsync(string message, string title, string[] recipient, string sender,
                                                    string scheduleDate, bool isSchedule = false, Attachment attachments = null)
        {
            //init data object
            var data = new DataDto
            {
                Message      = message,
                Recipient    = recipient,
                Sender       = sender,
                ScheduleDate = scheduleDate,
                IsSchedule   = isSchedule,
                File         = attachments?.File,
                Campaign     = title
            };

            var scopeFactory = _services
                               .BuildServiceProvider()
                               .GetRequiredService <IServiceScopeFactory>();

            var stream = await CreateStream(scopeFactory, data);


            if (!HelperExtention.IsNullAttachment(attachments))
            {
                _campaign = await ApiCallHelper <ResponseDto> .CampaignWithVoice(
                    $"{Constant.MnotifyGatewayJsonEndpoint}/voice/quick?key={ApiKey}",
                    data
                    );
                await InsertOrUpdateRecord(scopeFactory, stream);

                return(_campaign);
            }

            if (!HelperExtention.IsNullGroupWithMessage(null, null))
            {
                _campaign = await ApiCallHelper <ResponseDto> .CampaignGroup(
                    $"{Constant.MnotifyGatewayJsonEndpoint}/sms/group?key={ApiKey}",
                    data
                    );

                await InsertOrUpdateRecord(scopeFactory, stream);

                return(_campaign);
            }

            if (!HelperExtention.IsNullAttachmentWithGroup(attachments, null))
            {
                _campaign = await ApiCallHelper <ResponseDto> .CampaignGroupWithVoice(
                    $"{Constant.MnotifyGatewayJsonEndpoint}/voice/group?key={ApiKey}",
                    data
                    );

                await InsertOrUpdateRecord(scopeFactory, stream);

                return(_campaign);
            }

            _campaign = await ApiCallHelper <ResponseDto> .Campaign(
                $"{Constant.MnotifyGatewayJsonEndpoint}/sms/quick?key={ApiKey}",
                data
                );

            await InsertOrUpdateRecord(scopeFactory, stream);

            return(_campaign);
        }
Пример #14
0
 public RestaurantController(IHttpClientFactory clientFactory)
     : base(clientFactory)
 {
     this.apiCallHelper = new ApiCallHelper <RestaurantDTO>(this.clientFactory);
     this.apiCallHelper.ControllerName = "Restaurant";
 }
Пример #15
0
 public StockController(IHttpClientFactory clientFactory)
     : base(clientFactory)
 {
     this.apiCallHelper = new ApiCallHelper <StockDTO>(this.clientFactory);
     this.apiCallHelper.ControllerName = "Stock";
 }
Пример #16
0
 public CustomerController(IHttpClientFactory clientFactory)
     : base(clientFactory)
 {
     this.apiCallHelper = new ApiCallHelper <CustomerDTO>(this.clientFactory);
     this.apiCallHelper.ControllerName = "Customer";
 }