예제 #1
0
 public async Task<AsyncResult<string>> SaveAsync(Product product)
 {
     var token = authStore.LoadToken();
     using (var client = new BearerHttpClient(token.AccessToken))
     {
         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>();
 }
예제 #2
0
        public ChangePriceItem(Product p)
        {
            Product = p;

            k = Convert.ToString(p.K);
            length = Convert.ToString(p.Length);
        }
        public ProductEditWindowViewModel Init(Product p)
        {
            Title = string.Format("{0} {1}", p.Name, p.Size);

            Context = (p.IsSheet)
                ? new SheetEditViewModel2(p, canEditPrice)
                : new ProductEditViewModel2(p, canEditPrice);

            InitAttachments(p.Id);

            IsWindowOpen = true;
            return this;
        }
예제 #4
0
        public ProductEditViewModel Init(Product product = null)
        {
            if (product == null)
            {
                product = new Product();
                IsNewProduct = true;
            }
            else
            {
                IsNewProduct = false;
            }

            ProductToProps(product);

            var token = authStore.LoadToken();
            if (token != null)
            {
                IsEditor = token.IsEditor();
                DenyPriceEdit = !token.IsAdmin();
            }

            return this;
        }
예제 #5
0
 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;
     IsSheet = product.IsSheet;
     Firma = product.Firma;
 }
 private void UpdateContext()
 {
     var product = new Product();
     Context = (isSheet)
         ? new SheetEditViewModel2(product, true)
         : new ProductEditViewModel2(product, true);
 }
예제 #7
0
 private void OpenProduct(Product p)
 {
     editProductRequest.Raise(productEditViewModel.Init(p));
 }
예제 #8
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);
            }
        }
예제 #9
0
 public SheetEditViewModel2(Product product, bool canEditPrice) : base(product, canEditPrice)
 {
 }
예제 #10
0
 public ProductEditViewModel2(Product product, bool canEditPrice)
 {
     IsPriceReadonly = !canEditPrice;
     ProductToProps(product);
 }