public TblSchool CreateSchool(int eventID, string schoolUsername, string schoolPassword, string schoolName)
        {
            using (DB_YoungEnterpriseContext databaseContext = GetConnection())
            {
                // Should find judge or school by username, instead of searching all though
                foreach (TblJudge j in GetAllJudges())
                {
                    if (schoolUsername.Equals(j.FldJudgeUsername))
                    {
                        throw new UserNameAlreadyExistsException(schoolUsername);
                    }
                }

                foreach (TblSchool s in GetAllSchools())
                {
                    if (schoolUsername.Equals(s.FldSchoolUsername))
                    {
                        throw new UserNameAlreadyExistsException(schoolUsername);
                    }
                }

                TblSchool school = new TblSchool()
                {
                    FldEventId        = eventID,
                    FldSchoolUsername = schoolUsername,
                    FldSchoolPassword = schoolPassword,
                    FldSchoolName     = schoolName
                };
                databaseContext.TblSchool.Add(school);
                databaseContext.SaveChanges();
                return(school);
            }
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            TblSchool tblSchool = db.TblSchools.Find(id);

            var events = db.TblEvents.Where(a => a.SchoolId == tblSchool.SchoolId);

            var grades = db.TblGrades.Where(a => a.SchoolId == tblSchool.SchoolId);

            var guardians = db.TblGuardians.Where(a => a.SchoolId == tblSchool.SchoolId);

            var learners = db.TblLearners.Where(a => a.SchoolId == tblSchool.SchoolId);

            var teachers = db.TblTeachers.Where(a => a.SchoolId == tblSchool.SchoolId);

            var users = db.TblUsers.Where(a => a.SchoolId == tblSchool.SchoolId);

            if (events.Any() || grades.Any() || guardians.Any() || learners.Any() || teachers.Any() || users.Any())
            {
                TempData["DelFail"] = "You cannot delete a School that is linked to other tables in the system.";
                return(RedirectToAction("Index"));
            }



            db.TblSchools.Remove(tblSchool);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
 public object Delete(UpdateSchool s)
 {
     try
     {
         TblSchool objuser = db.TblSchools.Where(r => r.SchoolId == s.SchoolId).FirstOrDefault();
         if (objuser.Status == 1)
         {
             objuser.Status = 0;
         }
         else
         {
             objuser.Status = 1;
         }
         db.SaveChanges();
         return(new Result()
         {
             IsSucess = true, ResultData = "Deactivted"
         });
     }
     catch (Exception e)
     {
         return(new Error()
         {
             IsError = true, Message = e.Message
         });
     }
 }
Exemplo n.º 4
0
        public async Task <IActionResult> PutTblSchool([FromRoute] int id, [FromBody] TblSchool tblSchool)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblSchool.FldSchoolId)
            {
                return(BadRequest());
            }

            _context.Entry(tblSchool).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblSchoolExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public ActionResult SelectSchool([Bind(Include = "SchoolId")] TblSchool tblSchool)
        {
            try
            {
                string userData = "";
                int    schoolId = tblSchool.SchoolId;

                userData = EmailG + ";" + schoolId + ";" + 0 + ";" + UserIdG + ";";


                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, EmailG, DateTime.Now,
                                                                                 DateTime.Now.AddDays(2),
                                                                                 true,
                                                                                 userData,
                                                                                 FormsAuthentication.FormsCookiePath);

                // Encrypt the ticket.
                string encTicket = FormsAuthentication.Encrypt(ticket);

                // Create the cookie.
                HttpCookie userCookie = new HttpCookie("UserInformation", encTicket);
                userCookie.Expires = DateTime.Now.AddDays(2);

                Response.Cookies.Add(userCookie);
                return(RedirectToAction("NavigationHomeIndex", "PCMSNavigation"));
            }
            catch (Exception e)
            {
                string error = e.Message;
            }


            return(RedirectToAction("LoginHomeIndex"));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "SchoolId,SchoolCode,UserId,SchoolName,SchoolAddress,SchoolEmail,SchoolContactNr,SchoolStartDate,SchooEndDate")] TblSchool tblSchool)
        {
            TblUser tblUser = new TblUser();

            if (ModelState.IsValid)
            {
                db.TblSchools.Add(tblSchool);
                db.SaveChanges();

                tblUser.SchoolId         = tblSchool.SchoolId;
                tblUser.UserName         = tblSchool.SchoolName + " Admin";
                tblUser.UserAccessTypeId = 2;
                tblUser.EmailAddress     = tblSchool.SchoolEmail;
                tblUser.IsUserVerified   = false;
                tblUser.UserStartDate    = tblSchool.SchoolStartDate;
                tblUser.UserEndDate      = tblSchool.SchoolEndDate;

                db.TblUsers.Add(tblUser);
                db.SaveChanges();

                SendVerificationEmail(tblUser.EmailAddress, tblSchool.SchoolCode);

                tblSchool.UserId = tblUser.UserId;

                db.Entry(tblSchool).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.TblUsers, "UserId", "UserName", tblSchool.UserId);
            return(View(tblSchool));
        }
 public void DeleteSchool(TblSchool school)
 {
     using (DB_YoungEnterpriseContext databaseContext = GetConnection())
     {
         databaseContext.TblSchool.Remove(school);
         databaseContext.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "SchoolId,SchoolCode,UserId,SchoolName,SchoolAddress,SchoolEmail,SchoolContactNr,SchoolStartDate,SchooEndDate")] TblSchool tblSchool)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblSchool).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.TblUsers, "UserId", "UserName", tblSchool.UserId);
     return(View(tblSchool));
 }
