Ejemplo n.º 1
0
 public ReceivedProductViewModel(ReceivedProduct receivedProduct)
 {
     if (receivedProduct != null)
     {
         Id = receivedProduct.Id;
         ProductDetailID = receivedProduct.ProductDetailID;
         Quantity        = receivedProduct.Quantity;
         RowVersion      = receivedProduct.RowVersion;
         CreatedAt       = receivedProduct.CreatedAt;
         UpdatedAt       = receivedProduct.UpdatedAt;
         User            = new UserViewModel(receivedProduct.User);
     }
 }
Ejemplo n.º 2
0
 public Task <ReceivedProduct> Delete(Guid id)
 {
     return(Task.Run(() =>
     {
         ReceivedProduct receivedProduct = _db.ReceivedProducts.Find(id);
         if (receivedProduct != null)
         {
             _db.ReceivedProducts.Remove(receivedProduct);
             _db.SaveChanges();
         }
         return receivedProduct;
     }));
 }
Ejemplo n.º 3
0
 public Task <ReceivedProduct> Update(Guid id, ReceivedProduct data)
 {
     return(Task.Run(() =>
     {
         ReceivedProduct receivedProduct = _db.ReceivedProducts.Find(id);
         if (receivedProduct != null)
         {
             receivedProduct.Quantity = receivedProduct.Quantity;
             receivedProduct.ProductDetailID = receivedProduct.ProductDetailID;
             receivedProduct.UpdatedAt = DateTime.UtcNow;
             _db.SaveChanges();
         }
         return receivedProduct;
     }));
 }
Ejemplo n.º 4
0
        //plan tambah siapa penerima barang nya dan bikin sp
        public async Task <ReceivedProduct> Create(ReceivedProduct data)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    int totalQuantityProductDetail = _db.ProductDetails.Find(data.ProductDetailID).Quantity;
                    int totalReceivedProduct       = 0;
                    var objReceivedProduct         = _db.ReceivedProducts.Where(e => e.ProductDetailID == data.ProductDetailID);

                    if (objReceivedProduct.Count() != 0)
                    {
                        totalReceivedProduct = objReceivedProduct.Sum(e => e.Quantity);
                    }

                    if (totalQuantityProductDetail < totalReceivedProduct + data.Quantity)
                    {
                        transaction.Rollback();
                        throw new Exception("product is received more than request");
                    }

                    var receivedProductObj = await Task.Run(() =>
                    {
                        ReceivedProduct receivedProduct = _db.ReceivedProducts.Create();
                        receivedProduct.ProductDetailID = data.ProductDetailID;
                        receivedProduct.UserId          = data.UserId;
                        receivedProduct.Quantity        = data.Quantity;
                        _db.ReceivedProducts.Add(receivedProduct);
                        _db.SaveChanges();
                        transaction.Commit();
                        return(receivedProduct);
                    });

                    return(receivedProductObj);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
        }