Пример #1
0
        public int SaveChemicalPrepartion(PrdDyingChemicalSetup model, List <PrdDyingChemicalSetupDetail> details, UserCommonEntity commonEntity)
        {
            GFactory_EF_PrdDyingChemicalSetup             = new PrdDyingChemicalSetup_EF();
            GenericFactory_EF_PrdDyingChemicalSetupDetail = new PrdDyingChemicalSetupDetail_EF();
            int masterID = (int)model.ChemicalSetupID;
            PrdDyingChemicalSetup modelBase  = new PrdDyingChemicalSetup();
            List <Int32>          UpdatedIDs = new List <Int32>();
            List <PrdDyingChemicalSetupDetail> detailsList          = new List <PrdDyingChemicalSetupDetail>();
            List <PrdDyingChemicalSetupDetail> detailsInsertionList = new List <PrdDyingChemicalSetupDetail>();
            int result = 0;

            try
            {
                modelBase = ModelBinding(model, details);
                foreach (var item in modelBase.PrdDyingChemicalSetupDetails)
                {
                    if (item.EntryStateStatus == "Modified")
                    {
                        PrdDyingChemicalSetupDetail detailsEntity = new PrdDyingChemicalSetupDetail();
                        detailsEntity = DetailsBinding(modelBase.PrdDyingChemicalSetupDetails.Where(x => x.ChemicalSetupDetailID == item.ChemicalSetupDetailID).FirstOrDefault());
                        detailsList.Add(detailsEntity);
                        UpdatedIDs.Add((int)detailsEntity.ChemicalSetupDetailID);
                    }
                    if (item.EntryStateStatus == "Add" && masterID > 0)
                    {
                        PrdDyingChemicalSetupDetail detailsEntity = new PrdDyingChemicalSetupDetail();
                        detailsEntity = DetailsBinding(modelBase.PrdDyingChemicalSetupDetails.Where(x => x.ChemicalSetupDetailID == item.ChemicalSetupDetailID).FirstOrDefault());
                        detailsInsertionList.Add(detailsEntity);
                    }
                }

                foreach (var item in UpdatedIDs)
                {
                    modelBase.PrdDyingChemicalSetupDetails.Remove(modelBase.PrdDyingChemicalSetupDetails.Where(x => x.ChemicalSetupDetailID == item).FirstOrDefault());
                }
                if (masterID == 0)
                {
                    GFactory_EF_PrdDyingChemicalSetup.Insert(modelBase);
                    GFactory_EF_PrdDyingChemicalSetup.Save();
                }
                else
                {
                    GFactory_EF_PrdDyingChemicalSetup.Update(model);
                    GenericFactory_EF_PrdDyingChemicalSetupDetail.UpdateList(detailsList);
                    GenericFactory_EF_PrdDyingChemicalSetupDetail.InsertList(detailsInsertionList);
                    GFactory_EF_PrdDyingChemicalSetup.Save();
                    GenericFactory_EF_PrdDyingChemicalSetupDetail.Save();
                }

                result = 1;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return(result);
        }
Пример #2
0
        private PrdDyingChemicalSetupDetail DetailsBinding(PrdDyingChemicalSetupDetail Item)
        {
            PrdDyingChemicalSetupDetail entity = new PrdDyingChemicalSetupDetail();

            entity.EntryStateStatus      = Item.EntryStateStatus;
            entity.ChemicalSetupDetailID = Item.ChemicalSetupDetailID;
            entity.ChemicalSetupID       = Item.ChemicalSetupID;
            entity.ItemID    = Item.ItemID;
            entity.Qty       = Item.Qty;
            entity.UnitID    = Item.UnitID;
            entity.IsDeleted = Item.IsDeleted;
            entity.CompanyID = Item.CompanyID;
            entity.CreateBy  = Item.CreateBy;
            entity.CreateOn  = Item.CreateOn;
            entity.CreatePc  = Item.CreatePc;
            entity.UpdateBy  = Item.UpdateBy;
            entity.UpdateOn  = Item.UpdateOn;
            entity.UpdatePc  = Item.UpdatePc;
            entity.IsDeleted = Item.IsDeleted;
            entity.DeleteBy  = Item.DeleteBy;
            entity.DeleteOn  = Item.DeleteOn;
            entity.DeletePc  = Item.DeletePc;
            return(entity);
        }
Пример #3
0
        private PrdDyingChemicalSetup ModelBinding(PrdDyingChemicalSetup model, List <PrdDyingChemicalSetupDetail> details)
        {
            GFactory_EF_PrdDyingChemicalSetup = new PrdDyingChemicalSetup_EF();
            try
            {
                Int64 NextID = GFactory_EF_PrdDyingChemicalSetup.getMaxVal_int64("ChemicalSetupID", "PrdDyingChemicalSetup");
                model.ChemicalSetupID = model.ChemicalSetupID == 0 ? NextID : model.ChemicalSetupID;
                model.ColorID         = model.ColorID;
                model.Qty             = model.Qty;
                model.DepartmentID    = model.DepartmentID;
                model.UserID          = model.UserID;
                model.UnitID          = model.UnitID;
                model.IsDeleted       = false;
                NextID = GFactory_EF_PrdDyingChemicalSetup.getMaxVal_int64("ChemicalSetupDetailID", "PrdDyingChemicalSetupDetail");
                foreach (PrdDyingChemicalSetupDetail Item in details)
                {
                    PrdDyingChemicalSetupDetail entity = new PrdDyingChemicalSetupDetail();
                    entity.ChemicalSetupDetailID = Item.ChemicalSetupDetailID;
                    if (Item.ChemicalSetupDetailID == 0)
                    {
                        if (Item.IsDeleted)
                        {
                            continue;
                        }
                        Item.ChemicalSetupDetailID   = NextID++;
                        entity.ChemicalSetupDetailID = Item.ChemicalSetupDetailID;
                        entity.EntryStateStatus      = "Add";
                    }
                    else if (Item.IsDeleted == true)
                    {
                        entity.EntryStateStatus = "Delete";
                    }
                    else
                    {
                        entity.EntryStateStatus = "Modified";
                    }
                    entity.ItemID          = Item.ItemID;
                    entity.Qty             = Item.Qty;
                    entity.ChemicalSetupID = model.ChemicalSetupID;
                    entity.UnitID          = Item.UnitID;
                    entity.IsDeleted       = Item.IsDeleted;
                    entity.CompanyID       = Item.CompanyID;
                    entity.CompanyID       = model.CompanyID;
                    entity.CreateBy        = Item.CreateBy;
                    entity.CreateOn        = Item.CreateOn;
                    entity.CreatePc        = Item.CreatePc;
                    entity.UpdateBy        = Item.UpdateBy;
                    entity.UpdateOn        = Item.UpdateOn;
                    entity.UpdatePc        = Item.UpdatePc;
                    if (entity.EntryStateStatus != "Delete")
                    {
                        entity.IsDeleted = false;
                    }
                    else
                    {
                        entity.EntryStateStatus = "Modified";
                        entity.IsDeleted        = true;
                    }
                    entity.DeleteBy = Item.DeleteBy;
                    entity.DeleteOn = Item.DeleteOn;
                    entity.DeletePc = Item.DeletePc;

                    model.PrdDyingChemicalSetupDetails.Add(entity);
                }

                return(model);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                throw;
            }
        }