예제 #1
0
        /// <summary>
        /// 按Id获取
        /// </summary>
        /// <param name="primaryId">主键Id</param>
        /// <returns>业务对象</returns>
        public T1 GetById <T1, T2>(dynamic primaryId)
            where T1 : class
            where T2 : class
        {
            T2 t2 = _dataRepository.GetById <T2>(primaryId);

            return(AutoMapperHelper <T2, T1> .AutoConvert(t2));
        }
예제 #2
0
        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public bool Update <T1, T2>(T1 entity, IDbTransaction transaction = null)
            where T1 : class
            where T2 : class
        {
            var item = AutoMapperHelper <T1, T2> .AutoConvert(entity);

            return(_dataRepository.Update <T2>(item, transaction));
        }
예제 #3
0
        /// <summary>
        /// 插入操作
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public dynamic Insert <T1, T2>(T1 entity, IDbTransaction transaction = null)
            where T1 : class
            where T2 : class
        {
            T2 item = AutoMapperHelper <T1, T2> .AutoConvert(entity);

            return(_dataRepository.Insert <T2>(item, transaction));
        }
예제 #4
0
        /// <summary>
        /// 根据ID列表查询数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IEnumerable <StudentDto> GetStudentsByIds(List <dynamic> ids)
        {
            var sql = "SELECT * FROM DBO.STUDENT WHERE SID IN ('@ids')";

            var idsIn = string.Join("','", ids);

            var students = DataRepository.GetList <Student>(sql, new { ids = idsIn });

            return(AutoMapperHelper <IEnumerable <Student>, IEnumerable <StudentDto> > .AutoConvert(students));
        }
예제 #5
0
        /// <summary>
        /// 根据用户名和密码查询用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public T_UserDto LoginByUsername(T_UserSingleModel model)
        {
            var password = MD5Helper.ComputeMD5(model.Password);

            string sql = "SELECT * FROM T_USER WHERE USERNAME = @P_USERNAME AND PASSWORD= @P_PASSWORD";

            var user = DataRepository.GetFirstOrDefault <T_User>(sql, new { P_USERNAME = model.Username, P_PASSWORD = password });

            return(AutoMapperHelper <T_User, T_UserDto> .AutoConvert(user));
        }
예제 #6
0
        /// <summary>
        /// 批量更新订单数据
        /// </summary>
        /// <param name="entityList"></param>
        public void UpdateBatch(IEnumerable <OrderView> entityList)
        {
            Order epOrder = null;

            foreach (var entity in entityList)
            {
                epOrder = AutoMapperHelper <OrderView, Order> .AutoConvert(entity);

                Update <Order, EPOrder>(epOrder);
            }
        }
예제 #7
0
        /// <summary>
        /// 根据条件查询数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IEnumerable <StudentDto> GetStudentsByCondition(StudentSingleModel model)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT * FROM DBO.STUDENT ");
            sb.Append("WHERE 1=1 ");
            if (!string.IsNullOrEmpty(model.Name))
            {
                sb.Append("AND SNAME LIKE @TMP_NAME ");
            }
            sb.Append("ORDER BY SID");

            var students = DataRepository.GetList <Student>(sb.ToString(), new { TMP_NAME = $"%{model.Name}%" });

            return(AutoMapperHelper <IEnumerable <Student>, IEnumerable <StudentDto> > .AutoConvert(students));
        }
예제 #8
0
        /// <summary>
        /// 添加学生
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public dynamic AddStudent(StudentSingleModel model)
        {
            var transaction = DataRepository.Session.Begin();

            try
            {
                var student = AutoMapperHelper <StudentSingleModel, Student> .AutoConvert(model);

                var itemId = DataRepository.Insert <Student>(student, transaction);
                DataRepository.Session.Commit();

                return(itemId);
            }
            catch (Exception ex)
            {
                DataRepository.Session.Rollback();
                logger.Error(ex);

                return(string.Empty);
            }
        }
예제 #9
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public PagedDto GetStudentsPagination(StudentPagedModel model)
        {
            var predicateGroup = new PredicateGroup {
                Operator = GroupOperator.And, Predicates = new List <IPredicate>()
            };

            if (!string.IsNullOrEmpty(model.Sex))
            {
                var predicate1 = Predicates.Field <Student>(n => n.Ssex, Operator.Eq, model.Sex);
                predicateGroup.Predicates.Add(predicate1);
            }
            if (!string.IsNullOrEmpty(model.Name))
            {
                var predicate2 = Predicates.Field <Student>(n => n.Sname, Operator.Like, model.Name);
                predicateGroup.Predicates.Add(predicate2);
            }

            IList <ISort> sort = new List <ISort>
            {
                new Sort()
                {
                    PropertyName = "sid", Ascending = true
                },
                new Sort()
                {
                    PropertyName = "sage", Ascending = false
                }
            };

            long totalCount = 0L;
            var  students   = DataRepository.GetPage <Student>(model.PageIndex, model.PageSize, out totalCount, predicateGroup, sort);
            var  dataList   = AutoMapperHelper <IEnumerable <Student>, IEnumerable <StudentDto> > .AutoConvert(students);

            return(new PagedDto()
            {
                Count = totalCount,
                Data = dataList
            });
        }
예제 #10
0
        /// <summary>
        /// 根据ID获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public StudentDto GetStudentById(string id)
        {
            var student = DataRepository.Get <Student>(id);

            return(AutoMapperHelper <Student, StudentDto> .AutoConvert(student));
        }