示例#1
0
        public JsonResult GetClassInfo(EPortal.Models.Class Class)
        {
            //string orgid = Session["OrgId"].ToString();

            string orgid = User.OrgId;

            RoleList roleinforole = new RoleList();

            using (EPortalEntities entity = new EPortalEntities())
            {
                roleinforole = (from o in entity.Classes
                                where o.Id == Class.Id &&
                                o.OrganizationID == orgid
                                select new RoleList
                {
                    Id = o.Id,
                    Code = o.Code,
                    Name = o.Name,
                    Operation = "Edit"
                }).FirstOrDefault();
            }
            return(Json(roleinforole, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllTest()
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            List <TestListInfo> testlistinfo = new List <TestListInfo>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                testlistinfo = (from t in entity.Tests
                                where t.OrganizationID == orgid &&
                                t.IsPublish == false
                                select new TestListInfo
                {
                    TestId = t.Id,
                    Code = t.TestCode,
                    Name = t.TestName,
                    Selected = false
                }).ToList();
            }

            return(Json(testlistinfo, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public JsonResult DeleteTestInstruction(EPortal.Models.TestInstruction TestInstructioninfo)
        {
            int result = 0;
            //string orgid = Session["OrgId"].ToString();
            string orgid    = User.OrgId;
            string errormsg = string.Empty;
            string testid   = string.Empty;

            // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required");

            using (EPortalEntities entity = new EPortalEntities())
            {
                var gettestid = (from t in entity.TestInstructions
                                 where t.OrganizationID == orgid &&
                                 t.Id == TestInstructioninfo.Id
                                 select t).FirstOrDefault();
                if (gettestid != null)
                {
                    testid = gettestid.TestId;
                }
                var checkreferance = (from r in entity.Tests
                                      where r.OrganizationID == orgid &&
                                      r.Id == testid
                                      select r).FirstOrDefault();
                if (checkreferance != null && checkreferance.IsPublish == true)
                {
                    errormsg = "Operation conflict:Operation cannot be performed.Record already in Used.";
                }
                else
                {
                    entity.Entry(TestInstructioninfo).State = System.Data.Entity.EntityState.Deleted;
                    result = entity.SaveChanges();
                }
            }

            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetQuestionSourceInfo(EPortal.Models.Questionsource QuestionSourceinfo)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            List <QuestionTypeliSt> questiontypelist = new List <QuestionTypeliSt>();
            QuestionSourceList      QuestionSourceinfoQuestionSource = new QuestionSourceList();

            using (EPortalEntities entity = new EPortalEntities())
            {
                QuestionSourceinfoQuestionSource = (from o in entity.Questionsources

                                                    where o.Id == QuestionSourceinfo.Id &&
                                                    o.OrganizationID == orgid
                                                    select new QuestionSourceList
                {
                    Id = o.Id,
                    SourceCode = o.SourceCode,
                    SourceName = o.SourceName,
                    ResourceText = o.ResourceText,
                    QuestionTypeId = o.QuestionTypeId,
                    Operation = "Edit"
                }).FirstOrDefault();
                questiontypelist = (from qt in entity.QuestionTypes
                                    where qt.OrganizationID == orgid
                                    select new QuestionTypeliSt
                {
                    QuestionTypeId = qt.Id,
                    QuestionTypeCode = qt.TypeCode,
                    QuestionTypeName = qt.TypeName
                }).ToList();
            }
            questiontypelist.Insert(0, new QuestionTypeliSt {
                QuestionTypeId = "0", QuestionTypeCode = "Select", QuestionTypeName = "Select"
            });
            return(Json(new { sourcedata = QuestionSourceinfoQuestionSource, atypelist = questiontypelist }, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        public JsonResult GetMessageList()
        {
            List <MessageList> messagelist = new List <MessageList>();
            //string orgid = Session["OrgId"].ToString();
            //string userid = Session["UserId"].ToString();
            string orgid  = User.OrgId;
            string userid = User.UserId;

            using (EPortalEntities entity = new EPortalEntities())
            {
                messagelist = (from m in entity.UserFeedBacks
                               join p in entity.UserInfoes on m.ApplicantId equals p.Id
                               where m.OrganizationID == orgid &&
                               m.ApplicantTo == userid
                               select new MessageList
                {
                    Message = m.MessageInfo,
                    MessageDate = m.CreateDateTime,
                    MessageDatestr = "",
                    PhotoPath = "/Home/GetFile?fileid=" + p.Id,
                    ApplicantName = p.Name,
                    IsNew = false
                }).OrderByDescending(x => x.MessageDate).ToList();
                foreach (var item in messagelist)
                {
                    item.ApplicantName  = item.ApplicantName.ToUpper();
                    item.Message        = item.Message.Count() > 100 ? item.Message.Substring(0, 100) : item.Message;
                    item.MessageDatestr = (System.DateTime.Now - item.MessageDate).Days.ToString();
                    if ((System.DateTime.Now - item.MessageDate).Days < 7)
                    {
                        item.IsNew = true;
                    }
                }
                messagelist = messagelist.Where(x => x.IsNew == true).OrderBy(x => x.MessageDate).ToList();
            }
            return(Json(new { msgcount = messagelist.Count(), messagelist = messagelist.Take(5).ToList() }, JsonRequestBehavior.AllowGet));
        }
示例#6
0
        public JsonResult GetTestList()
        {
            //string orgid = Session["OrgId"].ToString();
            //string userid = Session["UserId"].ToString();

            string userid = User.UserId;
            string orgid  = User.OrgId;

            List <TestList> testlist = new List <TestList>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                testlist = (from um in entity.UserMarks
                            join t in entity.Tests on new
                {
                    orgid = um.OrganizationID,
                    testid = um.TestId
                } equals new
                {
                    orgid = t.OrganizationID,
                    testid = t.Id
                }

                            where um.ApplicantId == userid &&
                            um.OrganizationID == orgid
                            group t by new { testid = t.Id, testcode = t.TestCode, testname = t.TestName }
                            into j1
                            select new TestList
                {
                    Id = j1.Key.testid,
                    TestCode = j1.Key.testcode,
                    TestName = j1.Key.testname,
                    URl = "GetResult?testid=" + j1.Key.testid,
                }).ToList();
            }
            return(Json(testlist, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllQuestionType()
        {
            //string orgid = Session["OrgId"].ToString();

            string orgid = User.OrgId;
            List <QuestionTypeliSt> questiontypelist = new List <QuestionTypeliSt>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                questiontypelist = (from qt in entity.QuestionTypes
                                    where qt.OrganizationID == orgid
                                    select new QuestionTypeliSt
                {
                    QuestionTypeId = qt.Id,
                    QuestionTypeCode = qt.TypeCode,
                    QuestionTypeName = qt.TypeName
                }).ToList();
            }

            questiontypelist.Insert(0, new QuestionTypeliSt {
                QuestionTypeId = "0", QuestionTypeCode = "Select", QuestionTypeName = "Select"
            });
            return(Json(questiontypelist, JsonRequestBehavior.AllowGet));
        }
示例#8
0
        public JsonResult GetTestInstructionList(string searchtext)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;
            List <TestInstructionList> org = new List <TestInstructionList>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                org = (from o in entity.TestInstructions
                       join t in entity.Tests on new
                {
                    orgid = o.OrganizationID,
                    testid = o.TestId
                } equals new
                {
                    orgid = t.OrganizationID,
                    testid = t.Id
                }
                       where o.OrganizationID == orgid &&
                       ((searchtext == null || searchtext == "") ? true : (o.Code.ToLower().Contains(searchtext.ToLower()) ||
                                                                           o.Name.ToLower().Contains(searchtext.ToLower()) ||
                                                                           t.TestName.ToLower().Contains(searchtext.ToLower())
                                                                           ))
                       select new TestInstructionList
                {
                    Id = o.Id,
                    Code = o.Code,
                    Name = o.Name,
                    Operation = "Create",
                    DeleteConformation = false,
                    TestName = t.TestName,
                    IsTestPublish = t.IsPublish
                }).ToList();
            }
            return(Json(org, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetTestSectionList(string testid)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;
            List <TestSectionList> org = new List <TestSectionList>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                org = (from o in entity.TestSections
                       join p in entity.Tests on o.ParentId equals p.Id
                       where o.OrganizationID == orgid &&
                       o.ParentId == testid
                       select new TestSectionList
                {
                    Id = o.Id,
                    TestSectionCode = o.TestSectionCode,
                    TestSectionName = o.TestSectionName,
                }).ToList();
            }
            org.Insert(0, new TestSectionList {
                Id = "0", TestSectionCode = "Select", TestSectionName = "Select"
            });
            return(Json(org, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveSelectedRole(string selectedUser, string selectedrole)
        {
            //string orgid = Session["OrgId"].ToString();

            string orgid = User.OrgId;

            EPortal.Models.UserRole Userrorle = null;
            int result = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                Userrorle = (from usr in entity.UserRoles
                             where usr.OrganizationID == orgid &&
                             usr.RoleId == selectedrole &&
                             usr.UserId == selectedUser
                             select usr).FirstOrDefault();
                if (Userrorle == null)
                {
                    Userrorle                     = new UserRole();
                    Userrorle.Id                  = Guid.NewGuid().ToString();
                    Userrorle.UserId              = selectedUser;
                    Userrorle.RoleId              = selectedrole;
                    Userrorle.OrganizationID      = orgid;
                    Userrorle.RowState            = false;
                    Userrorle.CreateDateTime      = System.DateTime.Now;
                    entity.Entry(Userrorle).State = System.Data.Entity.EntityState.Added;
                }
                else
                {
                    entity.Entry(Userrorle).State = System.Data.Entity.EntityState.Modified;
                }

                result = entity.SaveChanges();
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveFeedback(UserFeedBack feedback)
        {
            int result = 0;
            //string orgid = Session["OrgId"].ToString();
            //string userid = Session["UserId"].ToString();

            string userid = User.UserId;
            string orgid  = User.OrgId;

            using (EPortalEntities entity = new EPortalEntities())
            {
                var orgadminid = (from a in entity.UserInfoes
                                  where a.OrganizationID == orgid &&
                                  a.Code == "Admin"
                                  select a.Id).FirstOrDefault();



                feedback.Id                  = Guid.NewGuid().ToString();
                feedback.OrganizationID      = orgid;
                feedback.RowState            = true;
                feedback.ApplicantId         = userid;
                feedback.CreateDateTime      = System.DateTime.Now;
                feedback.ApplicantTo         = orgadminid;
                entity.Entry(feedback).State = System.Data.Entity.EntityState.Added;
                entity.UserFeedBacks.Add(feedback);
                try
                {
                    result = entity.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetOrganizationList(string searchtext)
        {
            List <OrgList> org = new List <OrgList>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                org = (from o in entity.Organizations
                       where o.Id != "1" &&
                       ((searchtext == null || searchtext == "") ? true : (o.Code.ToLower().Contains(searchtext.ToLower()) ||
                                                                           o.Name.ToLower().Contains(searchtext.ToLower())
                                                                           ))
                       select new OrgList
                {
                    Id = o.Id,
                    Code = o.Code,
                    Name = o.Name,
                    Email = o.Email,
                    ContactNo = o.ContactNo,
                    Operation = "Create",
                    DeleteConformation = false,
                }).ToList();
            }
            return(Json(org, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetMailConfiguration()
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            MailCOnfigurationClass mailconfig = new MailCOnfigurationClass();

            using (EPortalEntities entity = new EPortalEntities())
            {
                mailconfig = (from m in entity.EMailConfigurations
                              where m.OrganizationId == orgid
                              select new MailCOnfigurationClass
                {
                    UserCreation = m.UserCreationMail,
                    TestAssign = m.TestAssignMail,
                    Login = m.AfterLoginMail,
                    ChangePassword = m.AfterChangePasswordMail,
                    ResultAfterTest = m.SendResultAfterTestMail,
                    Questionpaper = false
                }).FirstOrDefault();
            }

            return(Json(mailconfig, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AssignTestUser(string userid, string testid)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            bool   sendmailper = false;
            string usermail    = string.Empty;

            EPortal.Models.ApplicantTest apptest = null;
            int result = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                var checkuserexam = (from at in entity.ApplicantTests
                                     where at.OrganizationID == orgid &&
                                     at.ApplicantId == userid
                                     select at).ToList();
                if (checkuserexam.Count() > 0)
                {
                    foreach (var item in checkuserexam)
                    {
                        item.RowState            = false;
                        entity.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    }
                }


                apptest                     = new ApplicantTest();
                apptest.Id                  = Guid.NewGuid().ToString();
                apptest.TestId              = testid;
                apptest.ApplicantId         = userid;
                apptest.OrganizationID      = orgid;
                apptest.RowState            = true;
                apptest.CreateDateTime      = System.DateTime.Now;
                entity.Entry(apptest).State = System.Data.Entity.EntityState.Added;
                entity.ApplicantTests.Add(apptest);
                result = entity.SaveChanges();
                if (result > 0)
                {
                    var checkformail = (from mc in entity.EMailConfigurations
                                        where mc.OrganizationId == orgid
                                        select mc).FirstOrDefault();
                    if (checkformail != null)
                    {
                        if (checkformail.TestAssignMail == true)
                        {
                            sendmailper = true;
                            var getusermail = (from u in entity.UserInfoes
                                               where u.OrganizationID == orgid &&
                                               u.Id == userid
                                               select u).FirstOrDefault();
                            if (getusermail != null)
                            {
                                usermail = getusermail.Email;
                            }
                        }
                    }
                }
            }
            if (sendmailper == true && (usermail != null || usermail != ""))
            {
                string body     = "One new Test is assign to you,please check it once.";
                string heading  = "New test assign";
                bool   sendmail = homecontroller.SendMail(usermail, heading, body, null);
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
示例#15
0
        public ActionResult Login(EPortal.Models.UserInfo Userinfo)
        {
            if (Userinfo == null)
            {
                throw new ArgumentNullException(nameof(Userinfo));
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            EPortal.Models.Organization org      = null;
            EPortal.Models.UserInfo     Userdata = null;
            EPortal.Models.UserRole     Userrole = null;
            bool sendmailper = false;

            using (EPortalEntities entity = new EPortalEntities())
            {
                try
                {
                    org = (from o in entity.Organizations
                           where o.Code == Userinfo.OrganizationName
                           select o).FirstOrDefault();
                }
                catch (Exception)
                {
                }
                if (org != null)
                {
                    Userdata = (from u in entity.UserInfoes
                                where u.OrganizationID == org.Id &&
                                u.LogInId == Userinfo.LogInId &&
                                u.UserPassword == Userinfo.UserPassword
                                select u).FirstOrDefault();
                    if (Userdata != null)
                    {
                        Userrole = (from ro in entity.UserRoles
                                    where ro.OrganizationID == org.Id &&
                                    ro.UserId == Userdata.Id &&
                                    ro.RowState == true
                                    select ro).FirstOrDefault();
                    }
                    var checkformail = (from mc in entity.EMailConfigurations
                                        where mc.OrganizationId == org.Id
                                        select mc).FirstOrDefault();
                    if (checkformail != null)
                    {
                        if (checkformail.AfterLoginMail == true)
                        {
                            sendmailper = true;
                        }
                    }
                }
            }
            if (Userdata != null && Userrole != null)
            {
                CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
                //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true);

                serializeModel.OrgId = org.Id;
                //Session["OrgId"] = org.Id;

                // Session["OrgName"] = org.Name;
                serializeModel.OrgName = org.Name;

                //Session["UserId"] = Userdata.Id;
                serializeModel.UserId = Userdata.Id;

                //Session["UserName"] = Userdata.Name;
                serializeModel.UserName = Userdata.Name;

                //Session["ISApplicant"] = Userdata.IsApplicant;
                serializeModel.ISApplicant = Userdata.IsApplicant.ToString();

                if (Userrole != null)
                {
                    //Session["RoleId"] = Userrole.RoleId;
                    serializeModel.RoleId = Userrole.RoleId;
                }
                string userData = serializer.Serialize(serializeModel);
                //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true);
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                    1,
                    Userinfo.LogInId,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(15),
                    false,
                    userData.ToString(),
                    FormsAuthentication.FormsCookiePath);
                string     encTicket = FormsAuthentication.Encrypt(GetAuthTicket(GetAuthTicket1(authTicket: authTicket)));
                HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, GetEncTicket(encTicket));
                Response.Cookies.Add(cookie: faCookie);
                int cookieSize = Encoding.UTF8.GetByteCount(faCookie.Values.ToString());
                if (sendmailper == true)
                {
                    //getting client ip address
                    string ipAddress = Request.UserHostAddress.ToString();

                    //getting client browser name
                    string browserName = Request.Browser.Browser.ToString();

                    //getting client browser version



                    string body    = "Hi,Just now someone login to youe acocunt with IP:" + ipAddress + ",Browser:" + browserName + Request.Browser.Version.ToString() + ",If not you please contact us.";
                    string heading = "User login Details:";
                    if (Userdata.Email != null || Userdata.Email != "")
                    {
                        bool sendmail = SendMail(Userdata.Email, heading, body, null);
                    }
                }

                //var log = new logWriter("Login Successful for user:"******"UserHome"));
            }
            else
            {
                Session["InvalidUser"] = true;
                return(Redirect("/Home/Index"));
            }
        }
示例#16
0
        public string GetMarkup()
        {
            StringBuilder bulder = new StringBuilder();
            string        orgid  = User.OrgId;
            string        roleid = User.RoleId;
            string        Userid = User.UserId;
            //string roleid = User.
            //string Userid =
            bool isapplicant = false;

            if (User.ISApplicant != null && User.ISApplicant != "")
            {
                isapplicant = true;
            }
            using (EPortalEntities entity = new EPortalEntities())
            {
                var data = (from p in entity.Previleages
                            join u in entity.UserRoles on new
                {
                    roleid = p.RoleId,
                    Userid = Userid
                }
                            equals new
                {
                    roleid = u.RoleId,
                    Userid = u.UserId
                }
                            join mp in entity.ModulePages on p.PageId equals mp.PageId
                            join m in entity.Modules on mp.ModuleId equals m.Id
                            join pa in entity.Pages on p.PageId equals pa.Id
                            join orgp in entity.OrganizationPages on new
                {
                    pageid = p.PageId,
                    Orgid = p.OrganizationID
                } equals new
                {
                    pageid = orgp.PageId,
                    Orgid = orgp.OrganizationID
                }
                            where p.OrganizationID == orgid &&
                            p.RoleId == roleid &&
                            p.RowState == true &&
                            u.UserId == Userid &&
                            (isapplicant == false ? true : pa.ForAdmin == false) &&
                            (orgid == "1" ? true : (p.PCreate == true || p.PUpdate == true || p.PDelete == true || p.PView == true))
                            //group m by new { }into g
                            select new
                {
                    ModuleName = m.Name,
                    MOduleCode = m.Code,
                    ModuleId = m.Id,
                    ModuleSequence = m.SequenceNo,
                    PageId = pa.Id,
                    PageName = pa.Name,
                    PageCode = pa.Code,
                    pagesequence = pa.SequenceNo
                }).ToList();

                var data1 = (from p in data
                             group p by new { ModuleName = p.ModuleName, ModuleSequence = p.ModuleSequence, ModuleId = p.ModuleId, ModuleCode = p.MOduleCode } into g1
                             select new
                {
                    ModuleName = g1.Key.ModuleName,
                    ModuleId = g1.Key.ModuleId,
                    ModuleCode = g1.Key.ModuleCode,
                    ModuleSequence = g1.Key.ModuleSequence,
                    PageList = (from pa in data
                                where pa.ModuleId == g1.Key.ModuleId
                                select new
                    {
                        PageId = pa.PageId,
                        PageName = pa.PageName,
                        PageCode = pa.PageCode,
                        pagesequence = pa.pagesequence
                    }).OrderBy(x => x.pagesequence).ToList()
                }).OrderBy(x => x.ModuleSequence).ToList();



                #region New Nav
                //foreach (var item in data1)
                //{
                //    bulder.AppendFormat("<md-subheader class='md-no-sticky' style='height: 54px;'>{0}</md-subheader>", item.ModuleName);
                //    foreach (var pageitem in item.PageList)
                //    {
                //        bulder.AppendFormat("<md-list-item class='pagecolor margindownpage' ng-href='{0}'>", "/" + pageitem.PageCode + "/Index");
                //        bulder.AppendFormat("<p>{0}</p>", pageitem.PageName);
                //        bulder.Append("</md-list-item>");
                //    }
                //}

                #endregion


                #region New Navigation
                foreach (var item in data1)
                {
                    bulder.Append("<li>");
                    bulder.AppendFormat("<a><i class='fa fa-home'></i>{0}<span class='fa fa-chevron-down'></span></a>", item.ModuleName);
                    bulder.Append("<ul class='nav child_menu'>");
                    foreach (var pageitem in item.PageList)
                    {
                        bulder.AppendFormat("<li><a href='{0}'>{1}</a></li>", "/" + pageitem.PageCode + "/Index", pageitem.PageName);
                    }
                    bulder.Append("</ul>");
                    bulder.Append("</li>");
                }
                #endregion



                //#region New Navigation
                //foreach (var item in data1)
                //{
                //    bulder.Append("<li style='background-color:#009688;margin-bottom:1%;'>");
                //    bulder.AppendFormat("<div class='link' style='color: white;' id='clickeassessment'><i class='fa fa-database'></i>{0}<i class='fa fa-chevron-down'></i></div>", item.ModuleName);
                //    bulder.Append("<ul class='submenu'>");
                //    foreach (var pageitem in item.PageList)
                //    {
                //        bulder.AppendFormat("<li><a href='{0}'>{1}</a></li>", "/" + pageitem.PageCode + "/Index", pageitem.PageName);
                //    }
                //    bulder.Append("</ul>");
                //    bulder.Append("</li>");
                //}
                //#endregion

                return(bulder.ToString());
            }
        }
示例#17
0
        public JsonResult GetResult(string testid)
        {
            //string orgid = Session["OrgId"].ToString();
            //string userid = Session["UserId"].ToString();

            string userid = User.UserId;
            string orgid  = User.OrgId;

            //string OrgaName = Session["OrgName"].ToString();
            //string userName = Session["UserName"].ToString();

            string OrgaName = User.OrgName;
            string userName = User.UserName;

            List <UserReportCLass> useranslist = null;
            string    testname  = string.Empty;
            OrgDateil orgdetail = new OrgDateil();

            using (EPortalEntities entity = new EPortalEntities())
            {
                testname = (from t in entity.Tests
                            where t.OrganizationID == orgid &&
                            t.Id == testid
                            select t.TestName).FirstOrDefault();

                orgdetail = (from o in entity.Organizations
                             where o.Id == orgid
                             select new OrgDateil
                {
                    OrgaName = o.Name,
                    OrgaAddress = o.Address,
                    OrgaPin = o.Pin,
                    OrgaCountry = o.Country,
                    OrgaEst = o.ESTDate,
                    OrgaState = o.OrgState,
                    OrgLogo = "/Home/GetOrgLogo?orgid=" + o.Id
                }).FirstOrDefault();
                orgdetail.OrgaEststr = orgdetail.OrgaEst.HasValue?orgdetail.OrgaEst.Value.ToShortDateString():"";

                if (testname != null)
                {
                    useranslist = (from um in entity.UserMarks
                                   join s in entity.TestSections
                                   on new
                    {
                        orgid = um.OrganizationID,
                        testid = um.TestId,
                        sectionid = um.TestSectionId
                    } equals new
                    {
                        orgid = s.OrganizationID,
                        testid = s.ParentId,
                        sectionid = s.Id
                    }
                                   where um.OrganizationID == orgid &&
                                   um.TestId == testid &&
                                   um.ApplicantId == userid
                                   select new UserReportCLass
                    {
                        TestSectionId = um.TestSectionId,
                        TestSectionName = s.TestSectionName,
                        TestSectionMarkStr = um.Mark,
                        TestName = testname,
                        ApplicantName = userName
                    }).ToList();
                }
            }
            useranslist.Add(new UserReportCLass {
                TestSectionId = "Total", TestSectionName = "Total", TestSectionMarkStr = useranslist.Sum(x => Convert.ToDecimal(x.TestSectionMarkStr)).ToString()
            });
            //StringBuilder markup = PreparedMarkupforPDF(useranslist, testname);
            //ConvertHtmlToPdf(markup, testname);
            return(Json(new { useranslist = useranslist, orgdetail = orgdetail }, JsonRequestBehavior.AllowGet));
        }
示例#18
0
        public JsonResult fileUpload(HttpPostedFileBase filedata)
        {
            EPortal.Models.Previleage        Previleageforadmin     = null;
            EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
            List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
            List <EPortal.Models.Page>       getPage = new List <Page>();


            string errormsg      = string.Empty;
            int    resultforsave = 0;
            var    data          = Request.Files[0];
            bool   fileerror     = false;

            if (!Request.Files[0].ContentType.Contains("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
            {
                errormsg  = "Please select Excel file only.";
                fileerror = true;
            }
            if (fileerror == false)
            {
                #region Excel FIle upload
                //string orgid = Session["OrgId"].ToString();

                string orgid = User.OrgId;

                string path = string.Empty;
                //FileStream stream = new FileStream(data.FileName, FileMode.Open, FileAccess.Read);
                Excel.IExcelDataReader excelReader;
                excelReader = Excel.ExcelReaderFactory.CreateOpenXmlReader(data.InputStream);
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet result = excelReader.AsDataSet();
                List <EPortal.Models.UserInfo> useinfolist = new List <UserInfo>();
                EPortal.Models.UserInfo        useinfo     = null;

                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (result.Tables.Count > 0)
                    {
                        foreach (var item in result.Tables[0].Rows)
                        {
                            string loginid = ((System.Data.DataRow)item).ItemArray[2].ToString();
                            string code    = ((System.Data.DataRow)item).ItemArray[0].ToString();

                            var checkexist = (from u in entity.UserInfoes
                                              where u.OrganizationID == orgid &&
                                              (u.LogInId == loginid || u.Code == code)
                                              select u).ToList();
                            if (checkexist.Count() > 0)
                            {
                                errormsg = "One or more User already exist with same Details.";
                                break;
                            }
                            if (!EmailValidate(((System.Data.DataRow)item).ItemArray[4].ToString()))
                            {
                                errormsg = "One or more User have invalid emailid.";
                                break;
                            }
                            if (errormsg == "")
                            {
                                useinfo         = new UserInfo();
                                useinfo.Id      = Guid.NewGuid().ToString();
                                useinfo.Code    = ((System.Data.DataRow)item).ItemArray[0].ToString();
                                useinfo.Name    = ((System.Data.DataRow)item).ItemArray[1].ToString();
                                useinfo.LogInId = loginid;
                                DateTime password = Convert.ToDateTime(((System.Data.DataRow)item).ItemArray[3].ToString());
                                useinfo.UserPassword   = loginid;
                                useinfo.DateOfBirth    = Convert.ToDateTime(((System.Data.DataRow)item).ItemArray[3].ToString());
                                useinfo.OrganizationID = orgid;
                                useinfo.RowState       = true;
                                useinfo.CreateDateTime = System.DateTime.Now;
                                useinfo.Email          = ((System.Data.DataRow)item).ItemArray[4].ToString();
                                useinfo.IsApplicant    = Convert.ToBoolean(Convert.ToInt16(((System.Data.DataRow)item).ItemArray[5].ToString()));
                                useinfo.MobileNo       = null;
                                useinfo.PhotoPath      = null;
                                useinfo.NoOfLogin      = null;



                                if (Convert.ToBoolean(Convert.ToInt16(((System.Data.DataRow)item).ItemArray[5].ToString())))
                                {
                                    useinfo.UserType = "40";
                                    #region For Applicant
                                    var roleid = (from r in entity.RoleMasters
                                                  where r.OrganizationID == orgid &&
                                                  r.Code == "Applicant"
                                                  select r).FirstOrDefault();

                                    Userroleforadmin                = new UserRole();
                                    Userroleforadmin.Id             = Guid.NewGuid().ToString();
                                    Userroleforadmin.UserId         = useinfo.Id;
                                    Userroleforadmin.RoleId         = roleid.Id;
                                    Userroleforadmin.OrganizationID = orgid;
                                    Userroleforadmin.RowState       = true;
                                    Userroleforadmin.CreateDateTime = System.DateTime.Now;
                                    entity.UserRoles.Add(Userroleforadmin);


                                    var checkroleexist = (from r in entity.Previleages
                                                          where r.OrganizationID == orgid &&
                                                          r.RoleId == roleid.Id
                                                          select r).ToList();

                                    if (checkroleexist.Count() == 0)
                                    {
                                        #region Get All Page
                                        getPage = (from p in entity.Pages
                                                   where p.Code != "Organization" &&
                                                   p.ForAdmin == false
                                                   select p).ToList();
                                        if (getPage.Count() > 0)
                                        {
                                            foreach (Page itemp in getPage)
                                            {
                                                Previleageforadmin                = new Previleage();
                                                Previleageforadmin.Id             = Guid.NewGuid().ToString();
                                                Previleageforadmin.RoleId         = roleid.Id;
                                                Previleageforadmin.PageId         = itemp.Id;
                                                Previleageforadmin.OperationId    = string.Empty;
                                                Previleageforadmin.PCreate        = true;
                                                Previleageforadmin.PUpdate        = true;
                                                Previleageforadmin.PDelete        = true;
                                                Previleageforadmin.PView          = true;
                                                Previleageforadmin.OrganizationID = orgid;
                                                Previleageforadmin.RowState       = true;
                                                Previleageforadmin.CreateDateTime = System.DateTime.Now;
                                                Previleageforadminlist.Add(Previleageforadmin);
                                            }
                                        }
                                        #endregion

                                        foreach (Previleage itempre in Previleageforadminlist)
                                        {
                                            entity.Entry(itempre).State = System.Data.Entity.EntityState.Added;
                                            entity.Previleages.Add(itempre);
                                        }
                                    }
                                    #endregion
                                }
                                entity.Entry(useinfo).State = System.Data.Entity.EntityState.Added;
                                entity.UserInfoes.Add(useinfo);
                            }
                        }
                    }
                    else
                    {
                        errormsg = "Selected file is empty.No Data found.";
                    }

                    if (errormsg == string.Empty)
                    {
                        try
                        {
                            resultforsave = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                #endregion
            }
            return(Json(new { result = resultforsave > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
示例#19
0
        public JsonResult SaveUser(EPortal.Models.UserInfo UserInfo)
        {
            string errormsg = "";
            int    result   = 0;
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;



            #region Operation save

            EPortal.Models.Previleage        Previleageforadmin     = null;
            EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
            List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
            List <EPortal.Models.Page>       getPage = new List <Page>();



            using (EPortalEntities entity = new EPortalEntities())
            {
                if (UserInfo.Operation == "Create")
                {
                    var checkforloginid = (from u in entity.UserInfoes
                                           where u.OrganizationID == orgid &&
                                           (u.LogInId == UserInfo.LogInId || u.Code == UserInfo.Code)
                                           select u).FirstOrDefault();
                    if (checkforloginid == null)
                    {
                        UserInfo.Id             = Guid.NewGuid().ToString();
                        UserInfo.OrganizationID = orgid;
                        UserInfo.RowState       = true;
                        UserInfo.CreateDateTime = System.DateTime.Now;
                        // string password = UserInfo.DateOfBirth.Value.Day + "-" + UserInfo.DateOfBirth.Value.Month + "-" + UserInfo.DateOfBirth.Value.Year;
                        UserInfo.UserPassword = UserInfo.LogInId;
                        UserInfo.IsApplicant  = UserInfo.IsApplicant;
                        UserInfo.MobileNo     = null;
                        if (UserInfo.Email == null || UserInfo.Email == "")
                        {
                            UserInfo.Email = null;
                        }
                        else
                        {
                            UserInfo.Email = UserInfo.Email;
                        }

                        UserInfo.PhotoPath           = null;
                        UserInfo.NoOfLogin           = null;
                        UserInfo.UserType            = "40";
                        entity.Entry(UserInfo).State = System.Data.Entity.EntityState.Added;
                        entity.UserInfoes.Add(UserInfo);

                        if (UserInfo.IsApplicant == true)
                        {
                            try
                            {
                                #region For Applicant
                                var roleid = (from r in entity.RoleMasters
                                              where r.OrganizationID == orgid &&
                                              r.Code == "Applicant"
                                              select r).FirstOrDefault();

                                Userroleforadmin                = new UserRole();
                                Userroleforadmin.Id             = Guid.NewGuid().ToString();
                                Userroleforadmin.UserId         = UserInfo.Id;
                                Userroleforadmin.RoleId         = roleid.Id;
                                Userroleforadmin.OrganizationID = orgid;
                                Userroleforadmin.RowState       = true;
                                Userroleforadmin.CreateDateTime = System.DateTime.Now;
                                entity.UserRoles.Add(Userroleforadmin);


                                var checkroleexist = (from r in entity.Previleages
                                                      where r.OrganizationID == orgid &&
                                                      r.RoleId == roleid.Id
                                                      select r).ToList();

                                if (checkroleexist.Count() == 0)
                                {
                                    #region Get All Page

                                    var getorgpage = (from p in entity.OrganizationPages
                                                      where p.OrganizationID == orgid
                                                      select p).ToList();

                                    getPage = (from p in entity.Pages
                                               where p.Code != "Organization" &&
                                               p.ForAdmin == false
                                               select p).ToList();
                                    if (getPage.Count() > 0)
                                    {
                                        foreach (var item in getorgpage)
                                        {
                                            Previleageforadmin                = new Previleage();
                                            Previleageforadmin.Id             = Guid.NewGuid().ToString();
                                            Previleageforadmin.RoleId         = roleid.Id;
                                            Previleageforadmin.PageId         = item.PageId;
                                            Previleageforadmin.OperationId    = string.Empty;
                                            Previleageforadmin.PCreate        = true;
                                            Previleageforadmin.PUpdate        = true;
                                            Previleageforadmin.PDelete        = true;
                                            Previleageforadmin.PView          = true;
                                            Previleageforadmin.OrganizationID = orgid;
                                            Previleageforadmin.RowState       = true;
                                            Previleageforadmin.CreateDateTime = System.DateTime.Now;
                                            Previleageforadminlist.Add(Previleageforadmin);
                                        }
                                    }
                                    #endregion

                                    foreach (Previleage item in Previleageforadminlist)
                                    {
                                        entity.Entry(item).State = System.Data.Entity.EntityState.Added;
                                        entity.Previleages.Add(item);
                                    }
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                errormsg = ex.Message;
                            }
                        }
                    }
                    else
                    {
                        errormsg = "User already exist with same details.";
                    }
                    try
                    {
                        if (errormsg == "")
                        {
                            result = entity.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        errormsg = ex.Message;
                    }
                }
                else
                {
                    EPortal.Models.UserInfo usedata = (from o in entity.UserInfoes
                                                       where o.OrganizationID == orgid &&
                                                       o.Id == UserInfo.Id
                                                       select o
                                                       ).FirstOrDefault();
                    usedata.Code                = UserInfo.Code;
                    usedata.Name                = UserInfo.Name;
                    usedata.LogInId             = UserInfo.LogInId;
                    usedata.IsApplicant         = UserInfo.IsApplicant;
                    usedata.MobileNo            = UserInfo.MobileNo;
                    usedata.Email               = UserInfo.Email;
                    entity.Entry(usedata).State = System.Data.Entity.EntityState.Modified;
                    try
                    {
                        result = entity.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        errormsg = ex.Message;
                    }
                }
            }
            #endregion


            #region Send Mail
            if (UserInfo.Operation == "Create" && (UserInfo.Email != null || UserInfo.Email != ""))
            {
                bool sendmailper = false;
                using (EPortalEntities entity = new EPortalEntities())
                {
                    var checkformail = (from mc in entity.EMailConfigurations
                                        where mc.OrganizationId == orgid
                                        select mc).FirstOrDefault();
                    if (checkformail != null)
                    {
                        if (checkformail.UserCreationMail == true)
                        {
                            sendmailper = true;
                        }
                    }
                }
                if (sendmailper == true)
                {
                    string body     = "please find your UserName and Password below for E-Assessment.in ,UserName:"******" and Password :"******"";
                    string heading  = "Applicant " + UserInfo.Name + " created";
                    bool   sendmail = homecontroller.SendMail(UserInfo.Email, heading, body, null);
                }
            }
            #endregion


            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg, id = UserInfo.Id }, JsonRequestBehavior.AllowGet));
        }
示例#20
0
        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));
        }
        public JsonResult GetGroupQuestionList(string questiontypeid, string testid, string testsectionid)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;
            List <GroupQuestionlist> questionlist = new List <GroupQuestionlist>();
            int noofgroupquestion = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                questionlist = (from qs in entity.Questionsources
                                where qs.OrganizationID == orgid &&
                                qs.QuestionTypeId == questiontypeid
                                select new GroupQuestionlist
                {
                    Id = qs.Id,
                    QuestionText = qs.ResourceText,
                    Selected = (from q in entity.QuestionsourceGroups
                                join tq in entity.TestQuestions
                                on new
                    {
                        orgid = q.OrganizationID,
                        testid = testid,
                        testsectionid = testsectionid,
                        questionid = q.QuestionId,
                    } equals new
                    {
                        orgid = tq.OrganizationID,
                        testid = tq.TestId,
                        testsectionid = tq.TestSectionId,
                        questionid = tq.QuestionId
                    }
                                where q.OrganizationID == orgid &&
                                q.QuestionSourceId == qs.Id
                                select q.Id).FirstOrDefault() == null ? false : true,
                    Operation = (from q in entity.QuestionsourceGroups
                                 join tq in entity.TestQuestions
                                 on new
                    {
                        orgid = q.OrganizationID,
                        testid = testid,
                        testsectionid = testsectionid,
                        questionid = q.QuestionId,
                    } equals new
                    {
                        orgid = tq.OrganizationID,
                        testid = tq.TestId,
                        testsectionid = tq.TestSectionId,
                        questionid = tq.QuestionId
                    }
                                 where q.OrganizationID == orgid &&
                                 q.QuestionSourceId == qs.Id
                                 select q.Id).FirstOrDefault() == null ? "Create" : "Edit",
                    CreatDate = qs.CreateDateTime,
                    NoOfQuestion = (from noofq in entity.QuestionsourceGroups
                                    where noofq.OrganizationID == orgid &&
                                    noofq.QuestionSourceId == qs.Id
                                    select noofq).Count()
                }).OrderBy(x => x.CreatDate).ToList();

                noofgroupquestion = questionlist.Where(x => x.Selected == true).Sum(x => x.NoOfQuestion);
            }
            return(Json(new { questionlist = questionlist, noofgroupquestion = noofgroupquestion }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SendMailQA(UserTypeUserList selectedUser)
        {
            bool sendmail = false;
            //string orgid = Session["OrgId"].ToString();

            string orgid = User.OrgId;

            //string userid = Session["UserId"].ToString();
            string usermailid = string.Empty;
            List <TestApplyQuestionList> question          = null;
            List <TotalQuestionList>     totalnoofquestion = new List <TotalQuestionList>();
            int           result   = 0;
            string        errmsg   = string.Empty;
            string        testname = string.Empty;
            List <byte[]> pdfname  = new List <byte[]>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                var getusertest = (from ut in entity.ApplicantTests
                                   where ut.OrganizationID == orgid &&
                                   ut.ApplicantId == selectedUser.Id
                                   select ut).ToList();
                if (getusertest.Count() > 0)
                {
                    foreach (var item in getusertest)
                    {
                        testname = (from t in entity.Tests
                                    where t.OrganizationID == orgid &&
                                    t.Id == item.TestId
                                    select t.TestName).FirstOrDefault();

                        #region Get All question And Answer

                        question = (from tq in entity.TestQuestions
                                    join q in entity.Questions
                                    on new
                        {
                            orgid = tq.OrganizationID,
                            Questid = tq.QuestionId
                        } equals new
                        {
                            orgid = q.OrganizationID,
                            Questid = q.Id
                        }
                                    join qs in entity.Questionsources
                                    on new
                        {
                            orgid = q.OrganizationID,
                            questionsource = q.SourceId
                        } equals new
                        {
                            orgid = qs.OrganizationID,
                            questionsource = qs.Id
                        } into j1
                                    from qs in j1.DefaultIfEmpty()
                                    where tq.OrganizationID == orgid &&
                                    tq.TestId == item.TestId
                                    select new TestApplyQuestionList
                        {
                            QuestionId = tq.QuestionId,
                            QuestionText = q.Question1,
                            SourceText = qs != null ? qs.ResourceText : "",
                            QuestionNo = tq.SequenceNo,
                            TestQuestionoptionList = (from qo in entity.QuestionOptions
                                                      join an in entity.QuestionAnswars
                                                      on new
                            {
                                orgid = qo.OrganizationID,
                                questionid = tq.QuestionId,
                                optionid = qo.Id
                            }
                                                      equals new
                            {
                                orgid = an.OrganizationID,
                                questionid = an.QuestionId,
                                optionid = an.QuestionAnswarId
                            }
                                                      into j2
                                                      from an in j2.DefaultIfEmpty()
                                                      where qo.OrganizationID == orgid &&
                                                      qo.QuestionId == tq.QuestionId
                                                      select new TestQuestionoptionList
                            {
                                OptionId = qo.Id,
                                OptionText = qo.QuestionOption1,
                                QuestionAns = an == null ? false : true,
                                Selected = (from useran in entity.UserAnswers
                                            where useran.OrganizationID == orgid &&
                                            useran.TestId == item.TestId &&
                                            useran.QuestionId == tq.QuestionId &&
                                            useran.optionId == qo.Id &&
                                            useran.ApplicantId == selectedUser.Id
                                            select useran).FirstOrDefault() == null ? false : true
                            }).ToList(),
                        }).ToList();

                        #endregion

                        StringBuilder markup = PreparedMarkupforPDF(question, testname);
                        pdfname.Add(ConvertHtmlToPdf(markup, testname, selectedUser.Id));
                    }
                }
                else
                {
                    errmsg = "User don't have any test.";
                }
            }
            if (errmsg == string.Empty)
            {
                string body    = "Please find the attached file regarding user's Test Question and Answer.";
                string heading = "Test " + testname + " Question and Answer";
                sendmail = homecontroller.SendMail(selectedUser.Email, heading, body, pdfname);
            }
            return(Json(new { sendmail = sendmail, errmsg = errmsg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveAcYearConfiguration(string[] selecteddata, string acyearid)
        {
            string orgid  = User.OrgId;
            int    result = 0;

            EPortal.Models.AcademicYearCourse                    course                    = null;
            EPortal.Models.AcademicYearCourseClass               courseclass               = null;
            EPortal.Models.AcademicYearCourseClassSection        courseclasssection        = null;
            EPortal.Models.AcademicYearCourseClassSectionSubject courseclasssectionsubject = null;
            using (EPortalEntities entity = new EPortalEntities())
            {
                foreach (var item in selecteddata)
                {
                    string courseid  = item.Split('_')[0].ToString();
                    string classid   = item.Split('_')[1].ToString();
                    string sectionid = item.Split('_')[2].ToString();
                    string subjectid = item.Split('_')[3].ToString();

                    #region AcYearCourse Save
                    course                     = new AcademicYearCourse();
                    course.Id                  = Guid.NewGuid().ToString();
                    course.CourseId            = courseid;
                    course.OrganizationID      = orgid;
                    course.AcademicYearId      = acyearid;
                    course.Code                = "";
                    course.Name                = "";
                    course.Name                = "";
                    course.RowState            = true;
                    course.CreateDateTime      = DateTime.Now;
                    entity.Entry(course).State = System.Data.Entity.EntityState.Added;
                    #endregion

                    #region AcYearCourseclass Save


                    courseclass                     = new AcademicYearCourseClass();
                    courseclass.Id                  = Guid.NewGuid().ToString();
                    courseclass.Code                = "";
                    courseclass.Name                = "";
                    courseclass.CourseId            = courseid;
                    courseclass.ClassID             = classid;
                    courseclass.OrganizationID      = orgid;
                    courseclass.AcademicYearId      = acyearid;
                    courseclass.RowState            = true;
                    courseclass.CreateDateTime      = DateTime.Now;
                    entity.Entry(courseclass).State = System.Data.Entity.EntityState.Added;


                    #endregion

                    #region AcYearCourseClassSection

                    courseclasssection                     = new AcademicYearCourseClassSection();
                    courseclasssection.Id                  = Guid.NewGuid().ToString();
                    courseclasssection.Code                = "";
                    courseclasssection.Name                = "";
                    courseclasssection.CourseId            = courseid;
                    courseclasssection.ClassID             = classid;
                    courseclasssection.SectionId           = sectionid;
                    courseclasssection.OrganizationID      = orgid;
                    courseclasssection.AcademicYearId      = acyearid;
                    courseclasssection.RowState            = true;
                    courseclasssection.CreateDateTime      = DateTime.Now;
                    entity.Entry(courseclasssection).State = System.Data.Entity.EntityState.Added;

                    #endregion

                    #region AcYearCourseClassSectionSubject

                    courseclasssectionsubject                     = new AcademicYearCourseClassSectionSubject();
                    courseclasssectionsubject.Id                  = Guid.NewGuid().ToString();
                    courseclasssectionsubject.Code                = "";
                    courseclasssectionsubject.Name                = "";
                    courseclasssectionsubject.OrganizationID      = orgid;
                    courseclasssectionsubject.CourseId            = courseid;
                    courseclasssectionsubject.ClassID             = classid;
                    courseclasssectionsubject.SectionId           = sectionid;
                    courseclasssectionsubject.SubjectId           = subjectid;
                    courseclasssectionsubject.AcademicYearId      = acyearid;
                    courseclasssectionsubject.RowState            = true;
                    courseclasssectionsubject.CreateDateTime      = DateTime.Now;
                    entity.Entry(courseclasssectionsubject).State = System.Data.Entity.EntityState.Added;


                    #endregion
                }

                try
                {
                    result = entity.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }


            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveTestQuestion(List <UniqueQuestionIds> usniids, List <GroupQuestionIds> groupid, string testid, string testsection)
        {
            //string orgid = Session["OrgId"].ToString();
            string orgid  = User.OrgId;
            int    result = 0;

            EPortal.Models.TestQuestion testquestion = null;
            List <EPortal.Models.QuestionsourceGroup> questiongroupsou = null;

            using (EPortalEntities entity = new EPortalEntities())
            {
                int itera = 0;
                int count = 1;
                if (usniids != null)
                {
                    #region Unique
                    foreach (var item in usniids)
                    {
                        if (itera == 0)
                        {
                            var totalquestion = (from tq in entity.TestQuestions
                                                 where tq.OrganizationID == orgid &&
                                                 tq.TestId == testid
                                                 //&& tq.TestSectionId == testsection
                                                 select tq).ToList();
                            if (totalquestion.Count() > 0)
                            {
                                count = totalquestion.Max(x => x.SequenceNo.Value) + 1;
                            }
                            itera = 1;
                        }
                        var checkexist = (from tq in entity.TestQuestions
                                          where tq.OrganizationID == orgid &&
                                          tq.TestId == testid &&
                                          tq.TestSectionId == testsection &&
                                          tq.QuestionId == item.Id
                                          select tq).FirstOrDefault();
                        if (checkexist == null)
                        {
                            testquestion                     = new TestQuestion();
                            testquestion.Id                  = Guid.NewGuid().ToString();
                            testquestion.TestId              = testid;
                            testquestion.TestSectionId       = testsection;
                            testquestion.QuestionId          = item.Id;
                            testquestion.SequenceNo          = count;
                            testquestion.OrganizationID      = orgid;
                            testquestion.RowState            = true;
                            testquestion.CreateDateTime      = System.DateTime.Now;
                            entity.Entry(testquestion).State = System.Data.Entity.EntityState.Added;
                            entity.TestQuestions.Add(testquestion);
                            count = count + 1;
                        }
                        else
                        {
                            entity.Entry(checkexist).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    #endregion
                }
                if (groupid != null)
                {
                    #region Group Question
                    foreach (var item in groupid)
                    {
                        if (usniids == null)
                        {
                            var totalquestion = (from tq in entity.TestQuestions
                                                 where tq.OrganizationID == orgid &&
                                                 tq.TestId == testid
                                                 //&& tq.TestSectionId == testsection
                                                 select tq).ToList();
                            if (totalquestion.Count() > 0)
                            {
                                count = totalquestion.Max(x => x.SequenceNo.Value);
                            }
                        }
                        questiongroupsou = (from gqs in entity.QuestionsourceGroups
                                            where gqs.OrganizationID == orgid &&
                                            gqs.QuestionSourceId == item.Id
                                            select gqs).ToList();
                        if (questiongroupsou.Count() > 0)
                        {
                            foreach (var questionsource in questiongroupsou)
                            {
                                var checkexist = (from tq in entity.TestQuestions
                                                  where tq.OrganizationID == orgid &&
                                                  tq.TestId == testid &&
                                                  tq.TestSectionId == testid &&
                                                  tq.QuestionId == questionsource.QuestionId
                                                  select tq).FirstOrDefault();

                                if (checkexist == null)
                                {
                                    testquestion                     = new TestQuestion();
                                    testquestion.Id                  = Guid.NewGuid().ToString();
                                    testquestion.TestId              = testid;
                                    testquestion.TestSectionId       = testsection;
                                    testquestion.QuestionId          = questionsource.QuestionId;
                                    testquestion.SequenceNo          = count;
                                    testquestion.OrganizationID      = orgid;
                                    testquestion.RowState            = true;
                                    testquestion.CreateDateTime      = System.DateTime.Now;
                                    entity.Entry(testquestion).State = System.Data.Entity.EntityState.Added;
                                    entity.TestQuestions.Add(testquestion);
                                    count = count + 1;
                                }
                                else
                                {
                                    entity.Entry(checkexist).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }
                    }
                    #endregion
                }
                result = entity.SaveChanges();
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetprivilegeInfo(EPortal.Models.Organization org)
        {
            string orgid = org.Id;
            List <OrganizationPageList> organpagelist = new List <OrganizationPageList>();
            List <ModuleNameList>       listmodule    = new List <ModuleNameList>();

            using (EPortalEntities entity = new EPortalEntities())
            {
                organpagelist = (from m in entity.Modules
                                 join mp in entity.ModulePages on m.Id equals mp.ModuleId
                                 join p in entity.Pages on mp.PageId equals p.Id
                                 join op in entity.OrganizationPages on new
                {
                    Orgid = orgid,
                    pageid = p.Id
                }
                                 equals new
                {
                    Orgid = op.OrganizationID,
                    pageid = op.PageId
                } into j1
                                 from op in j1.DefaultIfEmpty()
                                 where m.SequenceNo != null
                                 select new OrganizationPageList
                {
                    ModuleidId = m.Id,
                    ModuleCode = m.Code,
                    ModuleName = m.Name,
                    moduleseq = m.SequenceNo,
                    PageId = p.Id,
                    PageCode = p.Code,
                    pageName = p.Name,
                    pageseq = p.SequenceNo,
                    PageSelected = op == null ? false : true
                }).ToList();

                if (organpagelist.Count() > 0)
                {
                    listmodule = (from m in organpagelist
                                  group m by new { sequ = m.moduleseq, moduleid = m.ModuleidId, modulecode = m.ModuleCode, modulename = m.ModuleName }
                                  into j1
                                  select new ModuleNameList
                    {
                        Id = j1.Key.moduleid,
                        Code = j1.Key.modulecode,
                        Name = j1.Key.modulename,
                        SequenceNo = j1.Key.sequ,
                        modulepagelist = (from pa in organpagelist
                                          where pa.ModuleidId == j1.Key.moduleid
                                          select new ModulePagelist
                        {
                            Id = pa.PageId,
                            Code = pa.PageCode,
                            Name = pa.pageName,
                            SequenceNo = pa.pageseq,
                            Create = pa.PageSelected
                        }).OrderBy(x => x.SequenceNo).ToList()
                    }).OrderBy(x => x.SequenceNo).ToList();
                }
            }
            return(Json(listmodule, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveQuestionType(EPortal.Models.QuestionType QuestionTypeInfo)
        {
            string errormsg = "";
            int    result   = 0;

            //if ((QuestionTypeInfo.TypeCode != "" || QuestionTypeInfo.TypeCode != null) && (QuestionTypeInfo.TypeName != "" || QuestionTypeInfo.TypeName != null))
            {
                //string orgid = Session["OrgId"].ToString();
                string orgid = User.OrgId;

                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (QuestionTypeInfo.Operation == "Create")
                    {
                        var checkquestiontype = (from qt in entity.QuestionTypes
                                                 where qt.OrganizationID == orgid &&
                                                 qt.TypeCode == QuestionTypeInfo.TypeCode
                                                 select qt).FirstOrDefault();
                        if (checkquestiontype == null)
                        {
                            QuestionTypeInfo.Id                  = Guid.NewGuid().ToString();
                            QuestionTypeInfo.OrganizationID      = orgid;
                            QuestionTypeInfo.RowState            = true;
                            QuestionTypeInfo.CreateDateTime      = System.DateTime.Now;
                            entity.Entry(QuestionTypeInfo).State = System.Data.Entity.EntityState.Added;
                            entity.QuestionTypes.Add(QuestionTypeInfo);

                            try
                            {
                                result = entity.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                            errormsg = "Question Type already exist with same Code.";
                        }
                    }
                    else
                    {
                        EPortal.Models.QuestionType usedata = (from o in entity.QuestionTypes
                                                               where o.OrganizationID == orgid &&
                                                               o.Id == QuestionTypeInfo.Id
                                                               select o
                                                               ).FirstOrDefault();
                        usedata.TypeCode            = QuestionTypeInfo.TypeCode;
                        usedata.TypeName            = QuestionTypeInfo.TypeName;
                        entity.Entry(usedata).State = System.Data.Entity.EntityState.Modified;
                        try
                        {
                            result = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            //else
            //{
            //    if (QuestionTypeInfo.TypeCode != "" || QuestionTypeInfo.TypeCode != null)
            //    {
            //        errormsg = "Please enter TypeCode.";
            //    }
            //    if (QuestionTypeInfo.TypeName != "" || QuestionTypeInfo.TypeName != null)
            //    {
            //        errormsg = "Please enter Name.";
            //    }
            //}

            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
示例#27
0
        public JsonResult SaveTestInstruction(EPortal.Models.TestInstruction TestInstructionInfo, string sourcetestinfo)
        {
            string errormsg = "";
            int    result   = 0;

            //if ((TestInstructionInfo.Code != "" || TestInstructionInfo.Code != null) && (TestInstructionInfo.Name != "" || TestInstructionInfo.Name != null))
            {
                //string orgid = Session["OrgId"].ToString();
                string orgid = User.OrgId;
                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (TestInstructionInfo.Operation == "Create")
                    {
                        var checkdub = (from qi in entity.TestInstructions
                                        where qi.OrganizationID == orgid &&
                                        qi.TestId == TestInstructionInfo.TestId &&
                                        qi.Code == TestInstructionInfo.Code
                                        select qi).FirstOrDefault();
                        if (checkdub == null)
                        {
                            TestInstructionInfo.InstructionText = sourcetestinfo;
                            TestInstructionInfo.Id                  = Guid.NewGuid().ToString();
                            TestInstructionInfo.OrganizationID      = orgid;
                            TestInstructionInfo.RowState            = true;
                            TestInstructionInfo.CreateDateTime      = System.DateTime.Now;
                            entity.Entry(TestInstructionInfo).State = System.Data.Entity.EntityState.Added;
                            entity.TestInstructions.Add(TestInstructionInfo);

                            try
                            {
                                result = entity.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                            errormsg = "Code already exist with same Code for selected Test.";
                        }
                    }
                    else
                    {
                        EPortal.Models.TestInstruction usedata = (from o in entity.TestInstructions
                                                                  where o.OrganizationID == orgid &&
                                                                  o.Id == TestInstructionInfo.Id
                                                                  select o
                                                                  ).FirstOrDefault();
                        usedata.Code                = TestInstructionInfo.Code;
                        usedata.Name                = TestInstructionInfo.Name;
                        usedata.InstructionText     = sourcetestinfo;
                        entity.Entry(usedata).State = System.Data.Entity.EntityState.Modified;
                        try
                        {
                            result = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            //else
            //{
            //    if (TestInstructionInfo.Code != "" || TestInstructionInfo.Code != null)
            //    {
            //        errormsg = "Please enter Code.";
            //    }
            //    if (TestInstructionInfo.Name != "" || TestInstructionInfo.Name != null)
            //    {
            //        errormsg = "Please enter Name.";
            //    }
            //    if (TestInstructionInfo.InstructionText != "" || TestInstructionInfo.InstructionText != null)
            //    {
            //        errormsg = "Please enter Instruction.";
            //    }
            //}

            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult OrganizationSave(List <ModuleNameList> moduleprevlist, string orgid)
        {
            EPortal.Models.OrganizationPage orgpage            = null;
            EPortal.Models.Previleage       Previleageforadmin = null;
            int result = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                foreach (var module in moduleprevlist)
                {
                    foreach (var modulepage in module.modulepagelist)
                    {
                        var checkexistornot = (from op in entity.OrganizationPages
                                               where op.OrganizationID == orgid &&
                                               op.PageId == modulepage.Id
                                               select op).FirstOrDefault();
                        string code = string.Empty;
                        if (module.Code == "OrganizationSetup" || module.Code == "UserManagement" || module.Code == "SchoolSetup" || module.Code == "Fee")
                        {
                            code = "Admin";
                        }
                        else
                        {
                            code = "Applicant";
                        }
                        var getroleid = (from r in entity.RoleMasters
                                         where r.OrganizationID == orgid &&
                                         r.Code == code
                                         select r).FirstOrDefault();
                        if (checkexistornot != null)
                        {
                            if (modulepage.Create == false)
                            {
                                entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Deleted;


                                if (getroleid != null)
                                {
                                    var prev = (from p in entity.Previleages
                                                where p.OrganizationID == orgid &&
                                                p.PageId == modulepage.Id &&
                                                p.RoleId == getroleid.Id
                                                select p).FirstOrDefault();
                                    if (prev != null)
                                    {
                                        entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Deleted;
                                    }
                                }
                            }
                            else
                            {
                                entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Modified;
                            }
                        }
                        else
                        {
                            if (modulepage.Create == true)
                            {
                                orgpage                     = new OrganizationPage();
                                orgpage.Id                  = Guid.NewGuid().ToString();
                                orgpage.OrganizationID      = orgid;
                                orgpage.PageId              = modulepage.Id;
                                orgpage.CreateDateTime      = System.DateTime.Now;
                                orgpage.RowState            = true;
                                entity.Entry(orgpage).State = System.Data.Entity.EntityState.Added;

                                Previleageforadmin                     = new Previleage();
                                Previleageforadmin.Id                  = Guid.NewGuid().ToString();
                                Previleageforadmin.RoleId              = getroleid.Id;
                                Previleageforadmin.PageId              = modulepage.Id;
                                Previleageforadmin.OperationId         = string.Empty;
                                Previleageforadmin.PCreate             = true;
                                Previleageforadmin.PUpdate             = true;
                                Previleageforadmin.PDelete             = true;
                                Previleageforadmin.PView               = true;
                                Previleageforadmin.OrganizationID      = orgid;
                                Previleageforadmin.RowState            = true;
                                Previleageforadmin.CreateDateTime      = System.DateTime.Now;
                                entity.Entry(Previleageforadmin).State = System.Data.Entity.EntityState.Added;
                                entity.Previleages.Add(Previleageforadmin);
                            }
                        }
                    }
                }
                result = entity.SaveChanges();
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
示例#29
0
        public JsonResult SaveCourse(EPortal.Models.Course course)
        {
            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 (course.Operation == "Create")
                    {
                        var checkrolecode = (from r in entity.RoleMasters
                                             where r.OrganizationID == orgid &&
                                             r.Code == course.Code
                                             select r).FirstOrDefault();
                        if (checkrolecode == null)
                        {
                            course.Id             = Guid.NewGuid().ToString();
                            course.OrganizationID = orgid;
                            course.RowState       = true;
                            course.CreateDateTime = System.DateTime.Now;

                            entity.Entry(course).State = System.Data.Entity.EntityState.Added;
                            entity.Courses.Add(course);
                            try
                            {
                                result = entity.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                            errormsg = "Course already exist with same Code.";
                        }
                    }
                    else
                    {
                        EPortal.Models.Course roledata = (from o in entity.Courses
                                                          where o.OrganizationID == orgid &&
                                                          o.Id == course.Id
                                                          select o
                                                          ).FirstOrDefault();

                        roledata.Code = course.Code;
                        roledata.Name = course.Name;
                        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));
        }
        public JsonResult SaveOrganization(EPortal.Models.Organization orgdata)
        {
            string errormsg = "";
            int    result   = 0;

            if ((orgdata.Code != "" || orgdata.Code != null) && (orgdata.Name != "" || orgdata.Name != null))
            {
                // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required");
                EPortal.Models.RoleMaster        roleadmin              = new RoleMaster();
                EPortal.Models.RoleMaster        roleapplicant          = new RoleMaster();
                EPortal.Models.UserInfo          Userforadmin           = new UserInfo();
                EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
                EPortal.Models.Previleage        Previleageforadmin     = null;
                List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
                List <EPortal.Models.Page>       getPage = new List <Page>();



                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (orgdata.Operation == "Create")
                    {
                        orgdata.Id = Guid.NewGuid().ToString();

                        #region Create AdminUser for This Organization
                        roleadmin.Id             = Guid.NewGuid().ToString();
                        roleadmin.Code           = "admin";
                        roleadmin.Name           = "admin";
                        roleadmin.OrganizationID = orgdata.Id;
                        roleadmin.RowState       = true;
                        roleadmin.CreateDateTime = System.DateTime.Now;



                        #region Create ROle for This User
                        roleapplicant.Id             = Guid.NewGuid().ToString();
                        roleapplicant.Code           = "Applicant";
                        roleapplicant.Name           = "Applicant";
                        roleapplicant.OrganizationID = orgdata.Id;
                        roleapplicant.RowState       = true;
                        roleapplicant.CreateDateTime = System.DateTime.Now;



                        #endregion

                        Userforadmin.Id             = Guid.NewGuid().ToString();
                        Userforadmin.Code           = "Admin";
                        Userforadmin.Name           = "Admin";
                        Userforadmin.LogInId        = "admin";
                        Userforadmin.UserPassword   = "******";
                        Userforadmin.UserType       = "50";
                        Userforadmin.OrganizationID = orgdata.Id;
                        Userforadmin.RowState       = true;
                        Userforadmin.CreateDateTime = System.DateTime.Now;

                        Userroleforadmin.Id             = Guid.NewGuid().ToString();
                        Userroleforadmin.UserId         = Userforadmin.Id;
                        Userroleforadmin.RoleId         = roleadmin.Id;
                        Userroleforadmin.OrganizationID = orgdata.Id;
                        Userroleforadmin.RowState       = true;
                        Userroleforadmin.CreateDateTime = System.DateTime.Now;



                        #endregion

                        #region Get All Page
                        getPage = (from p in entity.Pages
                                   where p.Code != "Organization" &&
                                   p.ForAdmin == true
                                   select p).ToList();
                        if (getPage.Count() > 0)
                        {
                            //foreach (Page item in getPage)
                            //{
                            //    Previleageforadmin = new Previleage();
                            //    Previleageforadmin.Id = Guid.NewGuid().ToString();
                            //    Previleageforadmin.RoleId = roleadmin.Id;
                            //    Previleageforadmin.PageId = item.Id;
                            //    Previleageforadmin.OperationId = string.Empty;
                            //    Previleageforadmin.PCreate = true;
                            //    Previleageforadmin.PUpdate = true;
                            //    Previleageforadmin.PDelete = true;
                            //    Previleageforadmin.PView = true;
                            //    Previleageforadmin.OrganizationID = orgdata.Id;
                            //    Previleageforadmin.RowState = true;
                            //    Previleageforadmin.CreateDateTime = System.DateTime.Now;
                            //    Previleageforadminlist.Add(Previleageforadmin);
                            //}
                        }
                        #endregion

                        entity.Entry(orgdata).State          = System.Data.Entity.EntityState.Added;
                        entity.Entry(roleadmin).State        = System.Data.Entity.EntityState.Added;
                        entity.Entry(roleapplicant).State    = System.Data.Entity.EntityState.Added;
                        entity.Entry(Userforadmin).State     = System.Data.Entity.EntityState.Added;
                        entity.Entry(Userroleforadmin).State = System.Data.Entity.EntityState.Added;

                        entity.Organizations.Add(orgdata);
                        entity.RoleMasters.Add(roleadmin);
                        entity.RoleMasters.Add(roleapplicant);
                        entity.UserInfoes.Add(Userforadmin);
                        entity.UserRoles.Add(Userroleforadmin);
                        //foreach (Previleage item in Previleageforadminlist)
                        //{
                        //    entity.Entry(item).State = System.Data.Entity.EntityState.Added;
                        //    entity.Previleages.Add(item);
                        //}
                        try
                        {
                            result = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        orgdata.Code      = orgdata.Code;
                        orgdata.Name      = orgdata.Name;
                        orgdata.ContactNo = orgdata.ContactNo;
                        orgdata.ESTDate   = orgdata.ESTDate;
                        orgdata.PhoneNo   = orgdata.PhoneNo;
                        orgdata.Email     = orgdata.Email;
                        orgdata.Address   = orgdata.Address;
                        orgdata.Country   = orgdata.Country;
                        orgdata.OrgState  = orgdata.OrgState;
                        orgdata.Location  = orgdata.Location;
                        orgdata.Pin       = orgdata.Pin;

                        entity.Entry(orgdata).State = System.Data.Entity.EntityState.Modified;
                        result = entity.SaveChanges();
                    }
                }
            }
            else
            {
                if (orgdata.Code != "" || orgdata.Code != null)
                {
                    errormsg = "Please enter Code.";
                }
                if (orgdata.Name != "" || orgdata.Name != null)
                {
                    errormsg = "Please enter Name.";
                }
            }

            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }