public void InsertOrUpdate(Student student)
 {
     if (student.StudentId == 0) //new
     {
         context.Students.Add(student);
     }
     else //edit
     {
         context.Entry(student).State = EntityState.Modified;
     }
 }
        public void EditTest1()
        {
            Mock<IStudentsRepository> repoMock = new Mock<IStudentsRepository>();
            Mock<IEmailer> emailMock = new Mock<IEmailer>();
            //StudentsController controller = new StudentsController(repoMock.Object, emailMock.Object);
            Student x = new Student {StudentId = 2};
            //controller.Edit(x.StudentId);

            repoMock.Verify(a => a.InsertOrUpdate(x));

            //Assert.Fail();
        }
Example #3
0
 public ActionResult Create(Student student, HttpPostedFileBase image, IEnumerable<int> compIds)
 {
     //save to db.
     if (ModelState.IsValid)
     {
         studentsRepository.InsertOrUpdate(student, image);
         return View("Thanks");
     }
     else
     {
         return View();
     }
 }
        public ActionResult Edit(Student student, HttpPostedFileBase image)
        {
            //save to db.
            //if you edit student
            if (ModelState.IsValid)
            {
                studentsRepository.InsertOrUpdate(student);
                student.SaveImage(image, Server.MapPath("~"), "/ProfileImages/");
                studentsRepository.Save();
                return RedirectToAction("Index");
            }

            return View(student);
        }
Example #5
0
 public ActionResult Delete(Student student)
 {
     //save to db.
     if (ModelState.IsValid)
     {
         int id = student.StudentId;
         studentsRepository.Delete(id);
         return RedirectToAction("Index");
     }
     else
     {
         return View(student);
     }
 }
Example #6
0
 public void InsertOrUpdate(Student student, HttpPostedFileBase image)
 {
     if (student.StudentId == 0) //new
     {
         dbContext.Students.Add(student);
         student.SaveImage(image, HostingEnvironment.MapPath("~"), "/UserUploads/");
         Save();
     }
     else //edit
     {
         dbContext.Entry(student).State = EntityState.Modified;
         student.SaveImage(image, HostingEnvironment.MapPath("~"), "/UserUploads/");
         Save();
     }
 }
        public ActionResult Create(Student student, 
            HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                studentsRepository.InsertOrUpdate(student);
                student.SaveImage(image, Server.MapPath("~"), "/ProfileImages/");
                studentsRepository.Save();

                return View("Thanks");
            }
            else
            {
                return View();
            }
        }
        public void TestMethod1()
        {
            Mock<IStudentsRepository> mockRepo = new Mock<IStudentsRepository>();

            StudentsController studentsController = new StudentsController(mockRepo.Object);

            Student s = new Student
            {
                Firstname = "Daniel",
                Lastname = "Something"
            };

            studentsController.Create(s, null);

            mockRepo.Verify(a => a.InsertOrUpdate(s, null));
            mockRepo.Verify(a => a.Save());
        }
        public void TestMethodEmail()
        {
            Mock<IStudentsRepository> mockRepo =
                new Mock<IStudentsRepository>();
            Mock<IEmailer> fakeEmailer = new Mock<IEmailer>();

            StudentsController controller =
                new StudentsController(mockRepo.Object, fakeEmailer.Object);

            Student s = new Student
            {
                Firstname = "Daniel",
                Lastname = "Something"
            };

            //controller.Create(s, null);

            fakeEmailer.Verify(a=>a.Send("Welcome to our website..."));
        }
        public ActionResult Create(Student student, 
            HttpPostedFileBase image, IEnumerable<int> compIds)
        {
            if (ModelState.IsValid)
            {
                studentsRepository.InsertOrUpdate(student);

                string path = Server != null ? Server.MapPath("~") : "";

                student.SaveImage(image, path , "/ProfileImages/");
                studentsRepository.Save();
                _emailer.Send("Welcome to our website...");
                return View("Thanks");
            }
            else
            {
                return View();
            }
        }
        public void TestMethod1()
        {
            //Arrange
            Mock<IStudentsRepository> mockRepo =
                new Mock<IStudentsRepository>();

            StudentsController controller =
                new StudentsController(mockRepo.Object, null);

            Student s = new Student
            {
                Firstname = "Daniel",
                Lastname = "Something"
            };

            //Act - Where you call the method to test
            //controller.Create(s, null);

            //Assert - verify that insertorupdate was called
            mockRepo.Verify(a=>a.InsertOrUpdate(s));
            mockRepo.Verify(a=>a.Save());
        }
        public void InsertOrUpdate(Student student)
        {
            if (student.StudentId == 0) //new : if no primary key is defined for the object
            {
                db.Students.Add(student);

            }
            else //edit
            {

                //student.SaveImage(image, Server.MapPath("~"), "/ProfileImages/");

                db.Entry(student).State = EntityState.Modified;

            }
            Save();
        }
