public WeiDaKaDTO Add(WeiDaKaDTO 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.InputTime = DateTime.Today;

            model.ActionTime = model.ActionTime.ToUniversalTime();

            // 数据验证
            this.ValidateModel(model);

            model.Status = KaoQinStatusDTO.Submited.ToString();;

            _Repository.Add(model);

            this.OperationLog(KaoQinMessagesResources.Add_WeiDaKa, model.ToDto(), null, operatorDTO);

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(model.ToDto());
        }
        public void Approve(WeiDaKaDTO itemDto, UserDTO operatorDTO = null)
        {
            //get persisted item
            var persistedModel = _Repository.Get(itemDto.Id);

            if (persistedModel == null)
            {
                throw new DataNotFoundException(KaoQinMessagesResources.WaiQin_NotExists);
            }

            if (persistedModel.Status == KaoQinStatusDTO.Canceled.ToString())
            {
                throw new DataNotFoundException(KaoQinMessagesResources.Canceled_CanNot_Approved);
            }

            if (itemDto.DepartmentOrCompanyOpinion.IsNullOrBlank())
            {
                throw new DataNotFoundException(KaoQinMessagesResources.Approve_Opinion_Empty);
            }

            if (persistedModel.DepartmentOrCompanyOpinion != itemDto.DepartmentOrCompanyOpinion)
            {
                UpdateDepartmentOrCompanyOpinion(persistedModel, itemDto, operatorDTO);
            }
        }
        public ActionResult Apply(WeiDaKaDTO 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;
                _weiDaKaService.Add(item, GetCurrentOperator());
                this.JsMessage = MessagesResources.Add_Success;

                return Json(new AjaxResponse
                {
                    Succeeded = true,
                    RedirectUrl = Url.Action("Index")
                });
            }));
        }
        public ActionResult Approve(WeiDaKaDTO item)
        {
            return(HttpHandleExtensions.AjaxCallGetResult(() =>
            {
                if (!IsWeiXinManager())
                {
                    throw new DefinedException(NotWeiXinManagerMessage);
                }

                item.DepartmentOrCompanyOpinionApproverId = CurrentMember.Userid;
                _weiDaKaService.Approve(item, GetCurrentOperator());

                this.JsMessage = MessagesResources.Approve_Success;
                return Json(new AjaxResponse
                {
                    Succeeded = true,
                    RedirectUrl = Url.Action("Approved")
                }, JsonRequestBehavior.AllowGet);
            }));
        }
        private void UpdateDepartmentOrCompanyOpinion(WeiDaKa persistedModel, WeiDaKaDTO itemDto, UserDTO operatorDTO = null)
        {
            var oldDTO = persistedModel.ToDto();

            // 可以修改的字段
            var current = oldDTO.ToModel();

            current.DepartmentOrCompanyOpinion           = itemDto.DepartmentOrCompanyOpinion;
            current.DepartmentOrCompanyOpinionApproverId = itemDto.DepartmentOrCompanyOpinionApproverId;

            if (persistedModel.Status == KaoQinStatusDTO.Submited.ToString())
            {
                current.Status   = KaoQinStatusDTO.Approved.ToString();
                current.Approved = DateTime.UtcNow;
            }

            this.OperationLog(KaoQinMessagesResources.Update_WeiDaKa, current.ToDto(), oldDTO, operatorDTO);

            //Merge changes
            _Repository.Merge(persistedModel, current);
            //commit unit of work
            _Repository.UnitOfWork.Commit();
        }
        public static string GetOperationLog(this WeiDaKaDTO entity, WeiDaKaDTO 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.InputTime));
                sb.AppendLine(string.Format("{0}: {1}", "未打卡时间", entity.ActionTime));
                sb.AppendLine(string.Format("{0}: {1}", "未打卡类型", entity.Type));
                sb.AppendLine(string.Format("{0}: {1}", "未打卡原因", entity.Reason));
                sb.AppendLine(string.Format("{0}: {1}", "状态", entity.Status));
            }
            else
            {
                if (entity.DepartmentOrCompanyOpinion != oldDTO.DepartmentOrCompanyOpinion)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                "部门/公司意见", oldDTO.DepartmentOrCompanyOpinion, entity.DepartmentOrCompanyOpinion));
                }
                if (entity.DepartmentOrCompanyOpinionApproverId != oldDTO.DepartmentOrCompanyOpinionApproverId)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                "部门/公司意见审批人", oldDTO.DepartmentOrCompanyOpinionApproverId, entity.DepartmentOrCompanyOpinionApproverId));
                }
                if (entity.Status != oldDTO.Status)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                "状态", oldDTO.Status, entity.Status));
                }
            }

            return(sb.ToString().TrimEnd('\r', '\n'));
        }
 public static WeiDaKa ToModel(this WeiDaKaDTO dto)
 {
     return(Mapper.Map <WeiDaKa>(dto));
 }
 /***********
  * 微信用户操作时,不能通过cookies找到登陆用户,因此,在表现层传当前的微信用户进来作为操作者
  *************/
 private void OperationLog(string action, WeiDaKaDTO itemDto, WeiDaKaDTO oldDto = null, UserDTO operatorDTO = null)
 {
     OperateRecorder.RecordOperation(itemDto.Id.ToString(), action,
                                     itemDto.GetOperationLog(oldDto), operatorDTO);
 }