public JsonResult DeleteAcademicYear(EPortal.Models.AcademicYear academicyear) { int result = 0; string orgid = User.OrgId; string errormsg = string.Empty; using (EPortalEntities entity = new EPortalEntities()) { //var checkref = (from r in entity.Subjects // where r.OrganizationID == orgid // && r.Id == Subject.Id // select r).FirstOrDefault(); //if (checkref != null) //{ // errormsg = "Operation conflict:Operation cannot be performed.Record already in Used."; //} //else //{ //Subject subjectinfo = (from sub in entity.Subjects // where sub.Id == Subject.Id // && sub.OrganizationID == orgid // select sub).FirstOrDefault(); entity.Entry(academicyear).State = System.Data.Entity.EntityState.Deleted; //List<SubjectDetail> subjectdetails = (from detsub in entity.SubjectDetails // where detsub.SubjectId == Subject.Id // && detsub.OrganizationID == orgid // select detsub).ToList(); //if (subjectdetails.Count() > 0) //{ // foreach (SubjectDetail item in subjectdetails) // { // entity.Entry(item).State = System.Data.Entity.EntityState.Deleted; // } //} result = entity.SaveChanges(); //} } return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetAcademicYearInfo(EPortal.Models.AcademicYear academicyear) { string orgid = User.OrgId; AcademicYearList roleinforole = new AcademicYearList(); using (EPortalEntities entity = new EPortalEntities()) { roleinforole = (from o in entity.AcademicYears where o.Id == academicyear.Id && o.OrganizationID == orgid select new AcademicYearList { Id = o.Id, Code = o.Code, Name = o.Name, PeriodFrom = o.AcademicYearFrom.Value, PeriodTo = o.AcademicYearTo.Value, Operation = "Edit", }).FirstOrDefault(); } return(Json(roleinforole, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveAcademicYear(EPortal.Models.AcademicYear academicyear) { string errormsg = ""; int result = 0; //if ((role.Code != "" || role.Code != null) && (role.Name != "" || role.Name != null)) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; using (EPortalEntities entity = new EPortalEntities()) { if (academicyear.Operation == "Create") { var checkrolecode = (from r in entity.AcademicYears where r.OrganizationID == orgid && r.Code == academicyear.Code select r).FirstOrDefault(); if (checkrolecode == null) { academicyear.Id = Guid.NewGuid().ToString(); academicyear.RowState = true; academicyear.CreateDateTime = DateTime.Now; academicyear.OrganizationID = orgid; entity.Entry(academicyear).State = System.Data.Entity.EntityState.Added; } else { errormsg = "Subject already exist with same Code."; } try { result = entity.SaveChanges(); } catch (Exception ex) { } } else { EPortal.Models.AcademicYear roledata = (from o in entity.AcademicYears where o.OrganizationID == orgid && o.Id == academicyear.Id select o ).FirstOrDefault(); roledata.Code = academicyear.Code; roledata.Name = academicyear.Name; roledata.AcademicYearFrom = academicyear.AcademicYearFrom; roledata.AcademicYearTo = academicyear.AcademicYearTo; entity.Entry(roledata).State = System.Data.Entity.EntityState.Modified; try { result = entity.SaveChanges(); } catch (Exception ex) { } } } } return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet)); }