Example #13
0
 public ActionResult Edit(Student student, HttpPostedFileBase image)
 {
     //save to db.
     if (ModelState.IsValid)
     {
         studentsRepository.InsertOrUpdate(student, image);
         return RedirectToAction("Index");
     }
     else
     {
         return View(student);
     }
 }
        public ActionResult Edit(Student student, HttpPostedFileBase image, IEnumerable<int> compIds)
        {
            //String serverPath = Server.MapPath("~");
            //String FolderName = "/UserUploads/";

            ICollection<Competency> list = new List<Competency>();
            foreach (int i in compIds)
            {
                list.Add(CompRepo.Find(i));
            }

            student.Competencies = list;

            if (image != null)
            {
                //delete the old image first?
                //student.RemoveImage(serverPath);
                student.SaveOrUpdateImage(image, Server.MapPath("~"), "/UserUploads/");

            }

            if (ModelState.IsValid)
            {
                foreach(Competency c in list)
                {
                    //update the shared table StudentCompetencies
                    c.Students.Add(student);
                    CompRepo.InsertOrUpdate(c);
                }

                repo.InsertOrUpdate(student);

                return RedirectToAction("Index");
            }
            //giver null pointer fordi vm ikke er udfyldt
            return View("Index");
        }
        public ActionResult Edit(Student student)
        {
            //save to db.
            //if you edit student
            if (ModelState.IsValid)
            {
                studentsRepository.InsertOrUpdate(student);
                studentsRepository.Save();
                return RedirectToAction("Index");
            }

            return View(student);
        }
        // Creates a ViewBag with a list of AssignedCompetencyData (all competencies with flags if they are currently assigned to the student or not)
        private void PopulateAssignedCompetencyData(Student student)
        {
            var allCompetencies = _competenciesRepository.All;
            var studentCompetencies = new HashSet<int>(student.Competencies.Select(c => c.CompetencyId));
            var viewModel = new List<AssignedCompetencyData>();

            foreach (var competency in allCompetencies)
            {
                viewModel.Add(new AssignedCompetencyData()
                {
                    CompetencyId = competency.CompetencyId,
                    Name = competency.Name,
                    Assigned = studentCompetencies.Contains(competency.CompetencyId)
                });
            }

            ViewBag.Competencies = viewModel;
        }
        public ActionResult Edit(Student student, HttpPostedFileBase image, IEnumerable<int> compIds)
        {
            if (ModelState.IsValid)
            {
                //student.SaveImage(image, Server.MapPath("~"), "/ProfileImages/");
                string path = Server != null ? Server.MapPath("~") : "";
                student.SaveImage(image, path, "/ProfileImages/");

                HandleStudentHelper handleStudentHelper = new HandleStudentHelper(student, compIds);
                handleStudentHelper.HandleStudent(true);

                return RedirectToAction("Index");
            }

            CreateEditStudentViewModel viewModel = new CreateEditStudentViewModel()
            {
                Student = student,
                Educations = _educationsRepository.All.ToList(),
                CompetencyHeaders = _competencyHeadersRepository.AllIncluding(a => a.Competencies).ToList()
            };
            return View(viewModel);
        }
        public async Task<ActionResult> Register(RegisterViewModel model, Student student,
                            HttpPostedFileBase image, IEnumerable<int> compIds)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    student.ApplicationUserId = user.Id;

                    //student.SaveImage(image, Server.MapPath("~"), "/ProfileImages/");
                    string path = Server != null ? Server.MapPath("~") : "";
                    student.SaveImage(image, path, "/ProfileImages/");

                    // Creates a UnitOfWork object (for saving different DbSet in one session to db) and creates a list of all 
                    // competencies to the student and save student to db. This code is also used in the StudentsController 
                    // in the Register method
                    HandleStudentHelper handleStudentHelper = new HandleStudentHelper(student, compIds);
                    handleStudentHelper.HandleStudent(null);

                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public HandleStudentHelper(Student student, IEnumerable<int> compIds)
 {
     this._student = student;
     this._compIds = compIds;
 }
        public async Task<ActionResult> Register(RegisterViewModel model, Student student)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //Save student object to database
                    StudentsRepository studentsRepository = new StudentsRepository();
                    student.ApplicationUserId = user.Id;
                    studentsRepository.InsertOrUpdate(student);
                    studentsRepository.Save();

                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }