public JsonResult GetTestInfo(EPortal.Models.Test Testinfo) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; TestList TestinfoTest = new TestList(); using (EPortalEntities entity = new EPortalEntities()) { TestinfoTest = (from o in entity.Tests where o.Id == Testinfo.Id && o.OrganizationID == orgid select new TestList { Id = o.Id, TestCode = o.TestCode, TestName = o.TestName, PeriodFrom = o.PeriodFrom, PeriodTo = o.PeriodTo, Operation = "Edit", HourTime = o.HourTime, MinTime = o.MinTime, IsPublish = o.IsPublish, Islocked = o.Islocked }).FirstOrDefault(); } return(Json(TestinfoTest, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteTest(EPortal.Models.Test Testinfo) { int result = 0; //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; string errormsg = string.Empty; // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required"); using (EPortalEntities entity = new EPortalEntities()) { var checkreferance = (from r in entity.ApplicantTests where r.OrganizationID == orgid && r.TestId == Testinfo.Id select r).FirstOrDefault(); if (checkreferance != null) { errormsg = "Operation conflict:Operation cannot be performed.Record already in Used."; } else { var checktestsectionref = (from tsr in entity.TestSections where tsr.OrganizationID == orgid && tsr.ParentId == Testinfo.Id select tsr).FirstOrDefault(); if (checktestsectionref != null) { errormsg = "Operation conflict:Operation cannot be performed.Record already in Used."; } else { entity.Entry(Testinfo).State = System.Data.Entity.EntityState.Deleted; result = entity.SaveChanges(); } } } return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveTest(EPortal.Models.Test TestInfo) { string errormsg = ""; int result = 0; //if ((TestInfo.TestCode != "" || TestInfo.TestCode != null) && (TestInfo.TestName != "" || TestInfo.TestName != null)) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; using (EPortalEntities entity = new EPortalEntities()) { if (TestInfo.Operation == "Create") { var checktestcodeexist = (from t in entity.Tests where t.OrganizationID == orgid && t.TestCode == TestInfo.TestCode select t).FirstOrDefault(); if (checktestcodeexist == null) { TestInfo.Id = Guid.NewGuid().ToString(); TestInfo.OrganizationID = orgid; TestInfo.RowState = true; TestInfo.CreateDateTime = System.DateTime.Now; TestInfo.IsPublish = false; TestInfo.Islocked = false; entity.Entry(TestInfo).State = System.Data.Entity.EntityState.Added; entity.Tests.Add(TestInfo); try { result = entity.SaveChanges(); } catch (Exception ex) { } } else { errormsg = "Test already exist with same Code."; } } else { EPortal.Models.Test usedata = (from o in entity.Tests where o.OrganizationID == orgid && o.Id == TestInfo.Id select o ).FirstOrDefault(); usedata.TestCode = TestInfo.TestCode; usedata.TestName = TestInfo.TestName; usedata.PeriodFrom = TestInfo.PeriodFrom; usedata.PeriodTo = TestInfo.PeriodTo; usedata.HourTime = TestInfo.HourTime; usedata.MinTime = TestInfo.MinTime; entity.Entry(usedata).State = System.Data.Entity.EntityState.Modified; try { result = entity.SaveChanges(); } catch (Exception ex) { } } } } //else //{ // if (TestInfo.TestCode != "" || TestInfo.TestCode != null) // { // errormsg = "Please enter Code."; // } // if (TestInfo.TestName != "" || TestInfo.TestName != null) // { // errormsg = "Please enter Name."; // } //} return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet)); }