Example #1
0
        //public async Task<AsyncResult<Product[]>> GetNamesAsync(List<string> ids)
        //{
        //    using (var client = httpClientFactory())
        //    {
        //        var data = JsonConvert.SerializeObject(ids);
        //        using (var content = new StringContent(data, Encoding.UTF8, "application/json"))
        //        {
        //            var uri = new Uri("api/products/getNames", UriKind.Relative);
        //            using (var resp = await client.PostAsync(uri, content))
        //            {
        //                var str = await resp.Content.ReadAsStringAsync();
        //                var res = JsonConvert.DeserializeObject<Product[]>(str);
        //                return new AsyncResult<Product[]> { Result = res, Succeed = true };
        //            }
        //        }
        //    }
        //}

        public async Task<AsyncResult<string>> SaveAsync(Product product)
        {
            using (var client = httpClientFactory())
            {
                var data = JsonConvert.SerializeObject(product);
                using (var content = new StringContent(data, Encoding.UTF8, "application/json"))
                {
                    if (product.Id == null)
                    {
                        var uri = new Uri("api/products/", UriKind.Relative);
                        var resp = await client.PostAsync(uri, content);
                        if (resp.StatusCode == HttpStatusCode.Created)
                        {
                            var id = await resp.Content.ReadAsStringAsync();
                            return new AsyncResult<string> { Result = id, Succeed = true };
                        }
                    }
                    else
                    {
                        var uri = new Uri(string.Concat("api/products/", product.Id), UriKind.Relative);
                        var resp = await client.PutAsync(uri, content);
                        if (resp.StatusCode == HttpStatusCode.OK)
                        {
                            return new AsyncResult<string> { Result = product.Id, Succeed = true };
                        }
                    }
                }
            }
            return new AsyncResult<string>();
        }
Example #2
0
        private void UpdateProductItem(Product current)
        {
            if (items == null) return;

            var old = items.FirstOrDefault(x => x.Id == current.Id);
            if (old != null)
            {
                var index = items.IndexOf(old);
                items.RemoveAt(index);
                items.Insert(index, current);
            }
            else
            {
                items.Add(current);
            }
        }
Example #3
0
 private void EditProduct(Product p)
 {
     var args = new OpenWindowEventArgs(PageName.ProductEditWindow, p);
     eventAggregator.GetEvent<OpenWindowEvent>().Publish(args);
 }
Example #4
0
 public SheetFormViewModel(Product product, bool canEditPrice)
     : base(product, canEditPrice)
 {
 }
Example #5
0
 public ChangePriceItem(Product p)
 {
     Product = p;
 }
 private void ProductToProps(Product product)
 {
     id = product.Id;
     name = product.Name;
     size = product.Size;
     k = product.K.ToString("0.##");
     priceOpt = product.PriceOpt.ToString(CultureInfo.InvariantCulture);
     priceRozn = product.PriceRozn;
     weight = product.Weight;
     count = product.Count.ToString(CultureInfo.InvariantCulture);
     if (product.Nd != null)
     {
         nd = string.Join(" ", product.Nd);
     }
     length = product.Length.ToString("0.###");
     priceIcome = product.PriceIcome.ToString(CultureInfo.InvariantCulture);
     Internal = product.Internal;
     Firma = product.Firma;
 }
 public ProductFormViewModel(Product product, bool canEditPrice)
 {
     IsPriceReadonly = !canEditPrice;
     ProductToProps(product);
 }
 private void UpdateContext()
 {
     var product = new Product();
     Context = (isSheet)
         ? new SheetFormViewModel(product, true)
         : new ProductFormViewModel(product, true);
 }