Beispiel #1
0
 /// <summary>
 /// menampilkan data produk yang tiba
 /// </summary>
 /// <returns></returns>
 public List<PoDelivered> getProductDelivered()
 {
     var product = getProducts();
     if (product.Count() > 0)
     {
         try
         {
             List<PoDelivered> lpod = new List<PoDelivered>();
             foreach (var item in product)
             {
                 int qty = 0;
                 ProductDelivered pdd = db.productDeliveredData.FirstOrDefault(p => p.po == _po && p.product == item.product);
                 if (pdd != null)
                 {
                     qty = pdd.qty_delivered;
                 }
                 PoDelivered pd = new PoDelivered()
                 {
                     product = item.product,
                     product_t = item.product_t,
                     qty = item.qty,
                     unit = item.unit,
                     qty_delivered = qty
                 };
                 lpod.Add(pd);
             }
             return lpod.ToList();
         }
         catch (Exception e)
         {
             Log.Error(e);
             return new List<PoDelivered>();
         }
     }
     else
     {
         return new List<PoDelivered>();
     }
 }
Beispiel #2
0
        /// <summary>
        /// perubahan status barang tiba
        /// </summary>
        /// <param name="po"></param>
        /// <param name="noteModel"></param>
        /// <param name="statusModel"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool setPoDelivered(string po, string noteModel, string statusModel, IEnumerable<ProductDelivered> model)
        {
            try
            {
                DeliveredInfo di = db.deliveredInfoData.FirstOrDefault(p => p.po == po);
                if (di == null)
                {
                    di = new DeliveredInfo()
                    {
                        po = po,
                        note = noteModel,
                        status = statusModel,
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now
                    };
                    db.deliveredInfoData.Add(di);
                }
                else
                {
                    di.note = noteModel;
                    di.status = statusModel;
                    di.updated_at = DateTime.Now;
                }
                db.SaveChanges();

                foreach (var item in model)
                {
                    ProductDelivered pd = db.productDeliveredData.FirstOrDefault(p => p.po == po && p.product == item.product);
                    if (pd == null)
                    {
                        pd = new ProductDelivered()
                        {
                            po = po,
                            product = item.product,
                            qty_delivered = item.qty_delivered,
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now
                        };
                        db.productDeliveredData.Add(pd);
                    }
                    else
                    {
                        //ProductDelivered newPd = new ProductDelivered() {
                        //    qty_delivered = item.qty_delivered,
                        //    updated_at = item.updated_at
                        //};
                        pd.qty_delivered = item.qty_delivered;
                        pd.updated_at = DateTime.Now;
                        //db.Entry(pd).CurrentValues.SetValues(newPd);
                        //db.Entry(pd).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                return true;
            }
            catch (Exception e)
            {
                Log.Error(e);
                return false;
            }
        }