public ActionResult <AttendanceCodeSortOrderModel> UpdateAttendanceCodeSortOrder(AttendanceCodeSortOrderModel attendanceCodeSortOrderModel) { AttendanceCodeSortOrderModel attendanceCodeSortOrderUpdate = new AttendanceCodeSortOrderModel(); try { attendanceCodeSortOrderUpdate = _attendanceCodeRegisterService.UpdateAttendanceCodeSortOrder(attendanceCodeSortOrderModel); } catch (Exception es) { attendanceCodeSortOrderUpdate._failure = true; attendanceCodeSortOrderUpdate._message = es.Message; } return(attendanceCodeSortOrderUpdate); }
/// <summary> /// Update Attendance Code Sort Order /// </summary> /// <param name="attendanceCodeSortOrderModel"></param> /// <returns></returns> public AttendanceCodeSortOrderModel UpdateAttendanceCodeSortOrder(AttendanceCodeSortOrderModel attendanceCodeSortOrderModel) { try { if (attendanceCodeSortOrderModel.AttendanceCategoryId > 0) { var AttendanceCodesSortOrderItem = new List <AttendanceCode>(); var targetAttendanceCodeSortOrderItem = this.context?.AttendanceCode.FirstOrDefault(x => x.SortOrder == attendanceCodeSortOrderModel.PreviousSortOrder && x.SchoolId == attendanceCodeSortOrderModel.SchoolId && x.TenantId == attendanceCodeSortOrderModel.TenantId && x.AttendanceCategoryId == attendanceCodeSortOrderModel.AttendanceCategoryId); if (targetAttendanceCodeSortOrderItem != null) { targetAttendanceCodeSortOrderItem.SortOrder = attendanceCodeSortOrderModel.CurrentSortOrder; if (attendanceCodeSortOrderModel.PreviousSortOrder > attendanceCodeSortOrderModel.CurrentSortOrder) { AttendanceCodesSortOrderItem = this.context?.AttendanceCode.Where(x => x.SortOrder >= attendanceCodeSortOrderModel.CurrentSortOrder && x.SortOrder < attendanceCodeSortOrderModel.PreviousSortOrder && x.SchoolId == attendanceCodeSortOrderModel.SchoolId && x.TenantId == attendanceCodeSortOrderModel.TenantId && x.AttendanceCategoryId == attendanceCodeSortOrderModel.AttendanceCategoryId).ToList(); if (AttendanceCodesSortOrderItem.Count > 0) { AttendanceCodesSortOrderItem.ForEach(x => x.SortOrder = x.SortOrder + 1); } } if (attendanceCodeSortOrderModel.CurrentSortOrder > attendanceCodeSortOrderModel.PreviousSortOrder) { AttendanceCodesSortOrderItem = this.context?.AttendanceCode.Where(x => x.SortOrder <= attendanceCodeSortOrderModel.CurrentSortOrder && x.SortOrder > attendanceCodeSortOrderModel.PreviousSortOrder && x.SchoolId == attendanceCodeSortOrderModel.SchoolId && x.TenantId == attendanceCodeSortOrderModel.TenantId && x.AttendanceCategoryId == attendanceCodeSortOrderModel.AttendanceCategoryId).ToList(); if (AttendanceCodesSortOrderItem.Count > 0) { AttendanceCodesSortOrderItem.ForEach(x => x.SortOrder = x.SortOrder - 1); } } } } this.context?.SaveChanges(); attendanceCodeSortOrderModel._failure = false; } catch (Exception es) { attendanceCodeSortOrderModel._message = es.Message; attendanceCodeSortOrderModel._failure = true; } return(attendanceCodeSortOrderModel); }
/// <summary> /// Update Attendance Code Sort Order /// </summary> /// <param name="attendanceCodeSortOrderModel"></param> /// <returns></returns> public AttendanceCodeSortOrderModel UpdateAttendanceCodeSortOrder(AttendanceCodeSortOrderModel attendanceCodeSortOrderModel) { AttendanceCodeSortOrderModel AttendanceCodeSortOrderUpdate = new AttendanceCodeSortOrderModel(); try { if (TokenManager.CheckToken(attendanceCodeSortOrderModel._tenantName + attendanceCodeSortOrderModel._userName, attendanceCodeSortOrderModel._token)) { AttendanceCodeSortOrderUpdate = this.attendanceCodeRepository.UpdateAttendanceCodeSortOrder(attendanceCodeSortOrderModel); } else { AttendanceCodeSortOrderUpdate._failure = true; AttendanceCodeSortOrderUpdate._message = TOKENINVALID; } } catch (Exception es) { AttendanceCodeSortOrderUpdate._failure = true; AttendanceCodeSortOrderUpdate._message = es.Message; } return(AttendanceCodeSortOrderUpdate); }