private CmnCustomCodeDetail DetailsBinding(CmnCustomCodeDetail Item) { CmnCustomCodeDetail entity = new CmnCustomCodeDetail(); entity.EntryStateStatus = Item.EntryStateStatus; entity.RecordDetailID = Item.RecordDetailID; entity.CustomCode = Item.CustomCode; entity.CustomCodeID = Item.CustomCodeID; entity.ParameterName = Item.ParameterName; entity.Length = Item.Length; entity.Seperator = Item.Seperator; entity.Sequence = Item.Sequence; entity.StatusID = Item.StatusID; 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); }
public int SavCustomCode(CmnCustomCode model, List <CmnCustomCodeDetail> details) { GenericFactory_EF_customCode = new CmnCustomCode_EF(); GenericFactory_EF_customDetails = new CmnCustomCodeDetail_EF(); int masterID = model.RecordID; CmnCustomCode modelBase = new CmnCustomCode(); List <Int32> UpdatedIDs = new List <Int32>(); List <CmnCustomCodeDetail> detailsListDeleted = new List <CmnCustomCodeDetail>(); List <CmnCustomCodeDetail> detailsList = new List <CmnCustomCodeDetail>(); List <CmnCustomCodeDetail> detailsInsertionList = new List <CmnCustomCodeDetail>(); int result = 0; try { modelBase = ModelBinding(model, details); foreach (var item in modelBase.CmnCustomCodeDetails) { if (item.EntryStateStatus == "Modified") { CmnCustomCodeDetail detailsEntity = new CmnCustomCodeDetail(); detailsEntity = DetailsBinding(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item.RecordDetailID).FirstOrDefault()); detailsList.Add(detailsEntity); UpdatedIDs.Add(detailsEntity.RecordDetailID); } if (item.EntryStateStatus == "Add" && masterID > 0) { CmnCustomCodeDetail detailsEntity = new CmnCustomCodeDetail(); detailsEntity = DetailsBinding(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item.RecordDetailID).FirstOrDefault()); detailsInsertionList.Add(detailsEntity); } } foreach (var item in UpdatedIDs) { modelBase.CmnCustomCodeDetails.Remove(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item).FirstOrDefault()); } if (masterID == 0) { GenericFactory_EF_customCode.Insert(modelBase); GenericFactory_EF_customCode.Save(); } else { GenericFactory_EF_customCode.Update(model); GenericFactory_EF_customDetails.UpdateList(detailsList); foreach (CmnCustomCodeDetail item in detailsList) { if (item.IsDeleted) { detailsListDeleted.Add(item); } } if (detailsListDeleted.Count > 0) { GenericFactory_EF_customDetails.DeleteList(detailsListDeleted); } GenericFactory_EF_customDetails.InsertList(detailsInsertionList); GenericFactory_EF_customCode.Save(); GenericFactory_EF_customDetails.Save(); GenericFactory_EF_customDetails = new CmnCustomCodeDetail_EF(); } result = 1; } catch (Exception ex) { ex.ToString(); return(result); } return(result); }
private CmnCustomCode ModelBinding(CmnCustomCode model, List <CmnCustomCodeDetail> details) { GenericFactory_EF_customCode = new CmnCustomCode_EF(); try { int NextID = GenericFactory_EF_customCode.getMaxVal_int("RecordID", "CmnCustomCode"); model.RecordID = model.RecordID == 0 ? NextID : model.RecordID; model.CustomCode = model.RecordID.ToString(); model.CompanyID = model.CompanyID; model.IsCompany = model.IsCompany ?? false; model.IsOrganogramCode = model.IsOrganogramCode ?? false; model.IsDeleted = false; NextID = GenericFactory_EF_customCode.getMaxVal_int("RecordDetailID", "CmnCustomCodeDetail"); foreach (CmnCustomCodeDetail Item in details) { CmnCustomCodeDetail entity = new CmnCustomCodeDetail(); entity.RecordDetailID = Item.RecordDetailID; if (Item.RecordDetailID == 0) { if (Item.IsDeleted) { continue; } Item.RecordDetailID = NextID++; entity.RecordDetailID = Item.RecordDetailID; entity.EntryStateStatus = "Add"; } else if (Item.IsDeleted == true) { entity.EntryStateStatus = "Delete"; } else { entity.EntryStateStatus = "Modified"; } entity.CustomCode = entity.RecordDetailID.ToString(); entity.CustomCodeID = model.RecordID; entity.ParameterName = Item.ParameterName; entity.Length = Item.Length; entity.Seperator = Item.Seperator; entity.Sequence = Item.Sequence; entity.StatusID = Item.StatusID; 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.CmnCustomCodeDetails.Add(entity); } } catch (Exception ex) { ex.ToString(); } return(model); }