private void UpdateCurs(string cursNume, Teacher t1, string numevechi1)
        {
            using (var context = new EducatieIncluzivaDBContext())
            {
                Course curs = (from p in context.Courses
                               where p.ProfesorId == t1.UserId && p.Nume.Equals(numevechi1)
                               select p).FirstOrDefault();

                if (curs != null)
                {
                    curs.Nume = cursNume;
                    DbEntityEntry <Course> entry = context.Entry(curs);
                    entry.State = EntityState.Modified;
                    context.SaveChanges();
                }
                else
                {
                    Course cur = new Course();
                    cur.Nume       = cursNume;
                    cur.ProfesorId = t1.UserId;
                    context.Courses.Add(cur);
                    context.SaveChanges();
                }
            }
        }
Exemple #2
0
        public ActionResult RegisterElevi(ElevRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                ResourcesRepository rr = new ResourcesRepository();
                HighSchool          hs = rr.GetHighSchoolByName(model.ScoalaDeProvenienta);

                Student elev = new Student(model.Parola, model.Nume, model.Prenume, model.Mail, hs);

                //User user = new User(model.Parola, model.Nume, model.Prenume, model.Mail);

                using (var db = new EducatieIncluzivaDBContext())
                {
                    //db.Useri.Add(user);
                    db.Entry(hs).State = EntityState.Unchanged;
                    db.Students.Add(elev);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    FormsAuthentication.SetAuthCookie(model.Mail, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View());
        }
 public void UpdateTeacher(string mail, string imageUrl)
 {
     using (var context = new EducatieIncluzivaDBContext())
     {
         var teacher = this.GetProfesoriByMail(mail);
         teacher.ImageUrl = imageUrl;
         context.Teachers.Attach(teacher);
         context.Entry(teacher).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
        public void UpdateTeacher(string nume, string prenume,
                                  string mail, string bio,
                                  string numevechi1, string numevechi2, string c1, string c2)
        {
            using (var context = new EducatieIncluzivaDBContext())
            {
                // get the teacher
                var theUser = this.GetProfesoriByMail(mail);

                //update general info about the teacher
                theUser.Description = bio;
                theUser.Mail        = mail;
                theUser.Nume        = nume;
                theUser.Prenume     = prenume;


                /* Course cur = new Course();
                 * cur.Nume = c1;
                 * Course cur2 = new Course();
                 * cur2.Nume = c2;
                 *
                 * cur.ProfesorId = theUser.UserId;
                 * cur2.ProfesorId = theUser.UserId;
                 *
                 * //if the teacher already has some courses
                 * if (theUser.Materii != null)
                 * {
                 *   if (!theUser.Materii.Contains(cur))
                 *   {
                 *       context.Courses.Add(cur);
                 *   }
                 *   if (!theUser.Materii.Contains(cur2))
                 *   {
                 *       context.Courses.Add(cur2);
                 *   }
                 * }
                 * else
                 * {
                 *   context.Courses.Add(cur);
                 *   context.Courses.Add(cur2);
                 *
                 * }
                 */
                UpdateCurs(c1, theUser, numevechi1);
                UpdateCurs(c2, theUser, numevechi2);

                DbEntityEntry <Teacher> entry = context.Entry(theUser);
                entry.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public void UpdateUser(string parola, string nume, string prenume, string mail,
                               HighSchool scoalaDeProvenienta)
        {
            using (var context = new EducatieIncluzivaDBContext())
            {
                var theUser = this.GetUserByMail(mail);
                theUser.Parola              = parola == null ? theUser.Parola : parola;
                theUser.Nume                = nume == null ? theUser.Nume : nume;
                theUser.Prenume             = prenume == null ? theUser.Prenume : prenume;
                theUser.Mail                = mail == null ? theUser.Mail : mail;
                theUser.ScoalaDeProvenienta = (scoalaDeProvenienta == theUser.ScoalaDeProvenienta) ? theUser.ScoalaDeProvenienta : scoalaDeProvenienta;

                context.Users.Attach(theUser);
                context.Entry(theUser).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public void UpdateTeacher(string nume, string prenume,
                                  string mail, string bio,
                                  string numevechi1, string numevechi2, string numevechi3, string c2, string c1, string c3)
        {
            using (var context = new EducatieIncluzivaDBContext())
            {
                // get the teacher
                var theUser = this.GetProfesoriByMail(mail);

                //update general info about the teacher
                theUser.Description = bio;
                theUser.Mail        = mail;
                theUser.Nume        = nume;
                theUser.Prenume     = prenume;

                UpdateCurs(c1, theUser, numevechi1);
                UpdateCurs(c2, theUser, numevechi2);
                UpdateCurs(c3, theUser, numevechi3);

                DbEntityEntry <Teacher> entry = context.Entry(theUser);
                entry.State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public ActionResult AddLesson(HttpPostedFileBase file, string mail, string materie)
        {
            var rr = new ResourcesRepository();

            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                ViewData["fileUp"] = null;
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var subPath = "~/App_Data/uploads/" + mail;

                bool IsExists = System.IO.Directory.Exists(Server.MapPath(subPath));

                if (!IsExists)
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
                }

                var subPath2 = "~/App_Data/uploads/" + mail + "/" + materie;

                bool IsExists2 = System.IO.Directory.Exists(Server.MapPath(subPath2));

                if (!IsExists2)
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(subPath2));
                }

                var path = Path.Combine(Server.MapPath("~/App_Data/uploads/"), mail + "/", materie, fileName);
                file.SaveAs(path);


                using (var db = new EducatieIncluzivaDBContext())
                {
                    var myTeacher = db.Teachers.SingleOrDefault(item => item.Mail == mail);
                    var curs      = from p in db.Courses
                                    where p.Nume.Equals(materie) && p.ProfesorId == myTeacher.UserId
                                    select p;

                    /*  Course cur = new Course();
                     * cur.Nume = materie;
                     * cur.ProfesorId = myTeacher.UserId;
                     */
                    Lesson l = new Lesson();
                    l.ProfesorOwner   = myTeacher;
                    l.ProfesorOwnerId = myTeacher.UserId;
                    l.Titlu           = fileName;

                    foreach (var c in curs)
                    {
                        c.Lectii.Add(l);
                        break;
                    }

                    /*  if (myTeacher.Materii != null)
                     * {
                     *    if (myTeacher.Materii.Contains(cur))
                     *    {
                     *        db.Lessons.Add(l);
                     *    }
                     *    else
                     *    {
                     *        Console.WriteLine("Nu exista");
                     *    }
                     * }
                     * else
                     * {
                     *    Console.WriteLine("e NULL");
                     * }
                     * /*
                     * if (myTeacher.Materii[0].Nume.Equals(materie))
                     * {
                     *    nr = 0;
                     * }
                     * else if (myTeacher.Materii[1].Nume.Equals(materie))
                     * {
                     *    nr = 1;
                     * }
                     * else
                     * {
                     *    nr = 2;
                     * }
                     * myTeacher.Materii[nr].Lectii.Add(l);
                     */
                    DbEntityEntry <Teacher> entry = db.Entry(myTeacher);
                    entry.State = EntityState.Modified;

                    db.SaveChanges();

                    ViewData["fileUp"]  = "incarcat";
                    ViewData["materie"] = materie;
                }
            }

            var model = rr.GetUserByMail(mail);

            // redirect back to the index action to show the form once again
            return(View("../../Views/AddLesson/AddLesson", model));
        }