Example #1
0
        public ActionResult SaveFile()
        {
            if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("admin"))
            {
                HttpPostedFileBase file = Request.Files[0];
                file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName));

                var result = "";

                char[] delimiterChar = { ',' };
                string[] data = null;

                var dataFile = Server.MapPath(@"~\Files\" + file.FileName);

                FileStream fin = new FileStream(dataFile, FileMode.Open);
                StreamReader sr = new StreamReader(fin);
                result = sr.ReadLine();

                try
                {

                    while (result != null)
                       
                    {
                        data = result.Split(delimiterChar);
                        user u = new user();
                        u.uid = data[0];
                        u.name = data[1];
                        u.type = data[2];
                        u.password = "******";
                        u.email = data[3];

                        var query = db.users.Where(x => x.uid.Equals(u.uid));
                        string s = null;
                        foreach (var a in query)
                        {
                            s = s + a.uid + " " + a.name;
                        }
                        if (s == null)
                        {
                            db.users.Add(u);
                            db.SaveChanges();

                            if (u.type.Equals("Student"))
                            {
                                student st = new student();
                                st.sid = u.uid;
                                st.name = u.name;
                                st.batch = u.uid.Substring(3, 3);
                                st.degree = u.uid.Substring(0, 3);
                                st.section = u.uid[6] == 'M' ? "Morning" : "Afternoon";
                                st.session = u.uid.Substring(0, 7);
                                st.password = u.password;
                                st.email = u.email;
                                db.students.Add(st);
                                db.SaveChanges();
                            }
                            else if (u.type.Equals("Teacher"))
                            {
                                teacher t = new teacher();
                                t.tid = u.uid;
                                t.name = u.name;
                                t.password = u.password;
                                t.email = u.email;
                                db.teachers.Add(t);
                                db.SaveChanges();
                            }
                        }

                        result = sr.ReadLine();
                        data = null;
                    }
                    sr.Close();
                    fin.Close();
                }
                catch (Exception e)
                {
                    ViewBag.ErrorType = "UserAdd";
                    ViewBag.message = "File format is not correct";
                    sr.Close();
                    fin.Close();
                    return View("ErrorPage");
                }
                return View("AddUser");
            }
            return RedirectToAction("signIn", "Home");
        }
Example #2
0
        public JsonResult GetTeachers()
        {
            var query = (from x in db.teachers
                         select x);

            List<teacher> data = new List<teacher>();

            foreach (var q in query)
            {
                teacher c = new teacher();
                c.tid = q.tid;

                data.Add(c);

            }
            return this.Json(data, JsonRequestBehavior.AllowGet);

        }
Example #3
0
 public ActionResult SaveUser( user u )
 {
     if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("admin"))
     {
         var query = db.users.Where(x => x.uid.Equals(u.uid));
         string s = null;
         foreach (var a in query)
         {
             s = s + a.uid + " " + a.name;
         }
         if (s == null)
         {
             u.password = "******";
             if (u.type.Equals("Teacher"))
             {
                 teacher t = new teacher();
                 t.name = u.name;
                 t.password = u.password;
                 t.tid = u.uid;
                 t.email = u.email;
                 t.dept = u.dept;
                 db.teachers.Add(t);
             }
             else
             {
                 student st = new student();
                 st.name = u.name;
                 st.password = u.password;
                 st.sid = u.uid;
                 st.batch = u.uid.Substring(0, 3);
                 st.degree = "BCS";
                 //st.section = u.uid[6] == 'M' ? "Morning" : "Afternoon";
                 st.section = "Morning";
                 st.session = u.uid.Substring(0, 6);
                 st.email = u.email;
                 st.dept = u.dept;
                 db.students.Add(st);
             }
             db.users.Add(u);
             db.SaveChanges();
             ViewBag.message = 1;
             return View("AddSingleUser");
         }
         else
         {
             ViewBag.message = 0;
             return View("AddSingleUser");
         }
     }
     return RedirectToAction("signIn", "Home");
     
 }
Example #4
0
        public ActionResult Faculty()
        {
            List<teacher> data = new List<teacher>();

            var query = from r in db.teachers

                                select r;

                    foreach (var q in query)
                    {
                        teacher c = new teacher();
                        c.tid = q.tid;
                        c.name = q.name;
                        c.email = q.email;
                        c.designation = q.designation;
                        data.Add(c);

                    }
            return View(data);
 
        }