public async Task <IEnumerable <CustomerResponseDto> > Handle(GetCustomerQuery request, CancellationToken cancellationToken) { using var dbContext = _dataContextFactory.SpawnDbContext(); var list = await dbContext.Customers.Include(x => x.Orders).ToListAsync(cancellationToken); return(_mapper.Map <IEnumerable <CustomerResponseDto> >(list)); }
public async Task <IEnumerable <BrandResponseDto> > Handle(GetBrandQuery request, CancellationToken cancellationToken) { using var dbContext = _dataContextFactory.SpawnDbContext(); var brands = await dbContext.Brands.ToListAsync(cancellationToken); return(_mapper.Map <IEnumerable <BrandResponseDto> >(brands)); }
public async Task <IEnumerable <StaffResponseDto> > Handle(GetStaffQuery request, CancellationToken cancellationToken) { using var dbcontext = _dataContextFactory.SpawnDbContext(); var staffList = await dbcontext.Staffs.ToListAsync(); return(_mapper.Map <IEnumerable <StaffResponseDto> >(staffList)); }
public async Task <IEnumerable <CategoryResponseDto> > Handle(GetCategoryQuery request, CancellationToken cancellationToken) { using var dbcontext = _dataContextFactory.SpawnDbContext(); var categories = await dbcontext.Categories.ToListAsync(); return(_mapper.Map <IEnumerable <CategoryResponseDto> >(categories)); }
public async Task <IEnumerable <ProductResponseDto> > Handle(GetProductQuery request, CancellationToken cancellationToken) { using var dbcontext = _dataContextFactory.SpawnDbContext(); var products = await dbcontext.Products.Include(c => c.Category).Include(b => b.Brand).ToListAsync(); return(_mapper.Map <IEnumerable <ProductResponseDto> >(products)); }
public async Task <CustomerResponseDto> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) { var entity = _mapper.Map <Customer>(request.CustomerRequestDto); using var dbcontext = _dataContextFactory.SpawnDbContext(); dbcontext.Customers.Update(entity); await dbcontext.SaveChangesAsync().ConfigureAwait(false); return(_mapper.Map <CustomerResponseDto>(entity)); }
public async Task <BrandResponseDto> Handle(CreateBrandCommand request, CancellationToken cancellationToken) { var entity = _mapper.Map <Brand>(request.BrandRequestDto); using var dbContext = _dataContextFactory.SpawnDbContext(); dbContext.Brands.Add(entity); await dbContext.SaveChangesAsync().ConfigureAwait(false); return(_mapper.Map <BrandResponseDto>(entity)); }
public async Task <IEnumerable <GetOrdersResponseDto> > Handle(GetOrderQuery request, CancellationToken cancellationToken) { using var dbContext = _dataContextFactory.SpawnDbContext(); var list = await dbContext.Orders .Include(c => c.Customer) .Include(s => s.Staff) .Include(s => s.Store) .Include(o => o.OrderItems).ThenInclude(p => p.Product) .ToListAsync(cancellationToken); return(_mapper.Map <IEnumerable <GetOrdersResponseDto> >(list)); }
public async Task <UpdateOrderResponseDto> Handle(UpdateOrderCommand request, CancellationToken cancellationToken) { var OrderId = new SqlParameter("@OrderId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.OrderId }; var OrderItemId = new SqlParameter("@OrderItemId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.OrderItemId }; var CustId = new SqlParameter("@CustId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.CustomerId }; var StaffId = new SqlParameter("@StaffId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.StaffId }; var StoreId = new SqlParameter("@StoreId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.StoreId }; var ProductId = new SqlParameter("@ProductId", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.ProductId }; var Quantity = new SqlParameter("@Quantity", SqlDbType.Int) { Value = request.UpdateOrderRequestDto.Quantity }; var OrderStatus = new SqlParameter("@OrderStatus", SqlDbType.VarChar, 255) { Value = request.UpdateOrderRequestDto.OrderStatus }; //var ShippedDate = new SqlParameter("@ShippedDate", SqlDbType.DateTime2) //{ // Value = DateTime.UtcNow.AddDays(_configuration.GetValue<int>("AppSettings:ExpectingDeliveryInDays")) //}; var IsSuccess = new SqlParameter("@IsError", SqlDbType.Bit) { Direction = ParameterDirection.Output }; var ResponseMessage = new SqlParameter("@ResponseMessage", SqlDbType.VarChar, 255) { Direction = ParameterDirection.Output }; bool? isSuccess = null; string message = ""; using var dbcontext = _dataContextFactory.SpawnDbContext(); var result = await dbcontext.Database.ExecuteSqlInterpolatedAsync($"EXEC updateOrderDetails @OrderId={OrderId.Value}, @OrderItemId={OrderId.Value}, @CustId={CustId.Value}, @StaffId={StaffId.Value}, @StoreId={StoreId.Value}, @ProductId={ProductId.Value}, @Quantity={Quantity.Value}, @OrderStatus={OrderStatus.Value}, @IsSuccess={IsSuccess} out, @ResponseMessage={ResponseMessage} out"); if (IsSuccess.Value != DBNull.Value) { isSuccess = (bool)IsSuccess.Value; } if (ResponseMessage.Value != DBNull.Value) { message = (string)ResponseMessage.Value; } await dbcontext.SaveChangesAsync().ConfigureAwait(false); var entity = new OrderResults { Success = isSuccess, Message = message }; return(_mapper.Map <UpdateOrderResponseDto>(entity)); }