/// <summary> /// Получить список заказов /// </summary> /// <param name="request"></param> /// <returns></returns> public PaginationResponse <OrderAdmin.OrderHeaderModel> GetFilteredOrders(PaginationRequest <BaseFilter> request) { using (var db = new DataContext()) { var query = db.OrderHeaders.AsNoTracking().Include(x => x.User.UserAddress) .Where(x => !x.IsDelete.HasValue && x.Status != (int)EnumStatusOrder.Cart) .OrderByDescending(x => x.DateCreate) as IQueryable <OrderHeader>; //if (!string.IsNullOrEmpty(request.Filter.Term)) // query = query.Where(x => x.Code.ToLower().Contains(request.Filter.Term.ToLower())); var model = new PaginationResponse <OrderAdmin.OrderHeaderModel> { Count = query.Count() }; query = request.Load(query); model.Items = query.ToList().Select(x => new OrderAdmin.OrderHeaderModel { Id = x.Id, DateCreate = x.DateCreate, UserName = $"{x.User?.FirstName} {x.User?.LastName}", StatusName = EnumService.GetEnumDescription((EnumStatusOrder)x.Status), Amount = x.Amount }).ToList(); return(model); } }
/// <summary> /// Получить модель заказа /// </summary> /// <param name="orderId">Ид заказа</param> /// <returns></returns> public BaseResponse <OrderAdmin.OrderHeaderModel> GetOrderHeaderModel(int orderId) { using (var db = new DataContext()) { var order = db.OrderHeaders.Include(x => x.User.UserAddress) .Where(x => x.Id == orderId).ToList().Select(x => new OrderAdmin.OrderHeaderModel { Id = x.Id, DateCreate = x.DateCreate, UserName = $"{x.User?.FirstName} {x.User?.LastName}", Status = x.Status, StatusName = EnumService.GetEnumDescription((EnumStatusOrder)x.Status), Amount = x.Amount, Address = GetAddress(x.Address) }).FirstOrDefault(); if (order == null) { return(new BaseResponse <OrderAdmin.OrderHeaderModel>(EnumResponseStatus.Error, "Заказ не найден")); } order.OrderProducts = GetOrderProducts(orderId, db); return(new BaseResponse <OrderAdmin.OrderHeaderModel>(order)); } }