Пример #1
0
        private void ValidateModel(XiuJia model)
        {
            if (model.Name.IsNullOrBlank())
            {
                throw new DefinedException(KaoQinMessagesResources.UserName_Empty);
            }

            if (model.UserId.IsNullOrBlank())
            {
                throw new DefinedException(KaoQinMessagesResources.UserId_Empty);
            }

            if (model.DepartmentId == 0)
            {
                throw new DefinedException(KaoQinMessagesResources.DepartmentId_Empty);
            }

            if (model.Position.IsNullOrBlank())
            {
                throw new DefinedException(KaoQinMessagesResources.Position_Empty);
            }

            if (model.ActionStartTime > model.ActionEndTime)
            {
                throw new DefinedException(KaoQinMessagesResources.XiuJia_StartTime_Greater_Than_EndTime);
            }

            if (model.Type.IsNullOrBlank())
            {
                throw new DefinedException(KaoQinMessagesResources.XiuJia_Type_Empty);
            }

            if (model.Reason.IsNullOrBlank())
            {
                throw new DefinedException(KaoQinMessagesResources.XiuJia_Reason_Empty);
            }

            if (model.ActionDays <= 0 && model.ActionHours <= 0)
            {
                throw new DefinedException(KaoQinMessagesResources.XiuJia_Days_Hours_Empty);
            }

            if (_Repository.Exists(model))
            {
                throw new DataExistsException(string.Format(KaoQinMessagesResources.XiuJia_Exists_WithValue, model.UserId, model.ActionStartTime.ToLocalTime()));
            }
        }
Пример #2
0
        private void UpdateCompanyLeaderOpinion(XiuJia persistedModel, XiuJiaDTO 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_XiuJia, current.ToDto(), oldDTO, operatorDTO);

            //Merge changes
            _Repository.Merge(persistedModel, current);
            //commit unit of work
            _Repository.UnitOfWork.Commit();
        }
 public static XiuJiaDTO ToDto(this XiuJia model)
 {
     return(Mapper.Map <XiuJiaDTO>(model));
 }