Exemplo n.º 9
0
        public async Task <IActionResult> PostTblSchool([FromBody] TblSchool tblSchool)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.TblSchool.Add(tblSchool);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblSchool", new { id = tblSchool.FldSchoolId }, tblSchool));
        }
Exemplo n.º 10
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TblSchool tblSchool = db.TblSchools.Find(id);

            if (tblSchool == null)
            {
                return(HttpNotFound());
            }
            return(View(tblSchool));
        }
        public int GetSchoolID(string schoolUsername)
        {
            List <TblSchool> schools = GetAllSchools();

            TblSchool selectedSchool = new TblSchool();

            foreach (TblSchool school in schools)
            {
                if (school.FldSchoolUsername.Equals(schoolUsername))
                {
                    selectedSchool = school;
                    return(selectedSchool.FldSchoolId);
                }
            }

            return(0);
        }
Exemplo n.º 12
0
        public object SaveSchool(School school)
        {
            if (school.UserName == null)
            {
                return(new Error()
                {
                    IsError = true, Message = "Required Username"
                });
            }

            TblSchool obj         = new TblSchool();
            var       httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                string UploadBaseUrl = ConfigurationManager.AppSettings["UploadBaseURL"];
                string fileName      = string.Empty;
                var    filePath      = string.Empty;
                string savePath      = string.Empty;
                foreach (string file in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[file];
                    fileName              = postedFile.FileName;
                    filePath              = ConfigurationManager.AppSettings["UploadDir"] + Guid.NewGuid() + fileName;
                    savePath              = HttpContext.Current.Server.MapPath(filePath); postedFile.SaveAs(savePath);
                    obj.SchoolName        = school.SchoolName;
                    obj.PhoneNo           = school.PhoneNo;
                    obj.Address           = school.Address;
                    obj.ContactPerson     = school.ContactPerson;
                    obj.LandlineNo        = school.LandlineNo;
                    obj.EmailId           = school.EmailId;
                    obj.Designation       = school.Designation;
                    obj.ValidityStartDate = school.ValidityStartDate;
                    obj.ValidityEndDate   = school.ValidityEndDate;
                    obj.PayrollTemplateId = school.PayrollTemplateId;
                    obj.FeeTemplateId     = school.FeeTemplateId;
                    obj.LoginTemplateId   = school.LoginTemplateId;
                    obj.ExamTemplateId    = school.ExamTemplateId;
                    obj.CreatedBy         = 1;
                    obj.CreatedDate       = school.CreatedDate;
                    obj.ModifiedBy        = 1;
                    obj.ModifiedDate      = school.ModifiedDate;
                    obj.UserPrefix        = school.UserPrefix;
                    obj.UserName          = school.UserName;
                    obj.Password          = school.Password;
                    obj.BoardId           = school.BoardId;
                    obj.Language          = school.Language;
                    obj.Logo              = UploadBaseUrl + filePath.Replace("~/", "");
                    obj.Banner            = school.Banner;
                    obj.Status            = 1;

                    db.TblSchools.Add(obj);
                    db.SaveChanges();
                }
            }
            //user.code = Convert.ToInt32(HttpContext.Current.Session["Code"]);
            return(new Result
            {
                IsSucess = true,
                ResultData = "School Created!"
            });
        }
