public IHttpActionResult GetAllInstructors()
        {
            var svc         = new InstructorService();
            var instructors = svc.GetAllInstructors();

            return(Ok(instructors));
        }
        public IHttpActionResult GetInstructorByID([FromUri] int instructorID)
        {
            var svc        = new InstructorService();
            var instructor = svc.GetInstructorByID(instructorID);

            return(Ok(instructor));
        }
        public IHttpActionResult GetInstructorsByLocation([FromUri] int locationID)
        {
            var svc         = new InstructorService();
            var instructors = svc.GetInstructorsByLocation(locationID);

            return(Ok(instructors));
        }
Exemplo n.º 4
0
        public Instructor GetInstructorInfo(int instructorId)
        {
            var service = new InstructorService(new InstructorRepository());
            var errors  = new List <string>();

            return(service.GetInstructorInfo(instructorId, ref errors));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Delete(int?id)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            await instructorService.Delete(id.Value);

            return(RedirectToAction("Index", "Instructors"));
        }
        public IHttpActionResult GetInstructorsByCourse([FromUri] int courseID)
        {
            var svc         = new InstructorService();
            var instructors = svc.GetInstructorsByCourse(courseID);

            return(Ok(instructors));
        }
Exemplo n.º 7
0
        public void CreateInstructor_UnderNormalConditions_AddsInstructorToInstructorList()
        {
            //arrange
            var instructorToBeCreated = new InstructorDto()
            {
                InstructorName = "test instructor name",
                IsActive       = true
            };

            var originalCountOfInstructors = _instructorList.Count;

            var mockInstructorRepo = Mock.Create <IInstructorRepository>();

            Mock.Arrange(() => mockInstructorRepo.Create(Arg.IsAny <Instructor>()))
            .DoInstead(() => _instructorList.Add(instructorToBeCreated))
            .OccursOnce();

            _instructorService = new InstructorService(mockInstructorRepo);

            //act

            _instructorService.Create(instructorToBeCreated);
            var actualCount = _instructorList.Count;

            //assert
            Mock.Assert(mockInstructorRepo);
            Assert.That(actualCount, Is.EqualTo(originalCountOfInstructors + 1));
        }
Exemplo n.º 8
0
        public async Task UpdateInstructor_UpdatesExistingInstructor()
        {
            var instructor = new Instructor
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            using (var context = new ApplicationDbContext(Options))
            {
                context.Instructors.Add(instructor);
                context.SaveChanges();
            }

            instructor.FirstName = "Jane";
            instructor.LastName  = "Other";
            using (var context = new ApplicationDbContext(Options))
            {
                var        service           = new InstructorService(context);
                Instructor updatedInstructor = await service.UpdateInstructor(instructor);

                Assert.AreEqual(instructor, updatedInstructor);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                Instructor retrievedInstructor = context.Instructors.Single();
                Assert.AreEqual(instructor.Id, retrievedInstructor.Id);
                Assert.AreEqual(instructor.FirstName, retrievedInstructor.FirstName);
                Assert.AreEqual(instructor.LastName, retrievedInstructor.LastName);
            }
        }
Exemplo n.º 9
0
        public async Task AddInstructor_PersistsInstructor()
        {
            var instructor = new Instructor
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            using (var context = new ApplicationDbContext(Options))
            {
                var service = new InstructorService(context);

                Instructor addedInstructor = await service.AddInstructor(instructor);

                Assert.AreEqual(addedInstructor, instructor);
                Assert.AreNotEqual(0, addedInstructor.Id);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                Instructor retrievedInstructor = context.Instructors.Single();
                Assert.AreEqual(instructor.FirstName, retrievedInstructor.FirstName);
                Assert.AreEqual(instructor.LastName, retrievedInstructor.LastName);
            }
        }
Exemplo n.º 10
0
        private InstructorService GetInstructorService()
        {
            var userId  = User.Identity.GetUserId();
            var service = new InstructorService(userId);

            return(service);
        }
Exemplo n.º 11
0
 public SchoolFactory()
 {
     StudentService    = new StudentService(new StudentDAO());
     InstructorService = new InstructorService(new InstructorDAO());
     CourseService     = new CourseService(new CourseDAO());
     UserService       = new UserService(new UserDAO());
 }
