Exemplo n.º 1
0
 public Maybe <StockDto> NewOrder(HttpRequest req)
 {
     return(req.TryGetMaybeObject(r =>
     {
         return new StreamReader(r.Body).ReadToEndAsync().Result
         .Map(s => JsonConvert.DeserializeObject <CartDto>(s))
         .Map(d => d.Lines.FirstOrDefault())
         .Map(l => new StockDto()
         {
             Name = l.Name, Quantity = l.Quantity
         });
     })
            .Railway(dto =>
     {
         var isExist = _stockRepo.IsExistAsync(dto.Value.Name).Result;
         if (isExist.IsSuccess && isExist.Value)
         {
             return Maybe.Ok(_stockRepo.UpdateAsync(dto.Value).Result.Value);
         }
         if (isExist.IsSuccess && !isExist.Value)
         {
             return Maybe.Ok(_stockRepo.AddAsync(dto.Value).Result.Value);
         }
         return Maybe.Fail <StockDto>(isExist.Error);
     }));
 }
Exemplo n.º 2
0
 public Maybe <StockDto> NewOrder(CartDto req)
 {
     return(req.TryGetMaybeObject(r =>
     {
         var temp = r.Lines.FirstOrDefault();
         return new StockDto()
         {
             Name = temp.Name, Quantity = temp.Quantity
         };
     })
            .Railway(dto =>
     {
         var isExist = _stockRepo.IsExistAsync(dto.Value.Name).Result;
         if (isExist.IsSuccess && isExist.Value)
         {
             return Maybe.Ok(_stockRepo.UpdateAsync(dto.Value).Result.Value);
         }
         if (isExist.IsSuccess && !isExist.Value)
         {
             return Maybe.Ok(_stockRepo.AddAsync(dto.Value).Result.Value);
         }
         return Maybe.Fail <StockDto>(isExist.Error);
     }));
 }