Exemplo n.º 13
0
        public object UpdateSchoolInfo(UpdateSchool school)
        {
            var httpRequest = HttpContext.Current.Request;
            var Logo        = System.Web.HttpContext.Current.Request.Files["logo"];

            var          Banner = System.Web.HttpContext.Current.Request.Files["banner"];
            var          json1  = System.Web.HttpContext.Current.Request.Form["id"];
            var          json   = System.Web.HttpContext.Current.Request.Form["data"];
            UpdateSchool info   = Newtonsoft.Json.JsonConvert.DeserializeObject <UpdateSchool>(json);

            if (info.SchoolName == null)
            {
                return(new Error()
                {
                    IsError = true, Message = "Requird Name"
                });
            }
            //var datas = db.TblSchools.FirstOrDefault(r => r.SchoolName == info.SchoolName);
            //if (Logo != null)
            //{
            //    return new Error() { IsError = true, Message = "Duplicate Entry Not Allowed" };
            //}
            var data = db.TblSchools.Where(r => r.SchoolId == info.SchoolId).FirstOrDefault();

            TblSchool obj            = new TblSchool();
            string    UploadBaseUrl  = ConfigurationManager.AppSettings["UploadBaseURL"];
            string    fileLogo       = string.Empty;
            string    fileBanner     = string.Empty;
            var       filePath       = string.Empty;
            var       filePathBanner = string.Empty;
            var       filePathSave   = string.Empty;
            string    savePath       = string.Empty;
            var       Upload         = data.SchoolName;


            data.SchoolId          = info.SchoolId;
            data.SchoolName        = info.SchoolName;
            data.PhoneNo           = info.PhoneNo;
            data.Address           = info.Address;
            data.ContactPerson     = info.ContactPerson;
            data.PayrollTemplateId = info.PayrollTemplateId;
            data.FeeTemplateId     = info.FeeTemplateId;
            data.LoginTemplateId   = info.LoginTemplateId;
            data.ExamTemplateId    = info.ExamTemplateId;
            data.ModifiedBy        = 1;
            data.ModifiedDate      = System.DateTime.Today.Date;
            data.UserPrefix        = info.UserPrefix;
            data.UserName          = info.UserName;
            data.Password          = info.Password;
            data.Language          = info.Language;
            data.LandlineNo        = info.LandlineNo;
            data.EmailId           = info.EmailId;
            data.Designation       = info.Designation;
            data.CreatedBy         = data.CreatedBy;
            data.CreatedDate       = data.CreatedDate;

            TblBoardDetail board = new TblBoardDetail();

            string[] ids       = json1.Split(',');
            var      boarddata = db.TblBoardDetails.Where(r => r.SchoolId == info.SchoolId).FirstOrDefault();

            //var getinfo = db.TblBoardDetails.Where(r => r.SchoolId == info.SchoolId && r.BoardId==boarddata.BoardId).FirstOrDefault();
            if (boarddata == null)
            {
                for (int i = 0; i < ids.Length; i++)
                {
                    board.SchoolId = data.SchoolId;

                    board.BoardId      = Convert.ToInt64(ids[i].Replace("[", "").Replace("]", ""));
                    board.CreatedBy    = 1;
                    board.CreatedDate  = System.DateTime.Today.Date;
                    board.ModifiedBy   = null;
                    board.ModifiedDate = System.DateTime.Today.Date;

                    db.TblBoardDetails.Add(board);
                    db.SaveChanges();
                }
            }
            else
            {
                for (int i = 0; i < ids.Length; i++)
                {
                    board.SchoolId = boarddata.SchoolId;

                    board.BoardId      = Convert.ToInt64(ids[i].Replace("[", "").Replace("]", ""));
                    board.CreatedBy    = 1;
                    board.CreatedDate  = System.DateTime.Today.Date;
                    board.ModifiedBy   = null;
                    board.ModifiedDate = System.DateTime.Today.Date;

                    //db.TblBoardDetails.Add(board);
                    db.SaveChanges();
                }
            }

            if (httpRequest.Files.Count == 0)
            {
                db.SaveChanges();
                return(new Result
                {
                    IsSucess = true,
                    ResultData = "School Updated!"
                });
            }
            else
            {
                var uploaddirc = Path.Combine(HttpContext.Current.Server.MapPath("/"), "SchoolUpload" + ("\\"));
                if (!Directory.Exists(uploaddirc))
                {
                    DirectoryInfo di = Directory.CreateDirectory(uploaddirc);
                }
                string paths = "SchoolUpload";
                for (int i = 0; i < httpRequest.Files.Count; i++)
                {
                    var uploadpath = Path.Combine(HttpContext.Current.Server.MapPath("/"), paths, Upload.ToString() + ("\\"));
                    if (!Directory.Exists(uploadpath))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(uploadpath);
                    }
                    if (i == 0 && Logo != null)
                    {
                        var file  = httpRequest.Files[i];
                        var Guids = Guid.NewGuid();
                        filePathSave = uploadpath + Guids;
                        filePath     = filePathSave + file.FileName;

                        savePath = uploadpath;
                        file.SaveAs(filePath);
                        data.Logo = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("/") + Guids + file.FileName;
                        //string Logo1 = data.Logo.Replace("~/", "");
                        //data.Logo = Logo1;
                    }
                    else
                    {
                        var file        = httpRequest.Files[i];
                        var GuidsBanner = Guid.NewGuid();
                        filePathSave   = uploadpath + GuidsBanner;
                        filePathBanner = filePathSave + file.FileName;

                        savePath = uploadpath;
                        file.SaveAs(filePathBanner);
                        data.Banner = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("\\") + GuidsBanner + file.FileName;
                        //string Banner1 = data.Banner.Replace("~/", "");
                        //data.Banner = Banner1;
                    }
                }

                db.SaveChanges();
                return(new Result
                {
                    IsSucess = true,
                    ResultData = "School Updated!"
                });
            }
        }