Exemplo n.º 12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         InstructorService instructorService = new InstructorService();
         repeaterInstructor.DataSource = instructorService.GetAllInstructor();
         repeaterInstructor.DataBind();
     }
 }
Exemplo n.º 13
0
        public async Task <ActionResult> Edit(int?id)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            var instructor        = await instructorService.GetById(id.Value);

            var instructorDTO = mapper.Map <InstructorDTO>(instructor);

            return(View(instructorDTO));
        }
Exemplo n.º 14
0
        // GET: Instructor
        public ActionResult Index()
        {
            ContosoContext       cc = new ContosoContext();
            InstructorRepository ir = new InstructorRepository(cc);
            InstructorService    instructorService = new InstructorService(ir);
            var instructor = instructorService.GetAllInstructors();

            return(View(instructor));
        }
Exemplo n.º 15
0
        public async Task <ActionResult> Create()
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            var instructors       = await instructorService.GetAll();

            var instructorsDTO = instructors.Select(x => mapper.Map <InstructorDTO>(x));

            ViewData["Instructors"] = new SelectList(instructorsDTO, "ID", "FullName");
            return(View());
        }
        public IHttpActionResult DeleteInstructor([FromUri] int instructorID)
        {
            var svc = new InstructorService();

            if (!svc.DeleteInstructor(instructorID))
            {
                return(InternalServerError());
            }
            return(Ok("Instructor successfully deleted."));
        }
Exemplo n.º 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var instructorID = Request.QueryString["ID"];
         InstructorService instructorService = new InstructorService();
         var instructor = instructorService.GetOneInstructor(Convert.ToInt32(instructorID));
         InstructorIDLabel.Text = instructor.ID.ToString();
         HireDateLabel.Text     = instructor.HireDate.ToString();
     }
 }
