コード例 #1
0
        public async Task <ApiSuccessResponse> UpdateAsync(long id, CourseUpdateRequest request)
        {
            var course = await _unitOfWork.CourseRepository.FindSingleAsync(x => x.CourseId == id);

            if (course == null)
            {
                throw new MyAppException("The course with a given id is not found!");
            }

            var courseCodeExistsAsync =
                await _unitOfWork.CourseRepository.FindSingleAsync(x => x.Code == request.Code && x.Code != course.Code);

            if (courseCodeExistsAsync != null)
            {
                throw new MyAppException("The course with a given email already exists in our system!");
            }

            course.Code = request.Code;
            course.Name = request.Name;

            _unitOfWork.CourseRepository.Update(course);
            if (await _unitOfWork.AppSaveChangesAsync())
            {
                return new ApiSuccessResponse()
                       {
                           StatusCode = 200,
                           Message    = "The student has been successfully updated."
                       }
            }
            ;

            throw new MyAppException("Something went wrong!");
        }
コード例 #2
0
        public async Task <Course> UpdateAsync(string code, CourseUpdateRequest request)
        {
            var acourse = await _unitOfWork.CourseRepository.GetAAsync(x => x.Code == code);

            if (acourse == null)
            {
                throw  new MyAppException("No data found");
            }

            if (code != request.Code)
            {
                if (await IsCodeExists(request.Code))
                {
                    throw  new MyAppException("Code already exist");
                }
            }
            acourse.Name = request.Name;
            acourse.Code = request.Code;

            _unitOfWork.CourseRepository.UpdateAsync(acourse);
            if (!await _unitOfWork.ApplicationSaveChangesAsync())
            {
                throw  new MyAppException("Some thing is wrong");
            }

            return(acourse);
        }
コード例 #3
0
 public async Task <ActionResult> ModifyRoaster(ModifyRoasterModel model)
 {
     if (ModelState.IsValid)
     {
         StringBuilder roaster = new StringBuilder();
         if (model.roasterIds != null)
         {
             roaster.Append(string.Join(",", model.roasterIds.Select(x => x.isMarkedForDeletion == false)));
         }
         if (!string.IsNullOrWhiteSpace(model.newRoasterIds))
         {
             if (model.roasterIds != null)
             {
                 roaster.Append(",");
             }
             foreach (var id in model.newRoasterIds.Split(','))
             {
                 roaster.Append(id.Trim());
                 roaster.Append(",");
             }
             roaster.Remove(roaster.Length - 1, 1);
         }
         CourseUpdateRequest cur = new CourseUpdateRequest();
         cur.CourseCode = model.courseCode;
         cur.Roaster    = roaster.ToString();
         bool resp = _courseCom.UpdateCourse(cur);
         if (resp)
         {
             return(RedirectToAction("ModifyRoaster", "Course", routeValues: new { courseCode = model.courseCode, message = "Success" }));
         }
     }
     return(RedirectToAction("ModifyRoaster", "Course", routeValues: new { courseCode = model.courseCode, message = "Failure" }));
 }
コード例 #4
0
        public async Task <ActionResult <CourseDto> > UpdateCourse(Guid courseId, [FromBody] CourseUpdateRequest courseRequest)
        {
            CourseDto course = await _coursesService.UpdateCourseAsync(courseId, courseRequest);

            if (course == null)
            {
                return(NotFound());
            }

            return(Ok(course));
        }