Exemplo n.º 14
0
        public object SaveSchool(School s)
        {
            try
            {
                var    Logo   = System.Web.HttpContext.Current.Request.Files["file"];
                var    Banner = System.Web.HttpContext.Current.Request.Files["file1"];
                var    json1  = System.Web.HttpContext.Current.Request.Form["id"];
                var    json   = System.Web.HttpContext.Current.Request.Form["data"];
                School school = Newtonsoft.Json.JsonConvert.DeserializeObject <School>(json);
                //var boardid = json1.Replace(",", "");

                if (school.UserName == null)
                {
                    return(new Error()
                    {
                        IsError = true, Message = "Required Username"
                    });
                }
                var info = db.TblSchools.FirstOrDefault(r => r.SchoolName == school.SchoolName);
                if (info != null)
                {
                    return(new Error()
                    {
                        IsError = true, Message = "Duplicate Entry Not Allowed"
                    });
                }
                TblSchool obj            = new TblSchool();
                var       httpRequest    = HttpContext.Current.Request;
                string    UploadBaseUrl  = ConfigurationManager.AppSettings["UploadBaseURL"];
                string    fileLogo       = string.Empty;
                string    fileBanner     = string.Empty;
                var       filePath       = string.Empty;
                string    savePath       = string.Empty;
                var       filePathBanner = string.Empty;
                var       filePathSave   = string.Empty;
                var       Upload         = school.SchoolName;

                obj.SchoolName        = school.SchoolName;
                obj.PhoneNo           = school.PhoneNo;
                obj.Address           = school.Address;
                obj.ContactPerson     = school.ContactPerson;
                obj.LandlineNo        = school.LandlineNo;
                obj.EmailId           = school.EmailId;
                obj.Designation       = school.Designation;
                obj.ValidityStartDate = school.ValidityStartDate;
                obj.ValidityEndDate   = school.ValidityEndDate;
                obj.PayrollTemplateId = school.PayrollTemplateId;
                obj.FeeTemplateId     = school.FeeTemplateId;
                obj.LoginTemplateId   = school.LoginTemplateId;
                obj.ExamTemplateId    = school.ExamTemplateId;
                obj.CreatedBy         = 1;
                obj.CreatedDate       = System.DateTime.Today.Date;
                obj.ModifiedBy        = 1;
                obj.ModifiedDate      = System.DateTime.Today.Date;
                obj.UserPrefix        = school.UserPrefix;
                obj.UserName          = school.UserName;
                obj.Password          = school.Password;
                obj.Language          = school.Language;
                obj.Status            = 1;

                var uploaddirc = Path.Combine(HttpContext.Current.Server.MapPath("/"), "SchoolUpload" + ("\\"));
                if (!Directory.Exists(uploaddirc))
                {
                    DirectoryInfo di = Directory.CreateDirectory(uploaddirc);
                }
                string paths = "SchoolUpload";
                for (int i = 0; i < httpRequest.Files.Count; i++)
                {
                    var uploadpath = Path.Combine(HttpContext.Current.Server.MapPath("/"), paths, Upload.ToString() + ("\\"));
                    if (!Directory.Exists(uploadpath))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(uploadpath);
                    }
                    if (i == 0 && Logo != null)
                    {
                        var file  = httpRequest.Files[i];
                        var Guids = Guid.NewGuid();
                        filePathSave = uploadpath + Guids;
                        filePath     = filePathSave + file.FileName;

                        savePath = uploadpath;
                        file.SaveAs(filePath);
                        obj.Logo = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("/") + Guids + file.FileName;
                        //string Logo1 = data.Logo.Replace("~/", "");
                        //data.Logo = Logo1;
                    }
                    else
                    {
                        var file        = httpRequest.Files[i];
                        var GuidsBanner = Guid.NewGuid();
                        filePathSave   = uploadpath + GuidsBanner;
                        filePathBanner = filePathSave + file.FileName;

                        savePath = uploadpath;
                        file.SaveAs(filePathBanner);
                        obj.Banner = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("\\") + GuidsBanner + file.FileName;
                        //string Banner1 = data.Banner.Replace("~/", "");
                        //data.Banner = Banner1;
                    }
                }

                db.TblSchools.Add(obj);
                db.SaveChanges();
                CopyDB objDB = new CopyDB();
                string name  = school.SchoolName.Replace(" ", "") + "DB";
                objDB.Copydata(name.ToUpper());
                var            details = db.TblSchools.FirstOrDefault(r => r.SchoolName == school.SchoolName);
                TblBoardDetail board   = new TblBoardDetail();
                string[]       ids     = json1.Split(',');

                for (int i = 0; i < ids.Length; i++)
                {
                    board.SchoolId     = details.SchoolId;
                    board.BoardId      = Convert.ToInt64(ids[i].Replace("[", "").Replace("]", ""));
                    board.CreatedBy    = 1;
                    board.CreatedDate  = System.DateTime.Today.Date;
                    board.ModifiedBy   = null;
                    board.ModifiedDate = System.DateTime.Today.Date;
                    db.TblBoardDetails.Add(board);
                    db.SaveChanges();
                }


                //user.code = Convert.ToInt32(HttpContext.Current.Session["Code"]);
                return(new Result
                {
                    IsSucess = true,
                    ResultData = "School Created!"
                });
            }
            catch (Exception e)
            {
                return(new Error {
                    IsError = true, Message = e.Message
                });
            }
        }
