public int SaveTeam(vCmnUserTeam master, List <vCmnuserTeamDetail> Details, UserCommonEntity commonEntity) { int returnValue = 0; try { GenericFactoryEF_CmnUserTeam = new CmnUserTeam_EF(); if (master.EntityMode == "Inserted") { CmnUserTeam returnModel = this.InsertionModelBinding(master, Details, commonEntity); GenericFactoryEF_CmnUserTeam.Insert(returnModel); GenericFactoryEF_CmnUserTeam.Save(); returnValue = 1; } else if (master.EntityMode == "Updated" && !Details.Any(x => x.EntityMode == "Inserted")) { CmnUserTeam returnModel = this.InsertionModelBinding(master, Details, commonEntity); GenericFactoryEF_CmnUserTeam.Update(returnModel); GFactory_EF_CmnuserTeamDetail = new CmnuserTeamDetail_EF(); GFactory_EF_CmnuserTeamDetail.UpdateList(this.UpdateDetailsBinding(Details, commonEntity)); GenericFactoryEF_CmnUserTeam.Save(); GFactory_EF_CmnuserTeamDetail.Save(); returnValue = 2; } else { CmnUserTeam returnModel = this.InsertionModelBinding(master, Details, commonEntity); GenericFactoryEF_CmnUserTeam.Update(returnModel); GFactory_EF_CmnuserTeamDetail = new CmnuserTeamDetail_EF(); GFactory_EF_CmnuserTeamDetail.UpdateList(this.UpdateDetailsBinding(Details.Where(x => x.EntityMode == "Updated").ToList(), commonEntity)); GFactory_EF_CmnuserTeamDetail.InsertList(this.InsertionList(master, Details.Where(x => x.EntityMode == "Inserted").ToList(), commonEntity)); GenericFactoryEF_CmnUserTeam.Save(); GFactory_EF_CmnuserTeamDetail.Save(); returnValue = 2; } } catch (Exception ex) { throw; } return(returnValue); }
public int DeleteTeam(vCmnUserTeam master, UserCommonEntity commonEntity) { int returnValue = 0; try { GenericFactoryEF_CmnUserTeam = new CmnUserTeam_EF(); CmnUserTeam returnModel = GenericFactoryEF_CmnUserTeam.FindBy(x => x.TeamID == master.TeamID).FirstOrDefault(); returnModel.IsDeleted = true; returnModel.DeleteBy = commonEntity.loggedUserID; returnModel.DeleteOn = DateTime.Now; returnModel.DeletePc = HostService.GetIP(); GenericFactoryEF_CmnUserTeam.Update(returnModel); GenericFactoryEF_CmnUserTeam.Save(); returnValue = 3; } catch (Exception) { throw; } return(returnValue); }
private CmnUserTeam InsertionModelBinding(vCmnUserTeam model, List <vCmnuserTeamDetail> details, UserCommonEntity commonEntity) { GenericFactoryEF_CmnUserTeam = new CmnUserTeam_EF(); try { Int64 NextID = GenericFactoryEF_CmnUserTeam.getMaxVal_int64("TeamID", "CmnUserTeam"); CmnUserTeam returnModel = new CmnUserTeam(); returnModel.TeamID = model.TeamID == 0 ? NextID : model.TeamID; returnModel.TeamName = model.TeamName; returnModel.DepartmentID = model.DepartmentID; returnModel.CompanyID = model.CompanyID; if (model.EntityMode == "Inserted") { returnModel.CreateBy = commonEntity.loggedUserID; returnModel.CreateOn = DateTime.Now; returnModel.CreatePc = HostService.GetIP(); } else { returnModel.UpdateBy = commonEntity.loggedUserID; returnModel.UpdateOn = DateTime.Now; returnModel.UpdatePc = HostService.GetIP(); } returnModel.IsDeleted = model.IsDeleted; if (returnModel.IsDeleted == true) { returnModel.DeleteBy = commonEntity.loggedUserID; returnModel.DeleteOn = DateTime.Now; returnModel.DeletePc = HostService.GetIP(); } NextID = GenericFactoryEF_CmnUserTeam.getMaxVal_int64("TeamDetailID", "CmnuserTeamDetail"); foreach (vCmnuserTeamDetail Item in details) { CmnuserTeamDetail entity = new CmnuserTeamDetail(); entity.TeamDetailID = NextID++; if (Item.EntityMode != "Inserted") { entity.TeamDetailID = Item.TeamDetailID; } entity.TeamID = returnModel.TeamID; entity.UserID = Item.UserID; entity.Sequence = Item.Sequence; entity.CompanyID = Item.CompanyID; entity.CreateBy = Item.CreateBy; entity.CreateOn = DateTime.Now; entity.CreatePc = HostService.GetIP(); 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; returnModel.CmnuserTeamDetails.Add(entity); } return(returnModel); } catch (Exception ex) { ex.Message.ToString(); throw; } }