Exemplo n.º 1
0
        public void Update(LoadCylinder obj)
        {
            LoadCylinder newLoadMaster = context.LoadCylinders.Where(obj1 => obj1.ID == obj.ID).FirstOrDefault();


            newLoadMaster.user_id  = obj.user_id;
            newLoadMaster.userName = obj.userName;
            newLoadMaster.loadDate = obj.loadDate;
            context.SaveChanges();
            if (obj.LoadDetailForEdit != null)
            {
                foreach (var i in obj.LoadDetailForEdit)
                {
                    LoadDetail newLoadDetail = new LoadDetail();
                    newLoadDetail.cylinder_Id    = i.cylinder_Id;
                    newLoadDetail.cylinderType   = i.cylinderType;
                    newLoadDetail.FilledCylinder = i.FilledCylinder;
                    var t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id);
                    var livecylinder = t.First();
                    if (t != null && i.ID <= 0)
                    {
                        //livecylinder.FilledCylinderCount = livecylinder.FilledCylinderCount - i.FilledCylinder;
                        //context.SaveChanges();
                        var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - i.FilledCylinder;
                        if (fillecount <= 0)
                        {
                            livecylinder.FilledCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.FilledCylinderCount = fillecount;
                        }
                        context.SaveChanges();
                    }

                    // var livecylinder = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id).FirstOrDefault();
                    // var livecylinder = t.First();
                    //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();
                    //}
                    newLoadDetail.load_Id = obj.ID;
                    context.LoadDetails.Add(newLoadDetail);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public int Insert(LoadCylinder obj)
        {
            LoadCylinder newLoadMaster = new LoadCylinder();


            newLoadMaster.user_id   = obj.user_id;
            newLoadMaster.userName  = obj.userName;
            newLoadMaster.loadDate  = obj.loadDate;
            newLoadMaster.createdBy = obj.createdBy;
            newLoadMaster.createdOn = obj.createdOn;
            context.LoadCylinders.Add(newLoadMaster);
            context.SaveChanges();
            if (obj.LoadDetail != null)
            {
                foreach (var i in obj.LoadDetail)
                {
                    LoadDetail newLoadDetail = new LoadDetail();
                    newLoadDetail.cylinder_Id    = i.cylinder_Id;
                    newLoadDetail.cylinderType   = i.cylinderType;
                    newLoadDetail.FilledCylinder = i.FilledCylinder;
                    var t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id);
                    var livecylinder = t.First();
                    if (t != null)
                    {
                        //livecylinder.FilledCylinderCount = livecylinder.FilledCylinderCount - i.FilledCylinder;
                        //context.SaveChanges();
                        var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - i.FilledCylinder;
                        if (fillecount <= 0)
                        {
                            livecylinder.FilledCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.FilledCylinderCount = fillecount;
                        }
                        context.SaveChanges();
                    }

                    newLoadDetail.load_Id = newLoadMaster.ID;
                    context.LoadDetails.Add(newLoadDetail);
                    context.SaveChanges();
                }
            }
            return(newLoadMaster.ID);
        }
Exemplo n.º 3
0
        public void DeleteDetail(int id)
        {
            LoadDetail newLoadCylinder = context.LoadDetails.Where(obj => obj.ID == id).FirstOrDefault();
            var        t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == newLoadCylinder.cylinder_Id);
            var        livecylinder = t.First();

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

            context.LoadDetails.Remove(newLoadCylinder);
            context.SaveChanges();
        }