コード例 #5
0
 public bool UpdateCourse(CourseUpdateRequest request)
 {
     try
     {
         Course.Update(request);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #6
0
        public HttpResponseMessage EditCourses(CourseUpdateRequest model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            SucessResponse response = new SucessResponse();

            _coursesService.Update(model);
            return(Request.CreateResponse(response));
        }
コード例 #7
0
        public static void ToUpdateEntity(this CourseUpdateRequest request, ref CourseEntity course)
        {
            if (request == null || course == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(request.Title))
            {
                course.Title = request.Title;
            }

            if (!string.IsNullOrEmpty(request.Description))
            {
                course.Description = request.Description;
            }
        }
コード例 #8
0
        public async Task <CourseDto> UpdateCourseAsync(Guid courseId, CourseUpdateRequest courseRequest)
        {
            if (courseId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(courseId));
            }

            CourseEntity course = await _context.Courses.FirstOrDefaultAsync(x => x.Id == courseId);

            if (course == null)
            {
                return(null);
            }

            courseRequest.ToUpdateEntity(ref course);

            await _context.SaveChangesAsync();

            return(course.ToDto());
        }
コード例 #9
0
 public void Update(CourseUpdateRequest courseUpdateRequest, Guid gradeId)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public async Task <IActionResult> Update(long id, CourseUpdateRequest request)
 {
     return(Ok(await _courseService.UpdateAsync(id, request)));
 }
コード例 #11
0
 public async Task <ActionResult> UpdateCourse(string code, CourseUpdateRequest request)
 {
     return(Ok(await _courseService.UpdateAsync(code, request)));
 }
コード例 #12
0
        public DomainModelResponse Update(CourseUpdateRequest request)
        {
            Course course       = _repCourse.Get(filter: f => f.CourseCode == request.CourseCode).FirstOrDefault();
            bool   updateCourse = false;

            if (request.CourseName != null) //Course name update
            {
                course.CourseName = request.CourseName;
                updateCourse      = true;
            }
            if (request.CourseDescription != null)
            {
                course.CourseDescription = request.CourseDescription;
                updateCourse             = true;
            }

            if (request.QuestionnaireCode != null)
            {
                EntityModel.Questionnaire questionnaire = _repQuestionnaire.Get(filter: f => f.QuestionnaireCode == request.QuestionnaireCode).FirstOrDefault();
                course.QuestionnaireId = questionnaire.QuestionnaireId;
                course.Questionnaire   = questionnaire;
                updateCourse           = true;
            }

            if (!string.IsNullOrWhiteSpace(request.Roaster))
            {
                course.Roaster = request.Roaster;
                updateCourse   = true;
            }

            if (updateCourse)
            {
                _repCourse.Update(course);
            }

            if (request.CourseNewUsers != null)
            {
                List <string> roleCodes = request.CourseNewUsers.Select(x => x.roleCode).ToList();
                List <string> emailIds  = request.CourseNewUsers.Select(x => x.emailId).ToList();

                List <AspNetUsers> userProfiles = _repUserProfile.Get(filter: f => emailIds.Contains(f.Email)).ToList();

                foreach (var user in request.CourseNewUsers)
                {
                    EntityModel.CourseUser cur = new EntityModel.CourseUser()
                    {
                        CourseId        = course.CourseId,
                        Course          = course,
                        UserId          = userProfiles.Where(x => x.Email == user.emailId).FirstOrDefault().Id,
                        AspNetUsers     = userProfiles.Where(x => x.Email == user.emailId).FirstOrDefault(),
                        LastChangedTime = DateTime.UtcNow
                    };
                    _repCourseUserRole.Add(cur);
                }
            }

            if (request.CourseDeleteUsers != null)
            {
                List <string> roleCodes = request.CourseDeleteUsers.Select(x => x.roleCode).ToList();
                List <string> emailIds  = request.CourseDeleteUsers.Select(x => x.emailId).ToList();

                List <AspNetUsers> userProfiles = _repUserProfile.Get(filter: f => emailIds.Contains(f.Email)).ToList();

                foreach (var user in request.CourseDeleteUsers)
                {
                    string UserId = userProfiles.Where(x => x.Email == user.emailId).FirstOrDefault().Id;

                    EntityModel.CourseUser cur = _repCourseUserRole.Get(filter: f => f.CourseId == course.CourseId && f.UserId == UserId).FirstOrDefault();
                    _repCourseUserRole.Delete(cur);
                }
            }

            _uow.Commit();
            _courseResponse.addResponse("Update", MessageCodes.InfoSavedSuccessfully, "Course : " + request.CourseCode);
            return(_courseResponse);
        }
コード例 #13
0
        public void Update(CourseUpdateRequest model)
        {
            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Courses_Update2",
                                         inputParamMapper : delegate(SqlParameterCollection updateCourse)
            {
                updateCourse.AddWithValue("@Id", model.Id);
                updateCourse.AddWithValue("@CourseName", model.CourseName);
                updateCourse.AddWithValue("@Length", model.Length);
                updateCourse.AddWithValue("@Description", model.Description);
                updateCourse.AddWithValue("@CourseStart", model.Start);
                updateCourse.AddWithValue("@CourseEnd", model.End);
                updateCourse.AddWithValue("@LearningObjectives", model.LearningObjectives);
                updateCourse.AddWithValue("@ExpectedOutcome", model.ExpectedOutcome);
                updateCourse.AddWithValue("@EvaluationCriteria", model.EvaluationCriteria);
                updateCourse.AddWithValue("@Format", model.Format);
            });

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CoursePrereqs_DeleteByCourseId",
                                         inputParamMapper : delegate(SqlParameterCollection parameterCollection)
            {
                parameterCollection.AddWithValue("@CourseId", model.Id);
            });
            foreach (var PrereqId in model.Prereqs)
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CoursePrereqs_Insert",
                                             inputParamMapper : delegate(SqlParameterCollection param)
                {
                    param.AddWithValue("@CourseId", model.Id);
                    param.AddWithValue("@PrereqId", PrereqId);
                });
            }


            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseTags_DeleteByCourseId",
                                         inputParamMapper : delegate(SqlParameterCollection parameterCollection)
            {
                parameterCollection.AddWithValue("@CourseId", model.Id);
            });
            foreach (var TagId in model.Tags)
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseTags_Insert",
                                             inputParamMapper : delegate(SqlParameterCollection param)
                {
                    param.AddWithValue("@CourseId", model.Id);
                    param.AddWithValue("@TagId", TagId);
                });
            }


            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseInstructors_DeleteByCourseId",
                                         inputParamMapper : delegate(SqlParameterCollection parameterCollection)
            {
                parameterCollection.AddWithValue("@CourseId", model.Id);
            });
            foreach (var instructorId in model.Instructors)
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseInstructors_Insert",
                                             inputParamMapper : delegate(SqlParameterCollection param)
                {
                    param.AddWithValue("@CourseId", model.Id);
                    param.AddWithValue("@InstructorId", instructorId);
                });
            }
        }
