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); } } } } } }
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()); }
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); } }
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; } } } } }
private void GetOfflineSavedPosts() { using (UserDialogs.Instance.Loading(AppConstant.PleaseWait)) { var result = ApiCallHelper.GetOfflineSavedPosts(); if (result != null) { Images = new ObservableCollection <Post>(result); } } }
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; } } }
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()); }
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")); }
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()); }
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; } }
public OrdersController(IHttpClientFactory clientFactory) : base(clientFactory) { this.apiCallHelper = new ApiCallHelper <OrderDTO>(this.clientFactory); this.apiCallHelper.ControllerName = "Order"; }
public ProductController(IHttpClientFactory clientFactory) : base(clientFactory) { this.apiCallHelper = new ApiCallHelper <ProductDTO>(this.clientFactory); this.apiCallHelper.ControllerName = "Product"; }
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); }
public RestaurantController(IHttpClientFactory clientFactory) : base(clientFactory) { this.apiCallHelper = new ApiCallHelper <RestaurantDTO>(this.clientFactory); this.apiCallHelper.ControllerName = "Restaurant"; }
public StockController(IHttpClientFactory clientFactory) : base(clientFactory) { this.apiCallHelper = new ApiCallHelper <StockDTO>(this.clientFactory); this.apiCallHelper.ControllerName = "Stock"; }
public CustomerController(IHttpClientFactory clientFactory) : base(clientFactory) { this.apiCallHelper = new ApiCallHelper <CustomerDTO>(this.clientFactory); this.apiCallHelper.ControllerName = "Customer"; }