public JsonResult SaveUserGroup(UserGroupList usergroup, List <ApplicantList> applicantlist) { string orgid = User.OrgId; EPortal.Models.GroupUser groupuser = null; EPortal.Models.GroupUserApplicant groupuserapplicant = null; List <EPortal.Models.GroupUserApplicant> groupuserapplicantlist = new List <GroupUserApplicant>(); int result = 0; using (EPortalEntities entity = new EPortalEntities()) { if (usergroup.Operation != "Edit") { #region Save User group groupuser = new GroupUser(); groupuser.Id = Guid.NewGuid().ToString(); groupuser.GroupUserCode = usergroup.UserGroupCode; groupuser.GroupUserName = usergroup.UserGroupName; groupuser.OganizationId = orgid; groupuser.createdDate = System.DateTime.Now; entity.Entry(groupuser).State = System.Data.Entity.EntityState.Added; entity.GroupUsers.Add(groupuser); foreach (ApplicantList item in applicantlist.ToList()) { groupuserapplicant = new GroupUserApplicant(); groupuserapplicant.Id = Guid.NewGuid().ToString(); groupuserapplicant.GroupUserId = groupuser.Id; groupuserapplicant.ApplicantId = item.ApplicantId; groupuserapplicant.OganizationId = orgid; groupuserapplicant.createdDate = System.DateTime.Now; entity.Entry(groupuserapplicant).State = System.Data.Entity.EntityState.Added; entity.GroupUserApplicants.Add(groupuserapplicant); } #endregion } else { #region Update User Group groupuser = (from ug in entity.GroupUsers where ug.OganizationId == orgid && ug.Id == usergroup.Id select ug).FirstOrDefault(); if (groupuser != null) { groupuserapplicantlist = (from gap in entity.GroupUserApplicants where gap.GroupUserId == usergroup.Id select gap).ToList(); if (groupuserapplicantlist.Count() > 0) { foreach (var item in groupuserapplicantlist) { var itemdata = (from apl in applicantlist where apl.ApplicantId == item.ApplicantId select apl).FirstOrDefault(); if (itemdata == null) { entity.Entry(item).State = System.Data.Entity.EntityState.Deleted; } else { entity.Entry(item).State = System.Data.Entity.EntityState.Modified; } } foreach (var item in applicantlist) { var itemdata = (from apl in groupuserapplicantlist where apl.ApplicantId == item.ApplicantId select apl).FirstOrDefault(); if (itemdata == null) { groupuserapplicant = new GroupUserApplicant(); groupuserapplicant.Id = Guid.NewGuid().ToString(); groupuserapplicant.GroupUserId = groupuser.Id; groupuserapplicant.ApplicantId = item.ApplicantId; groupuserapplicant.OganizationId = orgid; groupuserapplicant.createdDate = System.DateTime.Now; entity.Entry(groupuserapplicant).State = System.Data.Entity.EntityState.Added; entity.GroupUserApplicants.Add(groupuserapplicant); } } } } #endregion } try { result = entity.SaveChanges(); } catch (Exception ex) { } } return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet)); }
public JsonResult GetTestList(UserGroupList usergroup) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; string userid = string.Empty; List <string> applicantlist = new List <string>(); List <TestList> org = new List <TestList>(); using (EPortalEntities entity = new EPortalEntities()) { org = (from o in entity.Tests where o.OrganizationID == orgid && o.IsPublish == true select new TestList { Id = o.Id, TestCode = o.TestCode, TestName = o.TestName, Selected = false, AlreadyApplied = false }).ToList(); applicantlist = (from u in entity.GroupUserApplicants where u.OganizationId == orgid && u.GroupUserId == usergroup.Id select u.ApplicantId).ToList(); if (org.Count() > 0) { List <string> checkselected = null; List <string> checkapplied = null; foreach (var item in org) { checkselected = new List <string>(); checkapplied = new List <string>(); foreach (var applicant in applicantlist) { var checkselectedapp = (from at in entity.ApplicantTests where at.OrganizationID == orgid && at.TestId == item.Id && at.ApplicantId == applicant //&& at.RowState == true select at.ApplicantId).FirstOrDefault(); if (checkselectedapp != null) { checkselected.Add(checkselectedapp); } var checkappliedapp = (from aa in entity.UserAnswers where aa.OrganizationID == orgid && aa.ApplicantId == applicant && aa.TestId == item.Id select aa.ApplicantId).FirstOrDefault(); if (checkappliedapp != null) { checkapplied.Add(checkappliedapp); } } if (checkselected.Count() == applicantlist.Count()) { item.Selected = true; } if (checkapplied.Count() == applicantlist.Count()) { item.AlreadyApplied = true; } } } } return(Json(org, JsonRequestBehavior.AllowGet)); }