public void DeleteDetail(int id)
        {
            ReturnDetail newReturnCylinder = context.ReturnDetails.Where(obj => obj.ID == id).FirstOrDefault();
            var          t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == newReturnCylinder.cylinder_Id);
            var          livecylinder = t.First();

            if (t != null)
            {
                var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) + newReturnCylinder.FilledCylinder;
                if (fillecount <= 0)
                {
                    livecylinder.FilledCylinderCount = 0;
                }
                else
                {
                    livecylinder.FilledCylinderCount = fillecount;
                }


                var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) + newReturnCylinder.EmptyCylinder;
                if (emptycount <= 0)
                {
                    livecylinder.EmptyCylinderCount = 0;
                }
                else
                {
                    livecylinder.EmptyCylinderCount = emptycount;
                }

                var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) + newReturnCylinder.RejectedCylinder;
                if (replacecount <= 0)
                {
                    livecylinder.ReplacementCylinderCount = 0;
                }
                else
                {
                    livecylinder.ReplacementCylinderCount = replacecount;
                }

                context.SaveChanges();
            }
            context.ReturnDetails.Remove(newReturnCylinder);
            context.SaveChanges();
        }
        public int Insert(ReturnCylinder obj)
        {
            ReturnCylinder newReturnMaster = new ReturnCylinder();


            newReturnMaster.ERVNo      = obj.ERVNo;
            newReturnMaster.dealerName = obj.dealerName;
            newReturnMaster.returnDate = obj.returnDate;
            context.ReturnCylinders.Add(newReturnMaster);
            context.SaveChanges();
            if (obj.ReturnDetail != null)
            {
                foreach (var i in obj.ReturnDetail)
                {
                    ReturnDetail newReturnDetail = new ReturnDetail();
                    newReturnDetail.cylinder_Id      = i.cylinder_Id;
                    newReturnDetail.cylinderType     = i.cylinderType;
                    newReturnDetail.FilledCylinder   = i.FilledCylinder;
                    newReturnDetail.EmptyCylinder    = i.EmptyCylinder;
                    newReturnDetail.RejectedCylinder = i.RejectedCylinder;
                    var t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id);
                    var livecylinder = t.First();

                    if (t != null)
                    {
                        var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - i.FilledCylinder;
                        if (fillecount <= 0)
                        {
                            livecylinder.FilledCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.FilledCylinderCount = fillecount;
                        }


                        var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) - i.EmptyCylinder;
                        if (emptycount <= 0)
                        {
                            livecylinder.EmptyCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.EmptyCylinderCount = emptycount;
                        }

                        var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) - i.RejectedCylinder;
                        if (replacecount <= 0)
                        {
                            livecylinder.ReplacementCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.ReplacementCylinderCount = replacecount;
                        }

                        context.SaveChanges();
                    }
                    newReturnDetail.return_Id = newReturnMaster.ID;
                    context.ReturnDetails.Add(newReturnDetail);
                    context.SaveChanges();
                }
            }
            return(newReturnMaster.ID);
        }