diff --git a/SMS.Services/AttendanceManagement/AddAttendanceProcessor.cs b/SMS.Services/AttendanceManagement/AddAttendanceProcessor.cs new file mode 100644 index 0000000..bd84621 --- /dev/null +++ b/SMS.Services/AttendanceManagement/AddAttendanceProcessor.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SMS.Services.Entities; +using Youmay.Exceptions; +using Youmay.Services.Utils; +using NHibernate.Linq; +using SMS.Services.Enum; + +namespace SMS.Services.AttendanceManagement +{ + public class AddAttendanceProcessor + { + private ExecuteContext context; + + public AddAttendanceProcessor(ExecuteContext context) + { + this.context = context; + } + + public int Execute(AttendanceAddView view) + { + var student = LogicUtils.NotNull(context.Session.Get(context.OperatorInfo.OperatorId)); + var lesson = LogicUtils.NotNull(context.Session.Get(context.OperatorInfo.OperatorId)); + + DateTime start = lesson.TakeClassDate; + DateTime end = lesson.TakeClassDate; + + switch (lesson.LessonType) + { + case LessonType.Morning: + start = new DateTime(start.Year, start.Month, start.Day, 10, 0, 0); + end = new DateTime(start.Year, start.Month, start.Day, 11, 0, 0); + break; + case LessonType.Afternoon1: + start = new DateTime(start.Year, start.Month, start.Day, 12, 0, 0); + end = new DateTime(start.Year, start.Month, start.Day, 14, 0, 0); + break; + case LessonType.Afternoon2: + start = new DateTime(start.Year, start.Month, start.Day, 14, 0, 0); + end = new DateTime(start.Year, start.Month, start.Day, 16, 0, 0); + break; + case LessonType.Evening: + start = new DateTime(start.Year, start.Month, start.Day, 20, 0, 0); + end = new DateTime(start.Year, start.Month, start.Day, 22, 0, 0); + break; + default: + break; + } + + if (lesson.TakeClassDate < start.AddMinutes(-15) || lesson.TakeClassDate > end) + throw new AttendanceException(AttendanceExceptionType.NotAttendanceTime); + + var attendace = new Attendance() + { + Student = student, + Lesson = lesson, + AttendanceType = view.AttendanceType, + AttendanceDateTime = DateTime.Now, + Remark = view.Remark + }; + + using (var scope = context.Session.RequestTransaction()) + { + context.Session.Save(attendace); + scope.Commit(); + } + return attendace.Id; + } + + } +} diff --git a/SMS.Services/AttendanceManagement/AttendanceAddView.cs b/SMS.Services/AttendanceManagement/AttendanceAddView.cs new file mode 100644 index 0000000..6d74680 --- /dev/null +++ b/SMS.Services/AttendanceManagement/AttendanceAddView.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SMS.Services.Enum; + +namespace SMS.Services.AttendanceManagement +{ + public class AttendanceAddView + { + public int LessonId { get; set; } + + public AttendanceType AttendanceType { get; set; } + + public string Remark { get; set; } + } +} diff --git a/SMS.Services/AttendanceManagement/AttendanceException.cs b/SMS.Services/AttendanceManagement/AttendanceException.cs new file mode 100644 index 0000000..aa120a1 --- /dev/null +++ b/SMS.Services/AttendanceManagement/AttendanceException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using SMS.Services.Enum; + +namespace SMS.Services.AttendanceManagement +{ + public class AttendanceException : Exception + { + public AttendanceExceptionType Type { get; set; } + + public AttendanceException(AttendanceExceptionType type) + { + this.Type = type; + } + } +} diff --git a/SMS.Services/Entities/Attendance.cs b/SMS.Services/Entities/Attendance.cs index 7fb56df..6b1d23a 100644 --- a/SMS.Services/Entities/Attendance.cs +++ b/SMS.Services/Entities/Attendance.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using SMS.Services.Enum; namespace SMS.Services.Entities { @@ -22,10 +23,20 @@ public class Attendance /// public virtual Student Student { get; set; } + /// + /// 出勤类型 + /// + public virtual AttendanceType AttendanceType { get; set; } + /// /// 出勤时间 /// public virtual DateTime? AttendanceDateTime { get; set; } + /// + /// 原因 + /// + public virtual string Remark { get; set; } + } } diff --git a/SMS.Services/Enum/AttendanceExceptionType.cs b/SMS.Services/Enum/AttendanceExceptionType.cs new file mode 100644 index 0000000..f82b24b --- /dev/null +++ b/SMS.Services/Enum/AttendanceExceptionType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SMS.Services.Enum +{ + public enum AttendanceExceptionType + { + /// + /// 不是出勤时间,不能出勤 + /// + NotAttendanceTime + } +} diff --git a/SMS.Services/Enum/AttendanceType.cs b/SMS.Services/Enum/AttendanceType.cs new file mode 100644 index 0000000..df50e4b --- /dev/null +++ b/SMS.Services/Enum/AttendanceType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SMS.Services.Enum +{ + public enum AttendanceType + { + + /// + /// 到达 + /// + Arrive, + + + /// + /// 请假 + /// + AskOff, + + } +} diff --git a/SMS.Services/SMS.Services.csproj b/SMS.Services/SMS.Services.csproj index e7eebb9..08a3d17 100644 --- a/SMS.Services/SMS.Services.csproj +++ b/SMS.Services/SMS.Services.csproj @@ -64,6 +64,9 @@ + + + @@ -87,6 +90,8 @@ + + diff --git a/SMS.Web/Controllers/AttendanceController.cs b/SMS.Web/Controllers/AttendanceController.cs new file mode 100644 index 0000000..e8a5013 --- /dev/null +++ b/SMS.Web/Controllers/AttendanceController.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using SMS.Services; +using SMS.Web.Models; +using SMS.Web.Models.Attendance; +using SMS.Services.AttendanceManagement; +using SMS.Web.Common; + +namespace SMS.Web.Controllers +{ + public class AttendanceController : ManagementController + { + private Repository repository; + + private ProcessorManager manager; + + public AttendanceController(Repository repository, ProcessorManager manager) + { + this.repository = repository; + this.manager = manager; + } + + public ActionResult Index() + { + return View(); + } + + [HttpPost] + public ActionResult Create(CreateForm form) + { + if (ModelState.IsValid) + { + try + { + var processor = manager.Create(); + processor.Execute(ConvertTo(form)); + + ViewSuccessMessage("签到成功"); + + } + catch (AttendanceException e) + { + if (e.Type == Services.Enum.AttendanceExceptionType.NotAttendanceTime) + ViewErrorMessage("现在不是上课时间,不能签到"); + } + } + + return AjaxJson(); + } + + } +} diff --git a/SMS.Web/Controllers/ClassLessonController.cs b/SMS.Web/Controllers/ClassLessonController.cs index efd03ab..7af71f9 100644 --- a/SMS.Web/Controllers/ClassLessonController.cs +++ b/SMS.Web/Controllers/ClassLessonController.cs @@ -29,5 +29,7 @@ public ClassLessonController(Repository repository, ProcessorManager manager) return View(new IndexViewModel(manager.Create().Execute(id.Value))); } + + } } diff --git a/SMS.Web/Models/Attendance/CreateForm.cs b/SMS.Web/Models/Attendance/CreateForm.cs new file mode 100644 index 0000000..444da31 --- /dev/null +++ b/SMS.Web/Models/Attendance/CreateForm.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using SMS.Services.Enum; + +namespace SMS.Web.Models.Attendance +{ + public class CreateForm + { + public int LessonId { get; set; } + + public AttendanceType AttendanceType { get; set; } + + public string Remark { get; set; } + } +} \ No newline at end of file diff --git a/SMS.Web/SMS.Web.csproj b/SMS.Web/SMS.Web.csproj index b279d3e..3fd586c 100644 --- a/SMS.Web/SMS.Web.csproj +++ b/SMS.Web/SMS.Web.csproj @@ -156,6 +156,7 @@ + @@ -166,6 +167,7 @@ Global.asax + diff --git a/SMS.Web/Views/ClassLesson/Index.cshtml b/SMS.Web/Views/ClassLesson/Index.cshtml index 5cb215f..0855f51 100644 --- a/SMS.Web/Views/ClassLesson/Index.cshtml +++ b/SMS.Web/Views/ClassLesson/Index.cshtml @@ -3,6 +3,29 @@ 课表 } @section SiteHead{ + } @section SiteMap{ 课表 @@ -57,7 +80,8 @@ @Model.ClassLessons[start + j].Name
@Model.ClassLessons[start + j].TakeClassDate.ToString("yyyy年MM月dd日 ddd") - +
+ } } diff --git a/SMS.Web/Web.config b/SMS.Web/Web.config index 7e24561..f284b39 100644 --- a/SMS.Web/Web.config +++ b/SMS.Web/Web.config @@ -14,33 +14,11 @@ - - - - - - - - - + + + + - - - - - - - - - - - - - - - - -