コード例 #14
0
        public async Task <ActionResult> Create(CreateCourseModel model)
        {
            if (ModelState.IsValid)
            {
                CourseAddRequest car = new CourseAddRequest()
                {
                    CourseCode = model.CourseCode,
                    CourseName = model.CourseName,
                    //DesiredSkillSets = model.DesiredSkillSets,
                    GroupSize              = model.GroupSize,
                    CourseDescription      = model.CourseDescription,
                    PreferSimiliarSkillSet = model.PreferSimiliarSkillSet,
                    Term     = model.Term,
                    userList = new List <CourseNewUser>()
                };
                switch (model.GroupType)
                {
                case "Study Group":
                    car.GroupType = "Study";
                    break;

                case "Project Group (Open Projects)":
                    car.GroupType = "OpenProject";
                    break;

                case "Project Group (Closed Projects)":
                    car.GroupType = "ClosedProject";
                    break;
                }

                if (model.Users != null && model.Users.Count > 0)
                {
                    foreach (var user in model.Users)
                    {
                        car.userList.Add(new CourseNewUser()
                        {
                            emailId  = user.emailId,
                            roleCode = user.role.ToString()
                        });
                    }
                }

                bool result = _courseCom.AddCourse(car);
                if (result) //Course is added, now generate intelligent question set and add questionnaire
                {
                    QuestionnaireAddRequest qar = new QuestionnaireAddRequest()
                    {
                        IsATemplate       = false,
                        QuestionnaireCode = DateTime.UtcNow.ToString("MMddyyHmmss"),
                        Questions         = new List <DomainDto.Question>()
                    };
                    List <string> timeZones = TimeZoneInfo.GetSystemTimeZones().Select(x => x.DisplayName).ToList();
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "In what timezone are you mostly available?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeZones
                    });
                    List <string> timeSlots = new List <string>()
                    {
                        "6:00 AM - 9:00 AM",
                        "9:00 AM - 12:00 PM",
                        "12:00 PM - 3:00 PM",
                        "3:00 PM - 6:00 PM",
                        "6:00 PM - 9:00 PM",
                        "9:00 PM - 12:00 AM",
                        "Anytime",
                        "I am not available"
                    };
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "During weekday, what time are you available for group calls?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeSlots
                    });
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "During weekends, what time are you available for group calls?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeSlots
                    });

                    if (model.GenerateIntelligentQuestionnaire)
                    {
                        if (model.DesiredSkillSets != null)
                        {
                            foreach (var skl in model.DesiredSkillSets.Split(','))
                            {
                                qar.Questions.Add(new DomainDto.Question()
                                {
                                    questionText  = "What is your expertise in " + skl.Trim(),
                                    questionType  = "MultipleChoice",
                                    answerChoices = new List <string>()
                                    {
                                        "Beginner", "Intermediate", "Expert"
                                    }
                                });
                            }
                        }
                    }

                    if (model.Questions != null && model.Questions.Count > 0)
                    {
                        foreach (var q in model.Questions)
                        {
                            qar.Questions.Add(new DomainDto.Question()
                            {
                                questionType  = q.QuestionType,
                                questionText  = q.QuestionText,
                                answerChoices = q.AnswerChoices.Split(',').ToList(),
                                Priority      = getPriority(q.Priority)
                            });
                        }
                    }
                    bool res = _questionnaireCom.AddQuestionnaire(qar);
                    if (res)//Questionnaire is added, update course with questionnaire
                    {
                        CourseUpdateRequest cur = new CourseUpdateRequest()
                        {
                            CourseCode        = model.CourseCode,
                            QuestionnaireCode = qar.QuestionnaireCode
                        };
                        bool resp = _courseCom.UpdateCourse(cur);
                        if (!resp)
                        {
                            ModelState.AddModelError("", "Oops! Course was added, but someting wrong happened while adding questionnaire to course");
                            return(View(model));
                        }
                    }
                    //MvcApplication.courses.Add(model.CourseCode, model.CourseName);
                    //MvcApplication.courseDescription.Add(model.CourseCode, model.CourseDescription);
                    return(RedirectToAction("Teacher", "Course"));
                }
            }
            ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
            return(View(model));
        }