using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.SupervisionManage; using EMIS.ViewModel.SupervisionManage; using EMIS.ViewModel; using EMIS.Entities; using EMIS.CommonLogic.CalendarManage; using EMIS.CommonLogic.SystemServices; using System.Web; namespace EMIS.CommonLogic.SupervisionManage { public class LessonRecordServices : BaseServices, ILessonRecordServices, IFileUploadServices { public LessonRecordDAL LessonRecordDAL { get; set; } public Lazy SchoolYearServices { get; set; } public IGridResultSet GetLessonRecordViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate, int? pageIndex = null, int? pageSize = null) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> supervisorExp = (x => true); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID); } if (supervisionCollegeID.HasValue) { exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID); } if (startDate.HasValue) { exp = exp.And(x => x.LessonDate >= startDate); } if (endDate.HasValue) { var correctEndDate = endDate.Value.Date.AddDays(1); exp = exp.And(x => x.LessonDate < correctEndDate); } var query = LessonRecordDAL.GetLessonRecordViewQueryable(exp, supervisorExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) { query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue); } query = this.GetQueryByDataRange(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.LessonDate) .ThenBy(x => x.StartTimes); return query.ToGridResultSet(pageIndex, pageSize); } public List GetLessonRecordViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate) { return GetLessonRecordViewGrid(conditionView, schoolyearID, collegeID, supervisionCollegeID, startDate, endDate).rows; } public LessonRecordView GetLessonRecordView(Guid lessonRecordID) { return LessonRecordDAL.GetLessonRecordViewQueryable(x => x.LessonRecordID == lessonRecordID, (x => true)).FirstOrDefault(); } public void Save(LessonRecordView lessonRecordView, IList attachmentList) { var lessonRecord = new SUP_LessonRecord(); if (lessonRecordView.LessonRecordID != Guid.Empty) { lessonRecord = this.LessonRecordDAL.LessonRecordRepository.GetSingle(x => x.LessonRecordID == lessonRecordView.LessonRecordID, (x => x.SUP_LessonRecordAttachment)); this.SetModifyStatus(lessonRecord); } else { lessonRecord.LessonRecordID = Guid.NewGuid(); //lessonRecord.SchoolyearID = SchoolYearServices.Value.GetCurrentSchoolYear().SchoolYearID; this.SetNewStatus(lessonRecord); this.UnitOfWork.Add(lessonRecord); } lessonRecord.SchoolyearID = lessonRecordView.SchoolyearID; lessonRecord.LessonDate = lessonRecordView.LessonDate; lessonRecord.Location = lessonRecordView.Location; lessonRecord.SupervisionCollegeID = lessonRecordView.SupervisionCollegeID; lessonRecord.UserID = lessonRecordView.UserID; lessonRecord.ClassmajorID = lessonRecordView.ClassmajorID; lessonRecord.CoursematerialID = lessonRecordView.CoursematerialID; lessonRecord.Weekday = lessonRecordView.Weekday; lessonRecord.CoursesTimeID = lessonRecordView.CoursesTimeID; lessonRecord.TotalScore = lessonRecordView.TotalScore; lessonRecord.Content = HttpUtility.HtmlDecode(lessonRecordView.Content); //lessonRecordView.Content.Replace("<", "<").Replace(">", ">").Replace("&", "&").Replace(""", "\"").Replace("&apos", "'"); //System.Text.RegularExpressions.Regex.Unescape(lessonRecordView.Content); lessonRecord.Record = HttpUtility.HtmlDecode(lessonRecordView.Record); //System.Text.RegularExpressions.Regex.Unescape(lessonRecordView.Record); lessonRecord.SUP_LessonRecordAttachment = new HashSet(); if (attachmentList!=null) { attachmentList.ToList().ForEach(x => { var attachment = new SUP_LessonRecordAttachment(); attachment.LessonRecordAttachmentID = Guid.NewGuid(); attachment.LessonRecordID = lessonRecord.LessonRecordID; attachment.Name = x.FileName; attachment.Url = x.FileUrl; this.SetNewStatus(attachment); UnitOfWork.Add(attachment); }); } UnitOfWork.Commit(); } public void Delete(IList lessonRecordIDList) { UnitOfWork.Delete(x => lessonRecordIDList.Contains(x.LessonRecordID)); UnitOfWork.Delete(x => lessonRecordIDList.Contains(x.LessonRecordID)); } public List GetFileList(Guid? formID) { return LessonRecordDAL.GetLessonRecordAttachmentQueryable(x => x.LessonRecordID == formID).ToList(); } } }