public ActionResult PutGrade(int?subjectId, int?schoolKidId)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsAdmin())
            {
                if (!IsTeacher())
                {
                    return(Redirect("/Admin/LoginPage/?noPermission"));
                }
            }
            ViewBag.SchoolKidId = new SelectList(db.SchoolKids, "Id", "Name");
            ViewBag.SubjectId   = new SelectList(db.Subjects, "Id", "Name");

            IQueryable <SchoolKid> schoolKids = db.SchoolKids.Include(s => s.Group);
            IQueryable <Subject>   subjects   = db.Subjects.Include(s => s.Group);

            Subject   subject   = subjects.First(s => s.Id == subjectId);
            SchoolKid schoolKid = schoolKids.First(s => s.Id == schoolKidId);

            ViewBag.subject   = subject;
            ViewBag.schoolKid = schoolKid;
            return(View());
        }
        // GET: SchoolKids/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsAdmin())
            {
                return(Redirect("/Admin/LoginPage/?noPermission"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolKid schoolKid = await db.SchoolKids.FindAsync(id);

            if (schoolKid == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FatherId = new SelectList(db.Parents, "Id", "Login", schoolKid.FatherId);
            ViewBag.GroupId  = new SelectList(db.Groups, "Id", "Name", schoolKid.GroupId);
            ViewBag.MotherId = new SelectList(db.Parents, "Id", "Login", schoolKid.MotherId);
            ViewBag.SchoolId = new SelectList(db.Schools, "Id", "Name", schoolKid.SchoolId);
            return(View(schoolKid));
        }
Exemple #3
0
        public void Delete(int id)
        {
            SchoolKid c = db.SchoolKids.Find(id);

            if (c != null)
            {
                db.SchoolKids.Remove(c);
            }
        }
        public ActionResult SearchStudent(string RecordBookNumberID)
        {
            if (RecordBookNumberID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SchoolKid student = db.SchoolKids.Find(RecordBookNumberID);


            return(View("SearchStudentResults", student));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsAdmin())
            {
                return(Redirect("/Admin/LoginPage/?noPermission"));
            }
            SchoolKid schoolKid = await db.SchoolKids.FindAsync(id);

            db.SchoolKids.Remove(schoolKid);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        // GET: SchoolKids/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolKid schoolKid = await db.SchoolKids.FindAsync(id);

            if (schoolKid == null)
            {
                return(HttpNotFound());
            }
            return(View(schoolKid));
        }
        public ActionResult SendMessage(gmail model, int?subjectId, int?schoolKidId)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            MailMessage mm = new MailMessage("*****@*****.**", model.To);

            mm.Subject    = model.Subject;
            mm.Body       = model.Body;
            mm.IsBodyHtml = false;
            SmtpClient smtp = new SmtpClient();

            smtp.Host      = "smtp.gmail.com";
            smtp.Port      = 587;
            smtp.EnableSsl = true;
            NetworkCredential networkCredential = new NetworkCredential("*****@*****.**", "kundelik2020csharp");

            smtp.UseDefaultCredentials = true;
            smtp.Credentials           = networkCredential;
            smtp.Send(mm);

            IQueryable <Parent>    parents    = db.Parents;
            IQueryable <Subject>   subjects   = db.Subjects.Include(s => s.Group);
            IQueryable <SchoolKid> schoolKids = db.SchoolKids.Include(s => s.Group);

            Subject   subject   = subjects.First(s => s.Id == subjectId);
            SchoolKid schoolKid = schoolKids.First(s => s.Id == schoolKidId);


            IQueryable <Grade> grades = db.Grades.Include(g => g.SchoolKid).Include(g => g.Subject);

            grades = grades.Where(g => g.SchoolKidId == schoolKidId);
            grades = grades.Where(g => g.SubjectId == subjectId);

            ViewBag.subject   = subject;
            ViewBag.schoolKid = schoolKid;
            ViewBag.Message   = "Mail Has Been Sent Succesfully!";


            return(View());
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Login,Password,Name,Surname,MotherId,FatherId,SchoolId,GroupId")] SchoolKid schoolKid)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsAdmin())
            {
                return(Redirect("/Admin/LoginPage/?noPermission"));
            }
            if (ModelState.IsValid)
            {
                db.Entry(schoolKid).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.FatherId = new SelectList(db.Parents, "Id", "Login", schoolKid.FatherId);
            ViewBag.GroupId  = new SelectList(db.Groups, "Id", "Name", schoolKid.GroupId);
            ViewBag.MotherId = new SelectList(db.Parents, "Id", "Login", schoolKid.MotherId);
            ViewBag.SchoolId = new SelectList(db.Schools, "Id", "Name", schoolKid.SchoolId);
            return(View(schoolKid));
        }
        public ActionResult MessagePage(int?subjectId, int?schoolKidId)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            IQueryable <Parent>    parents    = db.Parents;
            IQueryable <Subject>   subjects   = db.Subjects.Include(s => s.Group);
            IQueryable <SchoolKid> schoolKids = db.SchoolKids.Include(s => s.Group);

            Subject   subject   = subjects.First(s => s.Id == subjectId);
            SchoolKid schoolKid = schoolKids.First(s => s.Id == schoolKidId);


            IQueryable <Grade> grades = db.Grades.Include(g => g.SchoolKid).Include(g => g.Subject);

            grades = grades.Where(g => g.SchoolKidId == schoolKidId);
            grades = grades.Where(g => g.SubjectId == subjectId);

            ViewBag.subject   = subject;
            ViewBag.schoolKid = schoolKid;
            return(View("SendMessage"));
        }
Exemple #10
0
 public void Update(SchoolKid c)
 {
     db.Entry(c).State = EntityState.Modified;
 }
Exemple #11
0
 public void Create(SchoolKid c)
 {
     db.SchoolKids.Add(c);
 }
        public ActionResult ParentPage(int?parent)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsAdmin())
            {
                if (!IsParent())
                {
                    return(Redirect("/Admin/LoginPage/?noPermission"));
                }
            }
            IQueryable <Grade>     grades      = db.Grades.Include(s => s.SchoolKid).Include(s => s.Subject);
            IQueryable <SchoolKid> schoolKids1 = db.SchoolKids.Include(s => s.Mother).Include(s => s.Father);

            if (parent != null && parent != 0)
            {
                if (IsAdmin())
                {
                    SchoolKid schoolKid = schoolKids1.First(s => s.MotherId == parent);
                    if (schoolKid == null)
                    {
                        schoolKid = schoolKids1.First(s => s.FatherId == parent);
                    }
                    grades = grades.Where(s => s.SchoolKidId == schoolKid.Id);
                }
                else
                {
                    return(Redirect("/Admin/LoginPage/?noPermission"));
                }
            }
            else
            {
                IQueryable <Parent> parents1 = db.Parents;
                Parent parent1 = null;
                string email   = (string)Session["currentUser"];
                foreach (Parent p in parents1)
                {
                    if (p.Login == email)
                    {
                        parent1 = p;
                        break;
                    }
                }
                if (parent1 != null)
                {
                    SchoolKid schoolKid = schoolKids1.First(s => s.MotherId == parent1.Id);
                    if (schoolKid == null)
                    {
                        schoolKid = schoolKids1.First(s => s.FatherId == parent1.Id);
                    }
                    grades = grades.Where(s => s.SchoolKidId == schoolKid.Id);
                }
            }

            List <Parent> parents = db.Parents.ToList();

            // устанавливаем начальный элемент, который позволит выбрать всех
            parents.Insert(0, new Parent {
                Name = "Все", Id = 0
            });

            GradeListViewModel plvm = new GradeListViewModel
            {
                Grades  = grades.Include(s => s.SchoolKid).Include(s => s.Subject).ToList(),
                Parents = new SelectList(parents, "Id", "Name")
            };

            return(View(plvm));
        }
        public ActionResult SchoolKidPage(int?schoolKid)
        {
            if (!isAuthenticate())
            {
                return(Redirect("/Admin/LoginPage/?error"));
            }
            if (!IsParent())
            {
                IQueryable <Grade> grades = db.Grades.Include(s => s.SchoolKid).Include(s => s.Subject);
                if (schoolKid != null && schoolKid != 0)
                {
                    if (!IsSchoolKid())
                    {
                        if (!IsParent())
                        {
                            grades = grades.Where(s => s.SchoolKidId == schoolKid);
                        }
                        else
                        {
                            return(Redirect("/Admin/LoginPage/?noPermission"));
                        }
                    }
                    else
                    {
                        return(Redirect("/Admin/LoginPage/?noPermission"));
                    }
                }
                else
                {
                    IQueryable <SchoolKid> schoolKids0 = db.SchoolKids;
                    SchoolKid schoolKid1 = null;
                    string    email      = (string)Session["currentUser"];
                    foreach (SchoolKid s in schoolKids0)
                    {
                        if (s.Login == email)
                        {
                            schoolKid1 = s;
                            break;
                        }
                    }
                    if (schoolKid1 != null)
                    {
                        grades = grades.Where(s => s.SchoolKidId == schoolKid1.Id);
                    }
                }

                List <SchoolKid> schoolKids = db.SchoolKids.ToList();
                // устанавливаем начальный элемент, который позволит выбрать всех
                schoolKids.Insert(0, new SchoolKid {
                    Name = "Все", Id = 0
                });

                GradeListViewModel plvm = new GradeListViewModel
                {
                    Grades     = grades.ToList(),
                    SchoolKids = new SelectList(schoolKids, "Id", "Name")
                };
                return(View(plvm));
            }
            else
            {
                return(Redirect("/Admin/LoginPage/?noPermission"));
            }
        }