コード例 #1
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));
         }
     }
 }
コード例 #2
0
 public string Add(StockMovement entity)
 {
     result = validator.Validate(entity);
     if (result.IsValid)
     {
         stockMovementDal.Add(entity);
         JObject jsonObject = new JObject();
         jsonObject.Add("Status", "success");
         jsonObject.Add("ErrorMessage", "Kayıt başarıyla oluşturuldu");
         JArray array = new JArray();
         array.Add(jsonObject);
         return(JsonConvert.SerializeObject(array));
     }
     else
     {
         return(JsonConvert.SerializeObject(result.Errors));
     }
 }