Exemplo n.º 15
0
        static void InsertSchools()
        {
            LINQ2SqlPracticeDataContext db;

            db = GetDBContext();

            TblSchool sch1 = new TblSchool();

            sch1.Sch_Id       = 1;
            sch1.Sch_Name     = "ZPHS School";
            sch1.Sch_Area     = "Dargamitta";
            sch1.Sch_City     = "Nellore";
            sch1.Sch_State    = "Andhra Pradesh";
            sch1.Sch_Country  = "INDia";
            sch1.Sch_Location = "Nippo Back Side";
            sch1.Sch_Pincode  = "524004";

            db.TblSchools.InsertOnSubmit(sch1);

            TblSchool sch2 = new TblSchool();

            sch2.Sch_Id       = 2;
            sch2.Sch_Name     = "MPUP School";
            sch2.Sch_Area     = "BhakthaVatsala Nagar";
            sch2.Sch_City     = "Nellore";
            sch2.Sch_State    = "Andhra Pradesh";
            sch2.Sch_Country  = "INDia";
            sch2.Sch_Location = "Current Office";
            sch2.Sch_Pincode  = "524004";

            db.TblSchools.InsertOnSubmit(sch2);

            TblSchool sch3 = new TblSchool();

            sch3.Sch_Id       = 3;
            sch3.Sch_Name     = "Narayana Olympiad School";
            sch3.Sch_Area     = "Haranadha Puram";
            sch3.Sch_City     = "Nellore";
            sch3.Sch_State    = "Andhra Pradesh";
            sch3.Sch_Country  = "INDia";
            sch3.Sch_Location = "Haranadha Puram";
            sch3.Sch_Pincode  = "524001";

            db.TblSchools.InsertOnSubmit(sch3);

            TblSchool sch4 = new TblSchool();

            sch4.Sch_Id       = 4;
            sch4.Sch_Name     = "Chaitanya E-Techno School";
            sch4.Sch_Area     = "Kanuru";
            sch4.Sch_City     = "Vijayawada";
            sch4.Sch_State    = "Andhra Pradesh";
            sch4.Sch_Country  = "INDia";
            sch4.Sch_Location = "Kanuru Village";
            sch4.Sch_Pincode  = "514001";

            db.TblSchools.InsertOnSubmit(sch4);

            TblSchool sch5 = new TblSchool();

            sch5.Sch_Id       = 5;
            sch5.Sch_Name     = "Ravindra Bharathi School";
            sch5.Sch_Area     = "Gajuwaka";
            sch5.Sch_City     = "Vizag";
            sch5.Sch_State    = "Andhra Pradesh";
            sch5.Sch_Country  = "INDia";
            sch5.Sch_Location = "Gajuwaka";
            sch5.Sch_Pincode  = "504002";

            db.TblSchools.InsertOnSubmit(sch5);
            db.SubmitChanges();
        }
