/// <summary> /// Update SortOrder For CourseCommentCategory /// </summary> /// <param name="reportCardCommentSortOrderViewModel"></param> /// <returns></returns> public CourseCommentCategorySortOrderViewModel UpdateSortOrderForCourseCommentCategory(CourseCommentCategorySortOrderViewModel courseCommentCategorySortOrderViewModel) { CourseCommentCategorySortOrderViewModel courseCommentCategorySort = new CourseCommentCategorySortOrderViewModel(); if (TokenManager.CheckToken(courseCommentCategorySortOrderViewModel._tenantName + courseCommentCategorySortOrderViewModel._userName, courseCommentCategorySortOrderViewModel._token)) { courseCommentCategorySort = this.reportCardRepository.UpdateSortOrderForCourseCommentCategory(courseCommentCategorySortOrderViewModel); } else { courseCommentCategorySort._message = TOKENINVALID; courseCommentCategorySort._failure = true; } return(courseCommentCategorySort); }
public ActionResult <CourseCommentCategorySortOrderViewModel> UpdateSortOrderForCourseCommentCategory(CourseCommentCategorySortOrderViewModel courseCommentCategorySortOrderViewModel) { CourseCommentCategorySortOrderViewModel courseCommentCategorySort = new CourseCommentCategorySortOrderViewModel(); try { courseCommentCategorySort = _reportCardService.UpdateSortOrderForCourseCommentCategory(courseCommentCategorySortOrderViewModel); } catch (Exception ex) { courseCommentCategorySort._message = ex.Message; courseCommentCategorySort._failure = true; } return(courseCommentCategorySort); }
/// <summary> /// Update SortOrder For CourseCommentCategory /// </summary> /// <param name="reportCardCommentSortOrderViewModel"></param> /// <returns></returns> public CourseCommentCategorySortOrderViewModel UpdateSortOrderForCourseCommentCategory(CourseCommentCategorySortOrderViewModel courseCommentCategorySortOrderViewModel) { try { //if (courseCommentCategorySortOrderViewModel.CourseId > 0) //{ var SortOrderItem = new List<CourseCommentCategory>(); var targetSortOrderItem = this.context?.CourseCommentCategory.FirstOrDefault(x => x.SortOrder == courseCommentCategorySortOrderViewModel.PreviousSortOrder && x.SchoolId == courseCommentCategorySortOrderViewModel.SchoolId && x.TenantId == courseCommentCategorySortOrderViewModel.TenantId && x.CourseId == courseCommentCategorySortOrderViewModel.CourseId); if (targetSortOrderItem != null) { targetSortOrderItem.SortOrder = courseCommentCategorySortOrderViewModel.CurrentSortOrder; if (courseCommentCategorySortOrderViewModel.PreviousSortOrder > courseCommentCategorySortOrderViewModel.CurrentSortOrder) { SortOrderItem = this.context?.CourseCommentCategory.Where(x => x.SortOrder >= courseCommentCategorySortOrderViewModel.CurrentSortOrder && x.SortOrder < courseCommentCategorySortOrderViewModel.PreviousSortOrder && x.SchoolId == courseCommentCategorySortOrderViewModel.SchoolId && x.TenantId == courseCommentCategorySortOrderViewModel.TenantId && x.CourseId == courseCommentCategorySortOrderViewModel.CourseId).ToList(); if (SortOrderItem.Count > 0) { SortOrderItem.ForEach(x => x.SortOrder = x.SortOrder + 1); } } if (courseCommentCategorySortOrderViewModel.CurrentSortOrder > courseCommentCategorySortOrderViewModel.PreviousSortOrder) { SortOrderItem = this.context?.CourseCommentCategory.Where(x => x.SortOrder <= courseCommentCategorySortOrderViewModel.CurrentSortOrder && x.SortOrder > courseCommentCategorySortOrderViewModel.PreviousSortOrder && x.SchoolId == courseCommentCategorySortOrderViewModel.SchoolId && x.TenantId == courseCommentCategorySortOrderViewModel.TenantId && x.CourseId == courseCommentCategorySortOrderViewModel.CourseId).ToList(); if (SortOrderItem.Count > 0) { SortOrderItem.ForEach(x => x.SortOrder = x.SortOrder - 1); } } } this.context?.SaveChanges(); courseCommentCategorySortOrderViewModel._failure = false; //} } catch (Exception es) { courseCommentCategorySortOrderViewModel._message = es.Message; courseCommentCategorySortOrderViewModel._failure = true; } return courseCommentCategorySortOrderViewModel; }