private void Initialize(MarketAdapterViewHolder holder, ProductDataObject item) { try { if (item.Images?.Count > 0) { if (item.Images[0].Image.Contains("http")) { GlideImageLoader.LoadImage(ActivityContext, item.Images?[0]?.Image, holder.Thumbnail, ImageStyle.CenterCrop, ImagePlaceholders.Drawable); } else { Glide.With(ActivityContext).Load(new File(item.Images?[0]?.Image)).Apply(new RequestOptions().CenterCrop().Placeholder(Resource.Drawable.ImagePlacholder).Error(Resource.Drawable.ImagePlacholder)).Into(holder.Thumbnail); } } GlideImageLoader.LoadImage(ActivityContext, item.Seller?.Avatar, holder.Userprofilepic, ImageStyle.CircleCrop, ImagePlaceholders.Color); holder.Title.Text = Methods.FunString.DecodeString(item.Name); holder.UserName.Text = WoWonderTools.GetNameFinal(item.Seller); holder.Time.Text = item.TimeText; var(currency, currencyIcon) = WoWonderTools.GetCurrency(item.Currency); Console.WriteLine(currency); holder.TxtPrice.Text = currencyIcon + " " + item.Price; holder.LocationText.Text = !string.IsNullOrEmpty(item.Location) ? item.Location : ActivityContext.GetText(Resource.String.Lbl_Unknown); } catch (Exception e) { Console.WriteLine(e); } }
public static void Bridge() { var clientRepository = new ClientRepository(); var productRepository = new ProductRepository(); var clientDataObject = new ClientDataObject(); clientRepository.AddObject(clientDataObject); clientRepository.SaveChanges(); clientRepository.CopyObject(clientDataObject); clientRepository.RemoveObject(clientDataObject); clientRepository.SaveChanges(); var productDataObject = new ProductDataObject(); productRepository.AddObject(productDataObject); clientRepository.SaveChanges(); productRepository.CopyObject(productDataObject); productRepository.RemoveObject(productDataObject); productRepository.SaveChanges(); Console.ReadKey(); }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 3500 && resultCode == Result.Ok) { if (string.IsNullOrEmpty(data.GetStringExtra("itemData"))) { return; } var item = JsonConvert.DeserializeObject <ProductDataObject>(data.GetStringExtra("itemData")); if (item != null) { ProductData = item; Get_Data_Product(item); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); SetTheme(AppSettings.SetTabDarkTheme ? Resource.Style.MyTheme_Dark_Base : Resource.Style.MyTheme_Base); Methods.App.FullScreenApp(this); // Create your application here SetContentView(Resource.Layout.ProductView_Layout); PostId = Intent?.GetStringExtra("Id") ?? string.Empty; ClickListener = new PostClickListener(this, NativeFeedType.Global); //Get Value And Set Toolbar InitComponent(); SetRecyclerViewAdapters(); ProductData = JsonConvert.DeserializeObject <ProductDataObject>(Intent?.GetStringExtra("ProductView") ?? ""); if (ProductData == null) { return; } Get_Data_Product(ProductData); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void Get_Data_Product() { try { ProductData = JsonConvert.DeserializeObject <ProductDataObject>(Intent?.GetStringExtra("ProductView")); if (ProductData != null) { var list = ProductData.Images; foreach (var attach in list.Select(productPathImage => new Attachments { Id = Convert.ToInt32(productPathImage.Id), TypeAttachment = "", FileSimple = productPathImage.Image, FileUrl = productPathImage.Image, })) { MAdapter.Add(attach); } TxtTitle.Text = ProductData.Name; var(currency, currencyIcon) = WoWonderTools.GetCurrency(ProductData.Currency); Console.WriteLine(currency); TxtPrice.Text = ProductData.Price; TxtCurrency.Text = currencyIcon; CurrencyId = ProductData.Currency; TxtLocation.Text = ProductData.Location; TxtAbout.Text = ProductData.Description; CategoryId = ProductData.Category; TxtCategory.Text = CategoriesController.ListCategoriesProducts.FirstOrDefault(a => a.CategoriesId == ProductData.Category)?.CategoriesName; switch (ProductData.Type) { // New case "0": RbNew.Checked = true; RbUsed.Checked = false; ProductType = "0"; break; // Used default: RbNew.Checked = false; RbUsed.Checked = true; ProductType = "1"; break; } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public ActionResult EditProduct(ProductDataObject product) { using (ServiceProxy <IProductService> proxy = new ServiceProxy <IProductService>()) { proxy.Channel.UpdateProducts(new ProductDataObjectList { product }); if (product.Category.ID != Guid.Empty.ToString()) { proxy.Channel.CategorizeProduct(new Guid(product.ID), new Guid(product.Category.ID)); } else { proxy.Channel.UncategorizeProduct(new Guid(product.ID)); } return(RedirectToSuccess("更新商品信息成功!", "Products", "Admin")); } }
public ActionResult AddProduct(ProductDataObject product) { using (ServiceProxy <IProductService> proxy = new ServiceProxy <IProductService>()) { if (string.IsNullOrEmpty(product.ImageUrl)) { var fileName = Guid.NewGuid().ToString() + ".png"; System.IO.File.Copy(Server.MapPath("~/Images/Products/ProductImage.png"), Server.MapPath(string.Format("~/Images/Products/{0}", fileName))); product.ImageUrl = fileName; } var addedProducts = proxy.Channel.CreateProducts(new ProductDataObjectList { product }); if (product.Category != null && product.Category.ID != Guid.Empty.ToString()) { proxy.Channel.CategorizeProduct(new Guid(addedProducts[0].ID), new Guid(product.Category.ID)); } return(RedirectToSuccess("添加商品信息成功!", "Products", "Admin")); } }
static void Main(string[] args) { /* * https://en.wikipedia.org/wiki/Bridge_pattern * What problems can the Bridge design pattern solve? * An abstraction and its implementation should be defined and extended independently from each other. * A compile-time binding between an abstraction and its implementation should be avoided so that an implementation can be selected at run-time. * * When using subclassing, different subclasses implement an abstract class in different ways. * But an implementation is bound to the abstraction at compile-time and can't be changed at run-time. */ var clientRepository = new ClientRepository(); var clientDataObject = new ClientDataObject(); clientRepository.AddObject(clientDataObject); clientRepository.SaveChanges(); clientRepository.CopyObject(clientDataObject); clientRepository.RemoveObject(clientDataObject); clientRepository.SaveChanges(); Console.WriteLine("==============================================================="); var productRepository = new ProductRepository(); var productDataObject = new ProductDataObject(); productRepository.AddObject(productDataObject); clientRepository.SaveChanges(); productRepository.CopyObject(productDataObject); productRepository.RemoveObject(productDataObject); productRepository.SaveChanges(); Console.ReadKey(); }
private async void TxtAddOnClick(object sender, EventArgs e) { try { if (!Methods.CheckConnectivity()) { Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } else { if (string.IsNullOrEmpty(TxtTitle.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_name), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtPrice.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_price), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtLocation.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Location), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtAbout.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_about), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtCurrency.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_Currency), ToastLength.Short)?.Show(); return; } var list = MAdapter.AttachmentList.Where(a => a.TypeAttachment != "Default").ToList(); if (list.Count == 0) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Image), ToastLength.Short)?.Show(); } else { //Show a progress AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading) + "..."); var(apiStatus, respond) = await RequestsAsync.Market.Create_Product(TxtTitle.Text, TxtAbout.Text, TxtLocation.Text, TxtPrice.Text, CurrencyId, CategoryId, ProductType, list); if (apiStatus == 200) { if (respond is CreateProductObject result) { AndHUD.Shared.ShowSuccess(this); Toast.MakeText(this, GetText(Resource.String.Lbl_CreatedSuccessfully), ToastLength.Short)?.Show(); var listImage = list.Select(productPathImage => new Images { Id = "", ProductId = result.ProductId.ToString(), Image = productPathImage.FileSimple, ImageOrg = productPathImage.FileSimple }).ToList(); //Add new item to my Event list var user = ListUtils.MyProfileList?.FirstOrDefault(); ProductDataObject data = new ProductDataObject { Name = TxtTitle.Text, UserId = UserDetails.UserId, Id = result.ProductId.ToString(), Location = TxtLocation.Text, Description = TxtAbout.Text, Category = CategoryId, Images = new List <Images>(listImage), Price = TxtPrice.Text, Type = ProductType, Seller = user, Currency = CurrencyId, }; if (TabbedMarketActivity.GetInstance()?.MyProductsTab.MAdapter.MarketList != null) { TabbedMarketActivity.GetInstance()?.MyProductsTab.MAdapter?.MarketList?.Insert(0, data); TabbedMarketActivity.GetInstance()?.MyProductsTab.MAdapter?.NotifyItemInserted(TabbedMarketActivity.GetInstance().MyProductsTab.MAdapter.MarketList.IndexOf(data)); } Intent returnIntent = new Intent(); returnIntent?.PutExtra("product", JsonConvert.SerializeObject(data)); SetResult(Result.Ok, returnIntent); Finish(); } } else { Methods.DisplayAndHudErrorResult(this, respond); } } } } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); AndHUD.Shared.Dismiss(this); } }
private void Get_Data_Product(ProductDataObject productData) { try { ProductData = productData; PostData = new PostDataObject { PostId = productData.PostId, Product = new ProductUnion { ProductClass = productData, }, ProductId = productData.Id, UserId = productData.UserId, UserData = productData.Seller, Url = productData.Url, PostUrl = productData.Url, }; List <string> listImageUser = new List <string>(); if (productData.Images?.Count > 0) { listImageUser.AddRange(productData.Images.Select(t => t.Image)); } else { listImageUser.Add(productData.Images?[0]?.Image); } if (ViewPagerView.Adapter == null) { ViewPagerView.Adapter = new MultiImagePagerAdapter(this, listImageUser); ViewPagerView.CurrentItem = 0; CircleIndicatorView.SetViewPager(ViewPagerView); } ViewPagerView.Adapter.NotifyDataSetChanged(); GlideImageLoader.LoadImage(this, productData.Seller.Avatar, UserImageAvatar, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); var(currency, currencyIcon) = WoWonderTools.GetCurrency(productData.Currency); TxtProductPrice.Text = productData.Price + " " + currencyIcon; Console.WriteLine(currency); var readMoreOption = new StReadMoreOption.Builder() .TextLength(200, StReadMoreOption.TypeCharacter) .MoreLabel(GetText(Resource.String.Lbl_ReadMore)) .LessLabel(GetText(Resource.String.Lbl_ReadLess)) .MoreLabelColor(Color.ParseColor(AppSettings.MainColor)) .LessLabelColor(Color.ParseColor(AppSettings.MainColor)) .LabelUnderLine(true) .Build(); if (Methods.FunString.StringNullRemover(productData.Description) != "Empty") { var description = Methods.FunString.DecodeString(productData.Description); readMoreOption.AddReadMoreTo(TxtProductDescription, new String(description)); } else { TxtProductDescription.Text = GetText(Resource.String.Lbl_Empty); } TxtProductLocation.Text = Methods.FunString.DecodeString(productData.Location); TxtProductCardName.Text = Methods.FunString.SubStringCutOf(WoWonderTools.GetNameFinal(productData.Seller), 14); TxtProductTime.Text = productData.TimeText; if (productData.Seller.UserId == UserDetails.UserId) { BtnContact.Visibility = ViewStates.Gone; } //Type == "0" >> New // Type != "0" Used TxtProductNew.Visibility = productData.Type == "0" ? ViewStates.Visible : ViewStates.Gone; // Status InStock TxtProductInStock.Visibility = productData.Status == "0" ? ViewStates.Visible : ViewStates.Gone; } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }