Beispiel #1
0
        internal void CreateNewFaculty(NewFacultyViewModel model, int?uniId)
        {
            using (var db = new ErasmusDbContext())
            {
                if (model.Id.HasValue)
                {
                    //Edit functionality
                    var faculty = db.Faculties.SingleOrDefault(x => x.Id == model.Id);
                    if (faculty == null)
                    {
                        throw new FormValidationException("Invalid faculty provided");
                    }

                    var fieldsOfStudy = new List <FieldOfStudy>();
                    if (model.SelectedFos != null && model.SelectedFos.Any())
                    {
                        fieldsOfStudy = db.FieldsOfStudy.Where(x => model.SelectedFos.Contains(x.Id)).ToList();
                        if (fieldsOfStudy.Count != model.SelectedFos.Count)
                        {
                            throw new ValidationException("Some fields of study were not found.");
                        }
                    }

                    var oldFos = faculty.StudyFields;
                    foreach (var fos in oldFos)
                    {
                        //Reset fos if removed
                        fos.FacultyId = null;
                    }
                    db.SaveChanges();

                    faculty.Name        = model.Name;
                    faculty.StudyFields = fieldsOfStudy;
                    db.SaveChanges();
                    return;
                }
                else
                {
                    //New functionality
                    var fieldsOfStudy = new List <FieldOfStudy>();
                    if (model.SelectedFos != null && model.SelectedFos.Any())
                    {
                        fieldsOfStudy = db.FieldsOfStudy.Where(x => model.SelectedFos.Contains(x.Id)).ToList();
                        if (fieldsOfStudy.Count != model.SelectedFos.Count)
                        {
                            throw new ValidationException("Some fields of study were not found.");
                        }
                    }

                    db.Faculties.Add(new Faculty()
                    {
                        Name         = model.Name,
                        StudyFields  = fieldsOfStudy,
                        UniversityId = uniId
                    });

                    db.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public NewFacultyViewModel GetNewFacultyViewModel(int?uniId)
        {
            var model = new NewFacultyViewModel();

            using (var db = new ErasmusDbContext())
            {
                model.StudyFields = new MultiSelectList(db.FieldsOfStudy.Where(x => x.UniversityId == uniId).ToList().Select(x =>
                                                                                                                             new KeyValueIntStr()
                {
                    Key   = x.Id,
                    Value = x.Name
                }), "Key", "Value");
            }
            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// Security hole, never expose returned identity directly to view.
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public List <ErasmusUser> GetUsersListByRole(string roleName)
        {
            var model = new NewFacultyViewModel();

            using (var db = new ErasmusDbContext())
            {
                var role = db.Roles.SingleOrDefault(x => x.Name == roleName);
                if (role == null)
                {
                    return(new List <ErasmusUser>());
                }
                var userIds = role.Users.Select(x => x.UserId).ToList();
                var users   = db.Users.Where(x => userIds.Contains(x.Id)).ToList();
                return(users);
            }
        }
 public ActionResult NewFaculty(NewFacultyViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _adminBusinessLogic.CreateNewFaculty(model);
             ViewData.Add("LastActionResult", "Faculty created");
             return(RedirectToActionPermanent("Faculties"));
         }
         return(View(model));
     }
     catch (Exception e)
     {
         return(Json(new { result = "ERROR", message = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #5
0
        public void CreateNewFaculty(NewFacultyViewModel model)
        {
            using (var db = new ErasmusDbContext())
            {
                var fieldsOfStudy = db.FieldsOfStudy.Where(x => model.SelectedFos.Contains(x.Id)).ToList();
                if (fieldsOfStudy.Count != model.SelectedFos.Count)
                {
                    throw new ValidationException("Some fields of study were not found.");
                }

                db.Faculties.Add(new Faculty()
                {
                    Name        = model.Name,
                    StudyFields = fieldsOfStudy
                });

                db.SaveChanges();
            }
        }
 public ActionResult Admin_Login(Admin admin)
 {
     var email = admin.Email;
     var pass = admin.Password;
     //var data = db.Admins.Where(add => add.Password.Trim() == pass && add.Admin_Id == id).FirstOrDefault();
     var data = db.Admins.Where(add => add.Password == pass && add.Email.Trim()==email).FirstOrDefault();
     if (data != null && Session["myid"]==null)
     {  
         Session["myid"] = email;
         Session["username"] = "******";
         var Department = db.Departments.ToList();
         var viewModel = new NewFacultyViewModel()
         {
             department = Department
         };
         return View("Admin_level1", viewModel);
     }
      return RedirectToAction("Admin_Login");
     //return RedirectToAction("Submit");
 }
Beispiel #7
0
        public NewFacultyViewModel GetNewFacultyViewModel(int?uniId, int id)
        {
            var model = new NewFacultyViewModel();

            using (var db = new ErasmusDbContext())
            {
                var faculty = db.Faculties.SingleOrDefault(x => x.Id == id && x.UniversityId == uniId);
                if (faculty == null)
                {
                    throw new FormValidationException("Invalid faculty");
                }
                model.Id          = faculty.Id;
                model.Name        = faculty.Name;
                model.SelectedFos = faculty.StudyFields.Select(x => x.Id).ToList();

                model.StudyFields = new MultiSelectList(db.FieldsOfStudy.Where(x => x.UniversityId == uniId).ToList().Select(x =>
                                                                                                                             new KeyValueIntStr()
                {
                    Key   = x.Id,
                    Value = x.Name
                }), "Key", "Value", model.SelectedFos);
            }
            return(model);
        }