public ActionResult Save(AddLessonViewModel model, HttpPostedFileBase file)
        {
            ViewBag.Faculty   = ListFaculty((int)EnumParamaterGroup.Faculty);
            ViewBag.Departman = ListFaculty((int)EnumParamaterGroup.Departman);
            ViewBag.Class     = ListFaculty((int)EnumParamaterGroup.Class);
            if (ModelState.IsValid)
            {
                var loginUser = GetLoginUser();
                using (SduEntities ent = new SduEntities())
                {
                    if (file != null)
                    {
                        string path = HttpContext.Server.MapPath("~/Content/docs/") + file.FileName;
                        file.SaveAs(path);
                        List <string> dt = new List <string>();
                        IWorkbook     workbook;
                        IWorksheet    sheet;
                        uint          lastRow;

                        workbook = new Excel2007.Workbook(path);
                        sheet    = workbook.Worksheets.GetWorksheetByIndex(0);
                        lastRow  = sheet.LastRow;
                        for (uint i = 1; i <= lastRow; i++)
                        {
                            IRow   row       = sheet.Rows.GetRow(i);
                            string studentNo = "";
                            studentNo = GetCellValue(row, 0);
                            dt.Add(studentNo);
                        }
                        System.IO.File.Delete(path);
                        foreach (var item in dt)
                        {
                            Lesson lesson = new Lesson();
                            lesson.FacultyID     = model.FacultyID;
                            lesson.DepartmanID   = model.DepartmanID;
                            lesson.EducatorID    = loginUser.ID;
                            lesson.LessonName    = model.LessonName;
                            lesson.ClassID       = model.ClassID;
                            lesson.LessonCode    = model.LessonCode;
                            lesson.MaxContinuity = model.MaxContinuity;
                            lesson.StudentNo     = item.ToString();
                            ent.Lesson.Add(lesson);
                            ent.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(View("Index", model));
            }
        }
Esempio n. 2
0
 public ActionResult LoginUser(LoginViewModel login)
 {
     using (SduEntities ent = new SduEntities())
     {
         LoginUser loginUser      = new LoginUser();
         var       studentControl = ent.Student.Where(q => q.StudentNo == login.UserName && q.Password == login.Password).Select(q => q).SingleOrDefault();
         if (studentControl != null)
         {
             loginUser.AuthType  = (int)EnumAuthType.Ogrenci;
             loginUser.TCKN      = studentControl.TCKN;
             loginUser.ClassID   = studentControl.ClassID;
             loginUser.BranchID  = studentControl.BranchID;
             loginUser.StudentNo = studentControl.StudentNo;
             loginUser.CardNo    = studentControl.CardNo;
             // ortak olanlar
             loginUser.ID          = studentControl.StudentID;
             loginUser.NameSurname = studentControl.NameSurname;
             loginUser.Password    = studentControl.Password;
             loginUser.Photo       = studentControl.Photo;
             loginUser.FacultyID   = studentControl.FacultyID;
             loginUser.DepartmanID = studentControl.DepartmanID;
             Session["LoginUser"]  = loginUser;
             FormsAuthentication.SetAuthCookie(studentControl.StudentNo, false);
             return(RedirectToAction("Index", "AnaSayfa"));
         }
         else
         {
             var educatorControl = ent.Educator.Where(q => q.Username == login.UserName && q.Password == login.Password).Select(q => q).SingleOrDefault();
             if (educatorControl != null)
             {
                 loginUser.ID          = educatorControl.EducatorID;
                 loginUser.NameSurname = educatorControl.NameSurname;
                 loginUser.Password    = educatorControl.Password;
                 loginUser.Photo       = educatorControl.Photo;
                 loginUser.FacultyID   = educatorControl.FacultyID;
                 loginUser.DepartmanID = educatorControl.DepartmanID;
                 loginUser.AuthType    = (int)EnumAuthType.Hoca;
                 loginUser.SicilNo     = educatorControl.SicilNo;
                 Session["LoginUser"]  = loginUser;
                 FormsAuthentication.SetAuthCookie(educatorControl.SicilNo, false);
                 return(RedirectToAction("Index", "AnaSayfa"));
             }
             else
             {
                 Session["LoginUser"] = "******";
             }
         }
         return(View("Index", login));
     }
 }
 protected List <SelectListItem> ListFaculty(int type)
 {
     using (SduEntities ent = new SduEntities())
     {
         List <SelectListItem> item = new List <SelectListItem>();
         var list = ent.Parameter.Where(q => q.ParameterGroupID == type).Select(q => q).OrderBy(q => q.Text).ToList();
         foreach (var items in list)
         {
             item.Add(new SelectListItem {
                 Value = items.ParameterID.ToString(), Text = items.Text, Selected = false
             });
         }
         return(item);
     }
 }
 // GET: Home
 public ActionResult Index()
 {
     using (SduEntities ent = new SduEntities())
     {
         var loginUser = GetLoginUser();
         if (loginUser.AuthType == (int)EnumAuthType.Ogrenci)
         {
             HomePageViewModel detail = (from q in ent.Student
                                         join p in ent.Parameter on q.DepartmanID equals p.ParameterID
                                         join w in ent.Parameter on q.BranchID equals w.ParameterID
                                         join e in ent.Parameter on q.ClassID equals e.ParameterID
                                         join s in ent.Parameter on q.FacultyID equals s.ParameterID
                                         where q.TCKN == loginUser.TCKN
                                         select new HomePageViewModel
             {
                 TCKN = q.TCKN,
                 NameSurname = q.NameSurname,
                 Branch = w.Text,
                 Class = e.Text,
                 Departman = p.Text,
                 StudentNo = q.StudentNo,
                 Faculty = s.Text,
                 Photo = q.Photo,
                 AuthType = loginUser.AuthType
             }).SingleOrDefault();
             return(View(detail));
         }
         else
         {
             HomePageViewModel detail = (from q in ent.Educator
                                         join p in ent.Parameter on q.DepartmanID equals p.ParameterID
                                         join s in ent.Parameter on q.FacultyID equals s.ParameterID
                                         where q.SicilNo == loginUser.SicilNo
                                         select new HomePageViewModel
             {
                 SicilNo = q.SicilNo,
                 NameSurname = q.NameSurname,
                 Departman = p.Text,
                 Faculty = s.Text,
                 Photo = q.Photo,
                 AuthType = loginUser.AuthType
             }).SingleOrDefault();
             return(View(detail));
         }
     }
 }
        // GET: DersBilgileri
        public ActionResult Index()
        {
            using (SduEntities ent = new SduEntities())
            {
                var std = GetLoginUser();

                List <ListLessonsViewModel> list = (from q in ent.Lesson
                                                    join p in ent.Educator on q.EducatorID equals p.EducatorID
                                                    where q.StudentNo == std.StudentNo
                                                    select new ListLessonsViewModel
                {
                    LessonCode = q.LessonCode,
                    EducatorName = p.NameSurname,
                    LessonName = q.LessonName,
                    Max = q.MaxContinuity
                }).OrderBy(q => q.LessonCode).ToList();
                return(View(list));
            }
        }
        public IHttpActionResult Yoklama(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                using (SduEntities ent = new SduEntities())
                {
                    var control = ent.Student.Where(q => q.CardNo == id).Select(q => q).SingleOrDefault();
                    if (control != null)
                    {
                        YoklamaController cnt = new YoklamaController();
                        cnt.dosyayaYaz(control.Photo, control.StudentNo, control.NameSurname);
                    }
                }
            }
            Response rsp = new Response();

            rsp.response = id;
            return(Json(rsp));
        }
 public ActionResult UpdatePassword(SettingsViewModel settings)
 {
     if (ModelState.IsValid)
     {
         using (SduEntities ent = new SduEntities())
         {
             var loginUser = GetLoginUser();
             if (loginUser.AuthType == (int)EnumAuthType.Ogrenci)
             {
                 var update = ent.Student.Where(q => q.StudentID == settings.ID && q.Password == settings.CurrentPassword).Select(q => q).SingleOrDefault();
                 if (update != null)
                 {
                     update.Password = settings.NewPassword;
                     ent.SaveChanges();
                 }
                 else
                 {
                     Session["toastError"] = "error";
                     return(View("Index", settings));
                 }
             }
             else
             {
                 var update = ent.Educator.Where(q => q.EducatorID == settings.ID && q.Password == settings.CurrentPassword).Select(q => q).SingleOrDefault();
                 if (update != null)
                 {
                     update.Password = settings.NewPassword;
                     ent.SaveChanges();
                 }
                 else
                 {
                     Session["toastError"] = "error";
                     return(View("Index", settings));
                 }
             }
         }
         return(RedirectToAction("Logout", "Giris"));
     }
     else
     {
         return(View("Index", settings));
     }
 }