public string Transfer(int storeID, int storeTransferId, int ProductId, int Count)
        {
            try
            {
                var FirstStore = productInStoreDal.Get(p => p.StoreId == storeID && p.ProductId == ProductId);
                //var LastStore = productInStoreDal.Get(p => p.StoreId == storeID && p.ProductId == ProductId);

                ProductInStore transferControlData = productInStoreDal.Get(p => p.StoreId == storeTransferId && p.ProductId == ProductId);
                if (transferControlData == null)
                {
                    ProductInStore LastStoreNew = new ProductInStore {
                        ProductId = ProductId, StoreId = storeTransferId, Stock = Count
                    };
                    productInStoreDal.Add(LastStoreNew);
                }
                else
                {
                    var LastStore = productInStoreDal.Get(p => p.StoreId == storeTransferId && p.ProductId == ProductId);
                    LastStore.Stock = LastStore.Stock + Count;
                    productInStoreDal.Update(LastStore);
                }
                FirstStore.Stock = FirstStore.Stock - Count;
                productInStoreDal.Update(FirstStore);

                JObject jsonObject = new JObject();
                jsonObject.Add("Status", "success");
                jsonObject.Add("ErrorMessage", "Transfer başarıyla tamamlandı");
                JArray array = new JArray();
                array.Add(jsonObject);
                return(JsonConvert.SerializeObject(array));
            }
            catch (Exception)
            {
                JObject jsonObject = new JObject();
                //jsonObject.Add("Status", "success");
                jsonObject.Add("ErrorMessage", "Transfer gerçekleştirilemedi. Tekrar deneyiniz...");
                JArray array = new JArray();
                array.Add(jsonObject);
                return(JsonConvert.SerializeObject(array));
            }
        }
Exemplo n.º 2
0
 public string Buy(ProductInStore productInStore, StockMovement stockMovement)
 {
     result  = validator.Validate(productInStore);
     result2 = validator2.Validate(stockMovement);
     if (result.IsValid && result2.IsValid)
     {
         ProductInStore productInStore1 = productInStoreDal.Get(p => p.ProductId == productInStore.ProductId && p.StoreId == productInStore.StoreId);
         if (productInStore1 == null)
         {
             productInStoreDal.Add(productInStore);
         }
         else
         {
             productInStore1.Stock += productInStore.Stock;
             productInStoreDal.Update(productInStore1);
         }
         stockMovementDal.Add(stockMovement);
         JObject jsonObject = new JObject();
         jsonObject.Add("Status", "success");
         jsonObject.Add("ErrorMessage", "Ürün başarıyla satın alındı.");
         JArray array = new JArray();
         array.Add(jsonObject);
         return(JsonConvert.SerializeObject(array));
     }
     else
     {
         if (!result.IsValid)
         {
             return(JsonConvert.SerializeObject(result.Errors));
         }
         else
         {
             return(JsonConvert.SerializeObject(result2.Errors));
         }
     }
 }