Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
267 additions
and
27 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
SMS.Services/AttendanceManagement/AddAttendanceProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Student>(context.OperatorInfo.OperatorId)); | ||
var lesson = LogicUtils.NotNull(context.Session.Get<Lesson>(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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SMS.Services.Enum | ||
{ | ||
public enum AttendanceExceptionType | ||
{ | ||
/// <summary> | ||
/// 不是出勤时间,不能出勤 | ||
/// </summary> | ||
NotAttendanceTime | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SMS.Services.Enum | ||
{ | ||
public enum AttendanceType | ||
{ | ||
|
||
/// <summary> | ||
/// 到达 | ||
/// </summary> | ||
Arrive, | ||
|
||
|
||
/// <summary> | ||
/// 请假 | ||
/// </summary> | ||
AskOff, | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AddAttendanceProcessor>(); | ||
processor.Execute(ConvertTo<AttendanceAddView>(form)); | ||
|
||
ViewSuccessMessage("签到成功"); | ||
|
||
} | ||
catch (AttendanceException e) | ||
{ | ||
if (e.Type == Services.Enum.AttendanceExceptionType.NotAttendanceTime) | ||
ViewErrorMessage("现在不是上课时间,不能签到"); | ||
} | ||
} | ||
|
||
return AjaxJson(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters