public string DelUpdateSetMasterDetail(vmCmnParameters objcmnParam) { string result = string.Empty; using (var transaction = new TransactionScope()) { GFactory_EF_PrdSetMaster = new PrdSetMaster_EF(); GFactory_EF_PrdSetSetup = new PrdSetSetup_EF(); var Masteritem = new PrdSetMaster(); var SetDetail = new List <PrdSetSetup>(); //For Update Master Detail var SetMasterAll = GFactory_EF_PrdSetMaster.GetAll().Where(x => x.SetMasterID == objcmnParam.id); var SetDetailAll = GFactory_EF_PrdSetSetup.GetAll().Where(x => x.SetMasterID == objcmnParam.id); //-------------------END---------------------- try { using (_ctxCmn = new ERP_Entities()) { Masteritem = SetMasterAll.First(x => x.SetMasterID == objcmnParam.id); Masteritem.CompanyID = objcmnParam.loggedCompany; Masteritem.DeleteBy = objcmnParam.loggeduser; Masteritem.DeleteOn = DateTime.Now; Masteritem.DeletePc = HostService.GetIP(); Masteritem.IsDeleted = true; foreach (PrdSetSetup d in SetDetailAll.Where(d => d.SetMasterID == objcmnParam.id)) { d.CompanyID = objcmnParam.loggedCompany; d.DeleteBy = objcmnParam.loggeduser; d.DeleteOn = DateTime.Now; d.DeletePc = HostService.GetIP(); d.IsDeleted = true; SetDetail.Add(d); } } if (Masteritem != null) { GFactory_EF_PrdSetMaster.Update(Masteritem); GFactory_EF_PrdSetMaster.Save(); } if (SetDetail != null) { GFactory_EF_PrdSetSetup.UpdateList(SetDetail.ToList()); GFactory_EF_PrdSetSetup.Save(); } transaction.Complete(); result = "1"; } catch (Exception e) { result = ""; e.ToString(); } } return(result); }
public async Task <string> SaveUpdateSetSetupMasterDetail(vmSetSetupMasterDetail ModelMaster, List <vmSetSetupMasterDetail> ModelDetail, vmCmnParameters objcmnParam) { string result = string.Empty; long TransactionID = 0; using (var transaction = new TransactionScope()) { GFactory_EF_PrdSetMaster = new PrdSetMaster_EF(); GFactory_EF_PrdSetSetup = new PrdSetSetup_EF(); string SetNo = string.Empty; int SetMasterId = 0, SetDetailId = 0; long SetFirstDigit = 0, SetOtherDigits = 0; var Masteritem = new PrdSetMaster(); var SetDetail = new List <PrdSetSetup>(); vmSetSetupMasterDetail item = new vmSetSetupMasterDetail(); vmSetSetupMasterDetail items = new vmSetSetupMasterDetail(); //-------------------END---------------------- if (ModelDetail.Count() > 0) { try { using (_ctxCmn = new ERP_Entities()) { if (ModelMaster.SetMasterID == 0) { SetMasterId = Convert.ToInt16(GFactory_EF_PrdSetMaster.getMaxID("PrdSetMaster")); SetDetailId = Convert.ToInt16(GFactory_EF_PrdSetSetup.getMaxID("PrdSetSetup")); SetFirstDigit = Convert.ToInt64(SetDetailId.ToString().Substring(0, 1)); SetOtherDigits = Convert.ToInt64(SetDetailId.ToString().Substring(1, SetDetailId.ToString().Length - 1)); //CustomNo = GFactory_EF_PrdSetSetup.getCustomCode(MenuId, DateTime.Now, CompanyId, 1, 1); //if (CustomNo == null || CustomNo == "") //{ // SetNo = SetDetailId.ToString(); //} //else //{ // SetNo = CustomNo; //} TransactionID = SetMasterId; Masteritem = new PrdSetMaster { SetMasterID = SetMasterId, BuyerID = ModelMaster.BuyerID, Description = ModelMaster.Description, ItemID = (long)ModelMaster.ItemID, PIID = ModelMaster.PIID, PIItemlength = ModelMaster.PIItemlength, RefSetDate = ModelMaster.RefSetDate, RefSetID = ModelMaster.RefSetID, SetDate = ModelMaster.SetDate, SupplierID = ModelMaster.SupplierID, StatusID = ModelMaster.StatusID, CompanyID = objcmnParam.loggedCompany, CreateBy = objcmnParam.loggeduser, CreateOn = DateTime.Now, CreatePc = HostService.GetIP(), IsDeleted = false }; for (int i = 0; i < ModelDetail.Count(); i++) { item = ModelDetail[i]; var Detailitem = new PrdSetSetup { SetID = Convert.ToInt64(SetFirstDigit + "" + SetOtherDigits), YarnID = (long)item.YarnID, WarpYarnID = item.YarnID, WeftYarnID = item.WeftYarnID, Weave = item.Weave, BuyerID = item.BuyerID, ColorID = item.ColorID, Description = item.Description, EndsPerCreel = item.EndsPerCreel, LeaseReapet = item.LeaseRepeat, MachineSpeed = item.MachineSpeed, SetDate = item.SetDate, ItemID = (long)item.ItemID, PIID = item.PIID, SetLength = (long)item.SetLength, SetMasterID = SetMasterId, SetNo = item.SetNo, SupplierID = item.SupplierID, TotalEnds = item.TotalEnds, YarnCount = item.YarnCount, YarnRatio = item.YarnRatio, YarnRatioLot = item.YarnRatioLot, NoOfBall = item.NoOfBall, CompanyID = objcmnParam.loggedCompany, CreateBy = objcmnParam.loggeduser, CreateOn = DateTime.Now, CreatePc = HostService.GetIP(), IsDeleted = false }; //***************************************END******************************************* SetDetail.Add(Detailitem); SetOtherDigits++; } } else { var SetMasterAll = GFactory_EF_PrdSetMaster.GetAll().Where(x => x.SetMasterID == ModelMaster.SetMasterID); var SetDetailAll = GFactory_EF_PrdSetSetup.GetAll().Where(x => x.SetMasterID == ModelMaster.SetMasterID); Masteritem = SetMasterAll.FirstOrDefault(x => x.SetMasterID == ModelMaster.SetMasterID); Masteritem.BuyerID = ModelMaster.BuyerID; Masteritem.Description = ModelMaster.Description; Masteritem.ItemID = (long)ModelMaster.ItemID; Masteritem.PIID = ModelMaster.PIID; Masteritem.PIItemlength = ModelMaster.PIItemlength; Masteritem.RefSetDate = ModelMaster.RefSetDate; Masteritem.RefSetID = ModelMaster.RefSetID; Masteritem.SetDate = ModelMaster.SetDate; Masteritem.SupplierID = ModelMaster.SupplierID; Masteritem.StatusID = ModelMaster.StatusID; Masteritem.CompanyID = objcmnParam.loggedCompany; Masteritem.UpdateBy = objcmnParam.loggeduser; Masteritem.UpdateOn = DateTime.Now; Masteritem.UpdatePc = HostService.GetIP(); Masteritem.IsDeleted = false; for (int i = 0; i < ModelDetail.Count(); i++) { item = ModelDetail[i]; foreach (PrdSetSetup d in SetDetailAll.Where(d => d.SetMasterID == ModelMaster.SetMasterID && d.SetID == item.SetID)) { d.YarnID = (long)item.YarnID; d.WarpYarnID = item.YarnID; d.WeftYarnID = item.WeftYarnID; d.Weave = item.Weave; d.BuyerID = item.BuyerID; d.ColorID = item.ColorID; d.Description = item.Description; d.EndsPerCreel = item.EndsPerCreel; d.LeaseReapet = item.LeaseRepeat; d.MachineSpeed = item.MachineSpeed; d.SetDate = item.SetDate; d.ItemID = (long)item.ItemID; d.PIID = item.PIID; d.SetLength = (long)item.SetLength; d.SetNo = item.SetNo; d.SupplierID = item.SupplierID; d.TotalEnds = item.TotalEnds; d.YarnCount = item.YarnCount; d.YarnRatio = item.YarnRatio; d.YarnRatioLot = item.YarnRatioLot; d.NoOfBall = item.NoOfBall; d.CompanyID = objcmnParam.loggedCompany; d.UpdateBy = objcmnParam.loggeduser; d.UpdateOn = DateTime.Now; d.UpdatePc = HostService.GetIP(); d.IsDeleted = false; SetDetail.Add(d); break; } } } if (ModelMaster.SetMasterID > 0) { if (Masteritem != null) { GFactory_EF_PrdSetMaster.Update(Masteritem); GFactory_EF_PrdSetMaster.Save(); } if (SetDetail != null && SetDetail.Count != 0) { GFactory_EF_PrdSetSetup.UpdateList(SetDetail.ToList()); GFactory_EF_PrdSetSetup.Save(); } } else { if (Masteritem != null) { GFactory_EF_PrdSetMaster.Insert(Masteritem); GFactory_EF_PrdSetMaster.Save(); GFactory_EF_PrdSetMaster.updateMaxID("PrdSetMaster", Convert.ToInt64(SetMasterId)); } if (SetDetail != null && SetDetail.Count != 0) { GFactory_EF_PrdSetSetup.InsertList(SetDetail.ToList()); GFactory_EF_PrdSetSetup.Save(); GFactory_EF_PrdSetSetup.updateMaxID("PrdSetSetup", Convert.ToInt64(SetFirstDigit + "" + (SetOtherDigits - 1))); } } transaction.Complete(); result = "1"; } } catch (Exception e) { result = ""; e.ToString(); } } else { result = ""; throw new Exception(); } } // Approval Code #region WorkFlow Transaction Entry and email sending if (ModelMaster.SetMasterID == 0) { UserCommonEntity commonEntity = new UserCommonEntity(); commonEntity.currentMenuID = objcmnParam.menuId; commonEntity.loggedCompnyID = objcmnParam.loggedCompany; commonEntity.loggedUserID = objcmnParam.loggeduser; int workflowID = 0; List <vmCmnWorkFlowMaster> listWorkFlow = new WorkFLowMgt().GetWorkFlowMasterListByMenu(commonEntity); foreach (vmCmnWorkFlowMaster itemWFM in listWorkFlow) { int userTeamID = itemWFM.UserTeamID ?? 0; if (new WorkFLowMgt().checkUserValidation(commonEntity.loggedUserID ?? 0, itemWFM.WorkFlowID) && userTeamID > 0) { itemWFM.WorkFlowTranCustomID = (Int16)TransactionID; workflowID = new WorkFLowMgt().ExecuteTransactionProcess(itemWFM, commonEntity); } if (userTeamID == 0) { itemWFM.WorkFlowTranCustomID = (Int16)TransactionID; workflowID = new WorkFLowMgt().ExecuteTransactionProcess(itemWFM, commonEntity); } } int mail = 0; foreach (vmCmnWorkFlowMaster itemWFM in listWorkFlow) { NotificationEntity notification = new NotificationEntity(); notification.WorkFlowID = itemWFM.WorkFlowID; notification.TransactionID = (Int16)TransactionID; List <vmNotificationMail> nModel = new WorkFLowMgt().GetNotificationMailObjectList(notification, "Created"); foreach (var mailModel in nModel) { mail = await new EmailService().NotificationMail(mailModel); } } } #endregion WorkFlow Transaction Entry and email sending return(result); }