Ejemplo n.º 1
0
        public void Update(PurchaseCylinder obj)
        {
            PurchaseCylinder newPurchaseMaster = context.PurchaseCylinders.Where(obj1 => obj1.ID == obj.ID).FirstOrDefault();
            PurchaseDetail   newpurchaseDetail = new PurchaseDetail();

            newPurchaseMaster.dealerName   = obj.dealerName;
            newPurchaseMaster.BillNo       = obj.BillNo;
            newPurchaseMaster.purchaseDate = obj.purchaseDate;
            newPurchaseMaster.amount       = obj.amount;
            context.SaveChanges();
            if (obj.PurchaseDetailForEdit != null)
            {
                foreach (var i in obj.PurchaseDetailForEdit)
                {
                    newpurchaseDetail.cylinder_Id    = i.cylinder_Id;
                    newpurchaseDetail.cylinderType   = i.cylinderType;
                    newpurchaseDetail.FilledCylinder = i.FilledCylinder;
                    var livecylinder = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id).FirstOrDefault();
                    if (livecylinder != null)
                    {
                        livecylinder.FilledCylinderCount = livecylinder.FilledCylinderCount + i.FilledCylinder;
                        context.SaveChanges();
                    }
                    else
                    {
                        var livecylinderNew = new LiveCylinderDetail();
                        livecylinderNew.cylinder_Id              = i.cylinder_Id;
                        livecylinderNew.CylinderTypeName         = i.cylinderType;
                        livecylinderNew.FilledCylinderCount      = i.FilledCylinder;
                        livecylinderNew.EmptyCylinderCount       = 0;
                        livecylinderNew.ReplacementCylinderCount = 0;
                        context.LiveCylinderDetails.Add(livecylinderNew);
                        context.SaveChanges();
                    }
                    newpurchaseDetail.purchase_Id = obj.ID;
                    context.PurchaseDetails.Add(newpurchaseDetail);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        public int Insert(CylinderMaster obj)
        {
            CylinderMaster newCustomerMaster = new CylinderMaster();

            if (context.CylinderMasters.ToList() != null && context.CylinderMasters.ToList().Count > 0)
            {
                newCustomerMaster.ID = Convert.ToInt32(context.CylinderMasters.ToList().Last().ID) + 1;
            }
            else
            {
                newCustomerMaster.ID = 1;
            }

            // newCustomerMaster.ID = Convert.ToInt32(id.ID) + 1;
            newCustomerMaster.amount         = Convert.ToDecimal(string.Format("{0:0.00}", obj.amount));
            newCustomerMaster.cylinderType   = obj.cylinderType;
            newCustomerMaster.openingEmpty   = obj.openingEmpty;
            newCustomerMaster.openingFilled  = obj.openingFilled;
            newCustomerMaster.openingReplace = obj.openingReplace;
            newCustomerMaster.CreatedOn      = DateTime.Now;
            newCustomerMaster.CreatedBy      = obj.CreatedBy;


            context.CylinderMasters.Add(newCustomerMaster);
            context.SaveChanges();

            var livecylinderNew = new LiveCylinderDetail();

            livecylinderNew.cylinder_Id              = newCustomerMaster.ID;
            livecylinderNew.CylinderTypeName         = newCustomerMaster.cylinderType;
            livecylinderNew.FilledCylinderCount      = newCustomerMaster.openingFilled;
            livecylinderNew.EmptyCylinderCount       = newCustomerMaster.openingEmpty;
            livecylinderNew.ReplacementCylinderCount = newCustomerMaster.openingReplace;
            context.LiveCylinderDetails.Add(livecylinderNew);
            context.SaveChanges();

            return(newCustomerMaster.ID);
        }