Esempio n. 1
0
        public IActionResult Edit(CourseRequest course)
        {
            var courseModel = Mapper.Map <Course>(course);

            this.courseService.Edit(courseModel);
            return(Ok());
        }
Esempio n. 2
0
        public override CourseResponse SendItem(AbstractMoodleServiceClient client, Disciplina item)
        {
            CreateCourseClient createClient = (CreateCourseClient)client;
            long?categoryId = item.GetMoodleCursoId(ModalidadeAtual, GetCategoryByNameClient, client.GetUnderlyingHttpClient());

            if (!categoryId.HasValue)
            {
                throw new MoodleDataNotExistsException($"O curso [{item.CursoDescricao}]´nõa está adicionado ao MOODLE.");
            }

            CourseRequest request = new CourseRequest()
            {
                CategoryId = categoryId.Value,
                Fullname   = item.DisciplinaNome,
                Shortname  = item.ShortName,
                Visible    = 1
            };

            Task <CourseResponse> task = createClient.Post(request);

            task.Wait();

            CourseResponse response = task.Result;

            LastUrl = createClient.LastUrl;

            return(response);
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateCourse(
            [FromRoute] int id,
            [FromBody] CourseRequest courseRequest)
        {
            var now    = DateTime.UtcNow;
            var course = await _courseService.GetCourse(id);

            if (course == null)
            {
                return(NotFound($"No course found with id: {id}"));
            }

            course.Name       = courseRequest.Name;
            course.Instructor = courseRequest.Instructor;
            course.UpdatedOn  = now;

            var updated = await _courseService.UpdateCourse(course);

            if (updated)
            {
                return(Ok($"Course Updated with id: {id}"));
            }

            return(NotFound($"No course found with id: ${id}"));
        }
        public async Task Update_Success()
        {
            var course = new Course
            {
                CourseId    = 1,
                Name        = "Toeic 500",
                Description = "Khóa học ôn thi dành cho người mất gốc",
                TimeStudy   = "3 month"
            };

            await _courseRepository.Add(course);

            var courseUpdate = new CourseRequest
            {
                Name        = "Toeic 700",
                Description = "Khóa học ôn thi dành cho người mất gốc",
                TimeStudy   = "3 month"
            };

            var courseService = new CourseService(_courseRepository);

            var controller = new CourseController(courseService);

            //action
            var result = await controller.UpdateCourse(1, courseUpdate);

            //course

            result.Should().NotBeNull();

            var response    = Assert.IsType <OkObjectResult>(result.Result);
            var returnValue = Assert.IsType <Course>(response.Value);

            Assert.Equal("Toeic 700", returnValue.Name);
        }
        public async Task PostCourse_Success()
        {
            var course = new CourseRequest
            {
                Name        = "Toeic 500",
                Description = "Khóa học ôn thi dành cho người mất gốc",
                TimeStudy   = "3 month"
            };

            var courseService = new CourseService(_courseRepository);

            var controller = new CourseController(courseService);

            //action
            var result = await controller.PostCourse(course);

            //course

            result.Should().NotBeNull();

            var createdAtActionResult = Assert.IsType <OkObjectResult>(result.Result);
            var returnValue           = Assert.IsType <Course>(createdAtActionResult.Value);

            Assert.Equal("Toeic 500", returnValue.Name);
            Assert.Equal("Khóa học ôn thi dành cho người mất gốc", returnValue.Description);
            Assert.Equal("3 month", returnValue.TimeStudy);
        }
Esempio n. 6
0
        public async Task <ServiceResult <CourseResponse> > UpdateCourse(CourseRequest request)
        {
            var courseEntity = Mapper.Map <CourseRequest, Course>(request);
            var modelState   = new Dictionary <string, string[]>();

            _unitOfWork.CourseRepository.Update(courseEntity);

            // Handle Conflicts here
            int result;

            if (request.ConflictStrategy == ResolveStrategy.ShowUnresolvedConflicts)
            {
                var resolveConflicts = ConcurrencyHelper.ResolveConflicts(courseEntity, modelState);
                result = await _unitOfWork.SaveAsync(resolveConflicts, userResolveConflict : true);
            }
            else
            {
                RefreshConflict refreshMode = (RefreshConflict)request.ConflictStrategy;
                if (!EnumExtensions.IsFlagDefined(refreshMode))
                {
                    refreshMode = RefreshConflict.StoreWins;
                }
                result = _unitOfWork.SaveSingleEntry(refreshMode);
            }
            return(await GetServiceResult(courseEntity, modelState, result));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CourseRequest courseRequest = db.CourseRequests.Find(id);

            db.CourseRequests.Remove(courseRequest);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 8
0
 public static Course GetEntity(CourseRequest course)
 {
     return(new Course()
     {
         ID = course.ID,
         Name = course.Name,
         Description = course.Description
     });
 }
 public ActionResult Edit([Bind(Include = "Id,Course,User,Approved")] CourseRequest courseRequest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseRequest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(courseRequest));
 }
Esempio n. 10
0
        public async Task <IActionResult> Put([FromBody] CourseRequest value)
        {
            var result = await _courseService.UpdateCourse(value);

            if (!result.HasErrors)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Esempio n. 11
0
        public async Task <Course> Add(CourseRequest courseRequest)
        {
            var course = new Course
            {
                Name        = courseRequest.Name,
                Description = courseRequest.Description,
                TimeStudy   = courseRequest.TimeStudy
            };

            return(await _baseRepository.Add(course));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Id,Course,User,Approved")] CourseRequest courseRequest)
        {
            if (ModelState.IsValid)
            {
                db.CourseRequests.Add(courseRequest);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(courseRequest));
        }
 public void Execute(CourseRequest course)
 {
     try
     {
         Course entity = CourseAdapter.GetEntity(course);
         _repository.Update(entity);
     }
     catch (Exception exc)
     {
         throw new CourseException("Error while update course!", exc);
     }
 }
Esempio n. 14
0
        public async Task <ServiceResult <CourseResponse> > AddCourse(CourseRequest request)
        {
            var courseEntity = Mapper.Map <CourseRequest, Course>(request);
            var modelState   = new Dictionary <string, string[]>();

            _unitOfWork.CourseRepository.Insert(courseEntity);

            // Handle Conflicts here
            int result = await _unitOfWork.SaveAsync();

            return(await GetServiceResult(courseEntity, modelState, result));
        }
Esempio n. 15
0
        /// <summary>
        /// Create a new course for the specified account.
        /// </summary>
        /// <param name="courseRequest">The details of the course to create</param>
        /// <returns></returns>
        public async Task <Course> CreateAsync(CourseRequest courseRequest)
        {
            courseRequest.ThrowIfNull("courseRequest")
            .AccountId.ThrowIfUnassigned("courseRequest.AccountId");
            courseRequest.Course.ThrowIfNull("courseRequest.Course");

            ApiRequest request = new ApiRequest(_config.CoursesEndpointUri)
                                 .Method(RequestMethod.Post)
                                 .Payload(_converter.Serialize(courseRequest));

            return(await GetReponseAsync <Course>(request).ConfigureAwait(false));
        }
Esempio n. 16
0
        //public Result<object> GetStudentCourses(string studentUsername)
        //{
        // Not needed duo to list of sessions
        //    throw new NotImplementedException();
        //}

        public Result <CourseRequest> RequestCourse(string Username, string courseName)
        {
            Result <CourseRequest> result = new Result <CourseRequest>();

            try
            {
                UserManagementService ums         = new UserManagementService();
                Result <OlescUser>    currentUser = ums.GetUser(Username);

                if (currentUser.isSuccess)
                {
                    /*If the courserequest is 0, means that there is no request*/
                    if (dbConn.Courses.Where(c => c.CourseName.Equals(courseName)).Count() == 0)
                    {
                        CourseRequest cr = new CourseRequest();
                        cr.CourseName = courseName;
                        cr.UserID     = currentUser.resultObject.ID;
                        cr.CreatedBy  = currentUser.resultObject.Email;
                        /*NO cr.UpdatedBy. The role will never be updated, either created or deleted */

                        dbConn.CourseRequests.Add(cr);

                        int NumOfRecords = dbConn.SaveChanges();
                        if (NumOfRecords >= 1)
                        {
                            result.isSuccess    = true;
                            result.message      = "Course requested succesfully";
                            result.resultObject = cr;
                        }
                    }
                    else
                    {
                        result.isSuccess    = false;
                        result.message      = courseName + " already exist";
                        result.resultObject = null;
                    }
                }
                else
                {
                    result.isSuccess    = currentUser.isSuccess;
                    result.message      = currentUser.message;
                    result.resultObject = null;
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
Esempio n. 17
0
        public void Execute(CourseRequest course)
        {
            Course entity = CourseAdapter.GetEntity(course);

            try
            {
                _repository.AddNew(entity);
            }
            catch (Exception exc)
            {
                throw new StudentException("Eror while create new course!", exc);
            }
        }
        /// <summary>
        /// Construct a row for a primary course with an optional alternate course for Course Request in Blackbaud.
        /// </summary>
        /// <param name="primary">The primary course requested.</param>
        /// <param name="secondary">(Optional) The course requested as an alternate to the primary course.</param>
        /// <returns></returns>
        protected static Dictionary<String,String> getRow(CourseRequest primary, CourseRequest secondary = null)
        {
            Dictionary<String, string> row = new Dictionary<string, string>()
            {
                {"Student Course Requested", "Yes"},
                {"Student ID", String.Format("\"{0}\"", primary.Student.BlackbaudId)},
                {"Student Course Academic year", AcademicYearStr(primary.Term)},
                {"Student Course Start term", String.Format("{0} Trimester", primary.Term.Name)},
                {"Student Course Course ID", primary.RequestableCourse.Course.BlackBaudID},
                {"Student Course Session","Regular School"}
            };

            String priority = "";
            if (primary.RequestableCourse.Course.Name.Contains("AP"))
            {
                priority = Priorities[0];
            }
            else if (primary.RequestableCourse.Course.LengthInTerms > 1)
            {
                priority = Priorities[1];
            }
            else
            {
                priority = Priorities[2];
            }

            row.Add("Student Course Priority", priority);

            if(secondary != null)
            {
                row.Add("Student Course Alternate Alternate course ID", secondary.RequestableCourse.Course.BlackBaudID);
                row.Add("Student Course Alternate Alternate start term", String.Format("{0} Trimester", secondary.Term.Name));
                String altpriority = "";
                if (secondary.RequestableCourse.Course.Name.Contains("AP"))
                {
                    altpriority = Priorities[0];
                }
                else if (secondary.RequestableCourse.Course.LengthInTerms > 1 || secondary.RequestableCourse.Course.Department.Name.Equals("English"))
                {
                    altpriority = Priorities[1];
                }
                else
                {
                    altpriority = Priorities[2];
                }

                row.Add("Student Course Alternate Alternate priority", altpriority);
            }

            return row;
        }
Esempio n. 19
0
        // GET: CourseRequests/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseRequest courseRequest = db.CourseRequests.Find(id);

            if (courseRequest == null)
            {
                return(HttpNotFound());
            }
            return(View(courseRequest));
        }
        public CourseBaseResponse Create(CourseRequest courseRequest)
        {
            courseRequest.Id = Guid.NewGuid();
            var course = Mapper.Map <Course>(courseRequest);

            _courseService.Create(course, out var isStudentSaved);

            if (isStudentSaved == false)
            {
                throw new InternalServerErrorException(CommonConstant.Error.InternalServerError);
            }

            return(Mapper.Map <CourseBaseResponse>(course));
        }
Esempio n. 21
0
        public async Task <Course> Update(int id, CourseRequest CourseRequest)
        {
            var course = await _baseRepository.GetById(id);

            if (course == null)
            {
                throw new Exception("Not Found");
            }

            course.Name        = CourseRequest.Name;
            course.Description = CourseRequest.Description;
            course.TimeStudy   = CourseRequest.TimeStudy;

            return(await _baseRepository.Update(course));
        }
        /// <summary>
        /// Construct a row for a Global Alternate course request in Blackbaud.
        /// </summary>
        /// <param name="primary">Global Alternate course requested.</param>
        /// <returns></returns>
        protected static Dictionary<String, String> getGARow(CourseRequest primary)
        {
            Dictionary<String, string> row = new Dictionary<string, string>()
            {
                {"Student Course Requested", "Yes"},
                {"Student ID", String.Format("\"{0}\"", primary.Student.BlackbaudId)},
                {"Student Course Academic year", AcademicYearStr(primary.Term)},
                {"Student Course Alternate Alternate start term", String.Format("{0} Trimester", primary.Term.Name)},
                {"Student Course Alternate Alternate course ID", primary.RequestableCourse.Course.BlackBaudID},
                {"Student Course Session","Regular School"},
                {"Student Course Alternate Alternate priority", Priorities[0]}
            };


            return row;
        }
        public void C_Req(CourseRequest Req)
        {
            Req.ReqDate = DateTime.Now;

            User usrObjectLec = cx.Users.FirstOrDefault(x => x.id == Req.T_ID);
            User usrObjectStu = cx.Users.FirstOrDefault(x => x.id == Req.S_ID);

            emailSending mailObject = new emailSending(usrObjectLec.mail, usrObjectStu.mail);
            string       title      = cx.Courses.FirstOrDefault(x => x.C_Code == Req.C_Code).C_Name;

            mailObject.SendEmail(Req.C_Code, title, Req.note);


            cx.CourseRequests.Add(Req);

            cx.SaveChanges();
        }
Esempio n. 24
0
        public async Task <IActionResult> PostCourse([FromBody] CourseRequest courseRequest)
        {
            var now         = DateTime.UtcNow;
            var courseToAdd = new Course
            {
                Name        = courseRequest.Name,
                Instructor  = courseRequest.Instructor,
                FinalGrade  = null,
                GradedItems = null,
                CreatedOn   = now,
                UpdatedOn   = now
            };

            await _courseService.AddCourse(courseToAdd);

            return(Ok($"Course added: {courseToAdd.Name}"));


            /*In method before: [FromBody] JObject objData ^^^*/

            //ICollection<GradedItemRequest> gradedItemsLstRequest = new List<GradedItemRequest>();
            //dynamic course = objData;
            //JArray gradedItemsJson = course.GradedItems;

            //if(gradedItemsJson != null)
            //{
            //    foreach (var gradedItem in gradedItemsJson)
            //    {
            //        gradedItemsLstRequest.Add(gradedItem.ToObject<GradedItemRequest>());
            //    }
            //}
            //ICollection<GradedItem> gradedItems = new List<GradedItem>();

            //foreach (var gradedItem in gradedItemsLstRequest)
            //{
            //    var gradedItemModel = new GradedItem
            //    {
            //        Name = gradedItem.Name,
            //        Grade = gradedItem.Grade,
            //        CreatedOn = now,
            //        UpdatedOn = now
            //    };

            //    gradedItems.Add(gradedItemModel);
            //}
        }
Esempio n. 25
0
 public void textureCallback(string[] backTextureurl)
 {
     for (int i = 0; i < backTextureurl.Length; i++)
     {
         if (!File.Exists(CommenValue.AssetPath + backTextureurl[i]))
         {
             CourseRequest courseRequest = new CourseRequest(requestUrl.textureUrl, backTextureurl[i]);
             getIconSignal.Dispatch(courseRequest);
         }
         else
         {
             Debug.Log("file:///" + CommenValue.AssetPath + backTextureurl[i]);
             CourseRequest courseRequest = new CourseRequest("file:///" + CommenValue.AssetPath, backTextureurl[i]);
             getIconSignal.Dispatch(courseRequest);
         }
     }
 }
    public void OnSetCourse(Course course)
    {
        this.course = course;
        courseItemView.SetData(course);
        Debug.Log("Set course");
        CourseRequest courseRequest = null;

        if (!File.Exists(filePath + "/" + course.thumb))
        {
            courseRequest = new CourseRequest(requestUrl.textureUrl, course.thumb);
            callHttpGetIconSignal.Dispatch(courseRequest);
        }
        else
        {
            courseRequest = new CourseRequest("file:///" + filePath, course.thumb);
            callHttpGetIconSignal.Dispatch(courseRequest);
        }
    }
        private void AcceptChanges()
        {
            CourseRequest request = new CourseRequest()
            {
                Name        = _courseViewModel.Name,
                Description = _courseViewModel.Description
            };

            try
            {
                InteractorFactory.Scope.Instance.GetCommandNewCourse(_courseRepository).Execute(request);
                _viewContainer.CloseView();
            }
            catch (CourseException)
            {
                _viewContainer.ShowError("Error", "Error while create course!");
            }
        }
Esempio n. 28
0
        public async Task <dynamic> Add(CourseRequest courseRequest)
        {
            if (courseRequest == null)
            {
                AddError("20000");
                return(null);
            }

            var course = Course.Create(courseRequest.Name);

            //if (!user.IsValid)
            //{
            //    Error = user.Error;
            //    return null;
            //}

            _courseRepository.Add(course);
            return(await Task.FromResult(course));
        }
        public async Task <ActionResult> Post([FromBody] CourseRequest studentRequest)
        {
            try
            {
                var response = await _courseService.Add(studentRequest);

                var notifications = _courseService as Notifiable;

                if (response == null && notifications.Error.Any())
                {
                    return(BadRequest(notifications.Error));
                }

                return(Created(string.Empty, response));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.ToString()));
            }
        }
        private CourseResponse CriarDisciplinaMoodle(Disciplina item, long moodleCategoryId)
        {
            CreateCourseClient client = CreateCourseClient;

            BuildMoodleClient(client, MoodleTokenType.OfficialMoodleApiFunctions);

            CourseRequest request = new CourseRequest()
            {
                CategoryId = moodleCategoryId,
                Fullname   = item.DisciplinaNome,
                Shortname  = item.ShortName,
                Visible    = 1
            };

            Task <CourseResponse> task = client.Post(request);

            task.Wait();

            LastUrl = client.LastUrl;
            CourseResponse response = task.Result;

            return(response);
        }
 public void SaveCourseRequest(CourseRequest request)
 {
     if (request.ID == Guid.Empty)
     {
         _context.CourseRequests.Add(request);
     }
     else
     {
         CourseRequest dbEntry = _context.CourseRequests.Find(request.ID);
         if (dbEntry != null)
         {
             dbEntry.CourseId = request.CourseId;
             dbEntry.IsDeclined = request.IsDeclined;
             dbEntry.StudentId = request.StudentId;
         }
     }
     _context.SaveChanges();
 }