Exemplo n.º 16
0
        public ActionResult Login([Bind(Include = "SchoolId")] TblSchool tblSchool, FormCollection form)
        {
            //Uri currentUrl = Request.UrlReferrer;
            //if (currentUrl == null)
            //{
            //    return HttpNotFound();
            //}

            //Create(); //Only Called when we need to create the first PCMS User
            try
            {
                string username = Hash(form["EmailAddress"]);
                string password = form["PasswordHash"];
                var    user     = db.TblSystemAdmins.Where(t => t.Username == username);

                if (user.Any())
                {
                    if (user.FirstOrDefault().PasswordHash == Hash(password))
                    {
                        SetGlobals(user.FirstOrDefault().UserId, user.FirstOrDefault().EmailAddress);

                        try
                        {
                            string userData = "";
                            int?   schoolId = tblSchool.SchoolId;
                            if (schoolId == null)
                            {
                                schoolId = 0;
                            }
                            userData = EmailG + ";" + schoolId + ";" + 0 + ";" + UserIdG + ";";


                            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, EmailG, DateTime.Now,
                                                                                             DateTime.Now.AddDays(2),
                                                                                             true,
                                                                                             userData,
                                                                                             FormsAuthentication.FormsCookiePath);

                            // Encrypt the ticket.
                            string encTicket = FormsAuthentication.Encrypt(ticket);

                            // Create the cookie.
                            HttpCookie userCookie = new HttpCookie("UserInformation", encTicket);
                            userCookie.Expires = DateTime.Now.AddDays(2);

                            Response.Cookies.Add(userCookie);
                            //return RedirectToAction("NavigationHomeIndex", "PCMSNavigation");
                            return(RedirectToAction("SelectSchool"));
                        }
                        catch (Exception e)
                        {
                            string error = e.Message;
                        }

                        //return RedirectToAction("NavigationHomeIndex", "PCMSNavigation");
                        return(RedirectToAction("SelectSchool"));
                    }
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
            }

            return(RedirectToAction("Login"));
        }
Exemplo n.º 17
0
        public ActionResult Edit(int?id)
        {
            Uri currentUrl = Request.UrlReferrer;

            if (currentUrl == null)
            {
                return(HttpNotFound());
            }

            HttpCookie usesrCookie = Request.Cookies["UserInformation"];

            if (usesrCookie == null)
            {
                return(RedirectToAction("LoginHomeIndex", "PCMSLogin"));
            }

            int?school = Int32.Parse(pcmsLoginController.LoggedOnUserData(usesrCookie)[1]);

            //Get UserID
            int?userID = Int32.Parse(pcmsLoginController.LoggedOnUserData(usesrCookie)[3]);

            if (db.TblUsers.Find(userID) != null)
            {
                ViewBag.UserName = db.TblUsers.Find(userID).UserName;
            }
            else if (db.TblSystemAdmins.Find(userID) != null)
            {
                ViewBag.UserName = "******";
            }
            else
            {
                ViewBag.UserName = "";
            }

            bool check = false;

            int userId = Int32.Parse(pcmsLoginController.LoggedOnUserData(usesrCookie)[3]);

            if (userId == db.TblSystemAdmins.FirstOrDefault().UserId)
            {
                check = true;
            }

            ViewBag.PCMS = check;

            var School = db.TblSchools.Find(school);

            if (School != null)
            {
                ViewBag.SchoolCode = School.SchoolCode;
                ViewBag.SchoolName = School.SchoolName;
            }
            else
            {
                ViewBag.SchoolCode = null;
                ViewBag.SchoolName = null;
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TblSchool tblSchool = db.TblSchools.Find(id);

            if (tblSchool == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.TblUsers, "UserId", "UserName", tblSchool.UserId);
            return(View(tblSchool));
        }