public ChuChaiDTO Add(ChuChaiDTO itemDto, UserDTO operatorDTO = null) { var model = itemDto.ToModel(); model.Id = IdentityGenerator.NewSequentialGuid(); model.Created = DateTime.UtcNow; model.Canceled = SqlDateTime.MinValue.Value; model.Approved = SqlDateTime.MinValue.Value; model.OutTime = model.OutTime.ToUniversalTime(); model.InTime = model.InTime.ToUniversalTime(); // 数据验证 this.ValidateModel(model); model.Status = KaoQinStatusDTO.Submited.ToString(); _Repository.Add(model); this.OperationLog(KaoQinMessagesResources.Add_ChuChai, model.ToDto(), null, operatorDTO); //commit the unit of work _Repository.UnitOfWork.Commit(); return(model.ToDto()); }
public void Approve(ChuChaiDTO itemDto, UserDTO operatorDTO = null) { //get persisted item var persistedModel = _Repository.Get(itemDto.Id); if (persistedModel == null) { throw new DataNotFoundException(KaoQinMessagesResources.ChuChai_NotExists); } if (persistedModel.Status == KaoQinStatusDTO.Canceled.ToString()) { throw new DataNotFoundException(KaoQinMessagesResources.Canceled_CanNot_Approved); } if (itemDto.DepartmentOpinion.IsNullOrBlank() && itemDto.GeneralManagerOfficeOpinion.IsNullOrBlank() && itemDto.CompanyLeaderOpinion.IsNullOrBlank()) { throw new DataNotFoundException(KaoQinMessagesResources.Approve_Opinion_Empty); } if (persistedModel.DepartmentOpinion != itemDto.DepartmentOpinion) { UpdateDepartmentOpinion(persistedModel, itemDto, operatorDTO); } if (persistedModel.GeneralManagerOfficeOpinion != itemDto.GeneralManagerOfficeOpinion) { UpdateGeneralManagerOfficeOpinion(persistedModel, itemDto, operatorDTO); } if (persistedModel.CompanyLeaderOpinion != itemDto.CompanyLeaderOpinion) { UpdateCompanyLeaderOpinion(persistedModel, itemDto, operatorDTO); } }
public static string GetOperationLog(this ChuChaiDTO entity, ChuChaiDTO oldDTO = null) { var sb = new StringBuilder(); if (oldDTO == null) { sb.AppendLine(string.Format("{0}: {1}", "员工编号", entity.UserId)); sb.AppendLine(string.Format("{0}: {1}", "姓名", entity.Name)); sb.AppendLine(string.Format("{0}: {1}", "部门", entity.Department)); sb.AppendLine(string.Format("{0}: {1}", "职位", entity.Position)); sb.AppendLine(string.Format("{0}: {1}", "出差时间", entity.OutTime)); sb.AppendLine(string.Format("{0}: {1}", "返回时间", entity.InTime)); sb.AppendLine(string.Format("{0}: {1}", "出差地点", entity.OutPlace)); sb.AppendLine(string.Format("{0}: {1}", "出差工作事由", entity.OutReason)); sb.AppendLine(string.Format("{0}: {1}", "状态", entity.Status)); } else { if (entity.DepartmentOpinion != oldDTO.DepartmentOpinion) { sb.AppendLine(string.Format("{0}: {1} => {2}", "部门意见", oldDTO.DepartmentOpinion, entity.DepartmentOpinion)); } if (entity.DepartmentOpinionApproverId != oldDTO.DepartmentOpinionApproverId) { sb.AppendLine(string.Format("{0}: {1} => {2}", "部门意见审批人", oldDTO.DepartmentOpinionApproverId, entity.DepartmentOpinionApproverId)); } if (entity.GeneralManagerOfficeOpinion != oldDTO.GeneralManagerOfficeOpinion) { sb.AppendLine(string.Format("{0}: {1} => {2}", "总经办意见", oldDTO.GeneralManagerOfficeOpinion, entity.GeneralManagerOfficeOpinion)); } if (entity.GeneralManagerOfficeOpinionApproverId != oldDTO.GeneralManagerOfficeOpinionApproverId) { sb.AppendLine(string.Format("{0}: {1} => {2}", "总经办意见审批人", oldDTO.GeneralManagerOfficeOpinionApproverId, entity.GeneralManagerOfficeOpinionApproverId)); } if (entity.CompanyLeaderOpinion != oldDTO.CompanyLeaderOpinion) { sb.AppendLine(string.Format("{0}: {1} => {2}", "公司领导意见", oldDTO.CompanyLeaderOpinion, entity.CompanyLeaderOpinion)); } if (entity.CompanyLeaderOpinionApproverId != oldDTO.CompanyLeaderOpinionApproverId) { sb.AppendLine(string.Format("{0}: {1} => {2}", "公司领导意见审批人", oldDTO.CompanyLeaderOpinionApproverId, entity.CompanyLeaderOpinionApproverId)); } if (entity.Status != oldDTO.Status) { sb.AppendLine(string.Format("{0}: {1} => {2}", "状态", oldDTO.Status, entity.Status)); } } return(sb.ToString().TrimEnd('\r', '\n')); }
public ActionResult Apply(ChuChaiDTO item) { return(HttpHandleExtensions.AjaxCallGetResult(() => { var department = GetCurrentMemberDepartment(); item.UserId = CurrentMember.Userid; item.Name = CurrentMember.Name; item.Position = CurrentMember.Position; item.DepartmentId = department.DepartmentId; item.Department = department.Name; _chuChaiService.Add(item, GetCurrentOperator()); this.JsMessage = MessagesResources.Add_Success; return Json(new AjaxResponse { Succeeded = true, RedirectUrl = Url.Action("Index") }); })); }
public ActionResult Approve(ChuChaiDTO item) { return(HttpHandleExtensions.AjaxCallGetResult(() => { if (!IsWeiXinManager()) { throw new DefinedException(NotWeiXinManagerMessage); } item.DepartmentOpinionApproverId = CurrentMember.Userid; item.GeneralManagerOfficeOpinionApproverId = CurrentMember.Userid; item.CompanyLeaderOpinionApproverId = CurrentMember.Userid; _chuChaiService.Approve(item, GetCurrentOperator()); this.JsMessage = MessagesResources.Approve_Success; return Json(new AjaxResponse { Succeeded = true, RedirectUrl = Url.Action("Approved") }, JsonRequestBehavior.AllowGet); })); }
private void UpdateCompanyLeaderOpinion(ChuChai persistedModel, ChuChaiDTO itemDto, UserDTO operatorDTO = null) { var oldDTO = persistedModel.ToDto(); // 可以修改的字段 var current = oldDTO.ToModel(); current.CompanyLeaderOpinion = itemDto.CompanyLeaderOpinion; current.CompanyLeaderOpinionApproverId = itemDto.CompanyLeaderOpinionApproverId; if (persistedModel.Status == KaoQinStatusDTO.Submited.ToString()) { current.Status = KaoQinStatusDTO.Approved.ToString(); current.Approved = DateTime.UtcNow; } this.OperationLog(KaoQinMessagesResources.Update_ChuChai, current.ToDto(), oldDTO, operatorDTO); //Merge changes _Repository.Merge(persistedModel, current); //commit unit of work _Repository.UnitOfWork.Commit(); }
/*********** * 微信用户操作时,不能通过cookies找到登陆用户,因此,在表现层传当前的微信用户进来作为操作者 *************/ private void OperationLog(string action, ChuChaiDTO itemDto, ChuChaiDTO oldDto = null, UserDTO operatorDTO = null) { OperateRecorder.RecordOperation(itemDto.Id.ToString(), action, itemDto.GetOperationLog(oldDto), operatorDTO); }
public static ChuChai ToModel(this ChuChaiDTO dto) { return(Mapper.Map <ChuChai>(dto)); }