Exemplo n.º 18
0
        public void DropStudentErrorTest2()
        {
            //// Arranage
            var errors            = new List <string>();
            var mockRepository    = new Mock <InterfaceInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

            //// Act
            instructorService.DropStudent(100, null, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Exemplo n.º 19
0
        public void GetRequestsErrorTest()
        {
            //// Arranage
            var errors            = new List <string>();
            var mockRepository    = new Mock <InterfaceInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

            //// Act
            instructorService.GetRequests(-1, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Exemplo n.º 20
0
        public void EditGradeErrorTest3()
        {
            //// Arrange
            var errors            = new List <string>();
            var mockRepository    = new Mock <InterfaceInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

            //// Act
            instructorService.EditGrade(100, "A12345", "A*", ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Exemplo n.º 21
0
        public void AssignTutorErrorTest2()
        {
            //// Arrange
            var errors            = new List <string>();
            var mockRepository    = new Mock <InterfaceInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

            //// Act
            instructorService.AssignTutor(-1, 1, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Exemplo n.º 22
0
        public async Task <ActionResult> Edit(InstructorDTO instructorDTO)
        {
            if (ModelState.IsValid)
            {
                var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
                var instructor        = mapper.Map <Instructor>(instructorDTO);
                instructor = await instructorService.Update(instructor);

                return(RedirectToAction("Index", "Instructors"));
            }

            return(View(instructorDTO));
        }
        public IHttpActionResult UpdateInstructor([FromBody] InstructorEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var svc = new InstructorService();

            if (!svc.UpdateInstructor(model))
            {
                return(InternalServerError());
            }

            return(Ok("Instructor successfully updated."));
        }
Exemplo n.º 24
0
        // GET: Instructors
        public async Task <ActionResult> Index(int?id)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));

            if (id != null)
            {
                var courses = await instructorService.GetCoursesByInstructor(id.Value);

                ViewBag.Courses = courses.Select(x => mapper.Map <CourseDTO>(x));
            }

            var instructors = await instructorService.GetAll();

            var instructorsDTO = instructors.Select(x => mapper.Map <InstructorDTO>(x));

            return(View(instructorsDTO));
        }
Exemplo n.º 25
0
        public string UpdateInstructorInfo(Instructor instructor)
        {
            var errors     = new List <string>();
            var repository = new InstructorRepository();
            var service    = new InstructorService(repository);

            service.UpdateInstructorInfo(new Instructor()
            {
                Id = instructor.Id, FirstName = instructor.FirstName, LastName = instructor.LastName
            }, ref errors);

            if (errors.Count == 0)
            {
                return("ok");
            }

            return("error");
        }
Exemplo n.º 26
0
        protected void repeaterInstructor_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            var instructorID = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "edit")
            {
                Response.Redirect("AddInstructor.aspx?id=" + instructorID);
            }
            if (e.CommandName == "delete")
            {
                InstructorService instructorService = new InstructorService();
                instructorService.DeleteInstructor(Convert.ToInt32(instructorID));
                Response.Redirect("ListInstructor.aspx");
            }
            if (e.CommandName == "details")
            {
                Response.Redirect("DetailsInstructor.aspx?id=" + instructorID);
            }
        }
Exemplo n.º 27
0
        public async Task <ActionResult> Create(OfficeAssignmentDTO officeAssignmentDTO)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            var instructors       = await instructorService.GetAll();

            var instructorsDTO = instructors.Select(x => mapper.Map <InstructorDTO>(x));

            ViewData["Instructors"] = new SelectList(instructorsDTO, "ID", "FullName", officeAssignmentDTO.InstructorID);

            if (ModelState.IsValid)
            {
                var officeAssignmentService = new OfficeAssignmentService(new OfficeAssignmentRepository(UniversityContext));
                var officeAssignment        = mapper.Map <OfficeAssignment>(officeAssignmentDTO);
                officeAssignment = await officeAssignmentService.Insert(officeAssignment);

                return(RedirectToAction("Index", "OfficeAssignments"));
            }

            return(View(officeAssignmentDTO));
        }
Exemplo n.º 28
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var instructorID = Request.QueryString["ID"];

            if (Page.IsValid && instructorID == null)
            {
                Contoso.Models.Instructor instructor = new Models.Instructor();
                instructor.ID       = Convert.ToInt32(ddlID.SelectedValue);
                instructor.HireDate = Convert.ToDateTime(txtHireDate.Text);
                InstructorService instructorService = new InstructorService();
                instructorService.AddInstructor(instructor);
            }
            if (Page.IsValid && instructorID != null)
            {
                Contoso.Models.Instructor instructor = new Models.Instructor();
                instructor.ID       = Convert.ToInt32(ddlID.SelectedValue);
                instructor.HireDate = Convert.ToDateTime(txtHireDate.Text);
                InstructorService instructorService = new InstructorService();
                instructorService.UpdateInstructor(instructor);
            }
        }
Exemplo n.º 29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var instructorID = Request.QueryString["ID"];

            if (!IsPostBack && instructorID == null)
            {
                ddlID.DataSource     = Utility.Utility.GetAllPeople();
                ddlID.DataTextField  = "ID";
                ddlID.DataValueField = "ID";
                ddlID.DataBind();
            }
            if (!IsPostBack && instructorID != null)
            {
                ddlID.DataSource     = Utility.Utility.GetAllPeople();
                ddlID.DataTextField  = "ID";
                ddlID.DataValueField = "ID";
                ddlID.DataBind();
                InstructorService         instructorService = new InstructorService();
                Contoso.Models.Instructor instructor        = instructorService.GetOneInstructor(Convert.ToInt32(instructorID));
                ddlID.SelectedValue = instructor.ID.ToString();
                txtHireDate.Text    = instructor.HireDate.ToString();
            }
        }
Exemplo n.º 30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBindingHelper.PopulateActiveBranches(BranchService, ddlBranch, User.Identity.Name, false);
            ddlBranch.SelectedValue = Convert.ToString(HomeBranchID);

            ddlMonth.DataSource     = CommonHelper.GetMonthNames();
            ddlMonth.DataTextField  = "Value";
            ddlMonth.DataValueField = "Key";
            ddlMonth.DataBind();
            ddlMonth.SelectedValue = DateTime.Today.Month.ToString();

            for (int year = DateTime.Today.Year - 3; year <= DateTime.Today.Year; year++)
            {
                ddlYear.Items.Add(new DropDownListItem(year.ToString(CultureInfo.InvariantCulture)));
            }
            ddlYear.FindItemByText(DateTime.Today.Year.ToString(CultureInfo.InvariantCulture)).Selected = true;


            ddlInstructor.DataSource     = InstructorService.GetAllInstructors();
            ddlInstructor.DataValueField = "ID";
            ddlInstructor.DataTextField  = "Name";
            ddlInstructor.DataBind();
        }