示例#1
0
        public void Delete(int id)
        {
            ReturnCylinder newReturnMaster = context.ReturnCylinders.Where(obj => obj.ID == id).FirstOrDefault();
            var            RD = context.ReturnDetails.Where(obj => obj.return_Id == id).ToList();

            foreach (var i in RD)
            {
                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();
                }
            }
            RD.ForEach(obj => context.ReturnDetails.Remove(obj));
            context.ReturnCylinders.Remove(newReturnMaster);
            context.SaveChanges();
        }
示例#2
0
        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);
        }