public async Task <OrderResponseModel> GetAsync(string userId, int id) { var order = await GetOrderAsync(id); var dishes = new List <BasketResponseItem>(); var items = await _context.OrderDishes.Include(x => x.Dish).Where(x => x.OrderId == id).ToListAsync(); foreach (var item in items) { dishes.Add(new BasketResponseItem { Id = item.DishId, Count = item.Count, Photo = item.Dish.Photo?[0], Price = item.Sum / item.Count }); } OrderResponseModel result = new OrderResponseModel { Id = order.Id, Sum = order.Sum, DeliveryMinutes = order.DeliveryMinutes, DeliverySum = order.DeliverySum, StatusId = order.StatusId, Address = new AddressEntity { ApartmentNumber = order.Address.ApartmentNumber, City = order.Address.City, HouseNumber = order.Address.HouseNumber, Street = order.Address.Street }, Dishes = dishes }; return(result); }
private AuthorizeRequestModel MapOrderToAuthorizeRequest(OrderResponseModel order, PlaceOrderModel placeOrder) { var model = new AuthorizeRequestModel { TransactionId = order.TransactionId, FirstName = order.Client.FirstName, LastName = order.Client.LastName, Email = order.Client.Email, IdentificationType = order.Client.IdentificationType, IdentificationNumber = order.Client.IdentificationNumber, PhoneNumber = order.Client.Phone, Amount = order.Total, CountryIsoCode = order.CountryIsoCode, CurrencyIsoCode = order.CurrencyIsoCode, OrderId = order.SaleOrderId, OrderGroup = order.OrderGroup, OrderNumber = order.SaleOrderId.ToString("D8"), SellerId = order.SellerId, SellerName = order.SellerName, Placeholder = placeOrder.Payment.Card.Placeholder, CardNumber = placeOrder.Payment.Card.CardNumber, Year = placeOrder.Payment.Card.Year, Month = placeOrder.Payment.Card.Month, Cvv = placeOrder.Payment.Card.Cvv, Installments = placeOrder.Payment.Card.Installments == 0 ? 1 : placeOrder.Payment.Card.Installments }; return(model); }
public void ReceiveResponse() { channel.ExchangeDeclare(exchange: Common.Constants.RabbitMQExchange, type: "direct"); channel.QueueDeclare(queue: customerTag, durable: false, exclusive: false, autoDelete: true, arguments: null); channel.QueueBind(queue: customerTag, exchange: Common.Constants.RabbitMQExchange, routingKey: customerTag); EventingBasicConsumer consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body.ToArray(); string responseStr = Encoding.UTF8.GetString(body); OrderResponseModel orderResponse = JsonConvert.DeserializeObject <OrderResponseModel>(responseStr); Console.WriteLine("{0} x '{1}' => {2} (Client ID = '{3}')", orderResponse.Quantity, orderResponse.ProductName, orderResponse.IsError ? "Couldn't Purchased" : "Purchased", customerId); }; channel.BasicConsume(queue: customerTag, autoAck: true, consumer: consumer); }
public static OrderResponseModel Map(OrderResponseDataModel responseFilter) { if (responseFilter is null) { return(new OrderResponseModel()); } var responseFilterModel = new OrderResponseModel { TotalCount = responseFilter.TotalCount }; foreach (var order in responseFilter.Orders) { var orderItemModels = new List <OrderItemModel>(); foreach (var orderItem in order.OrderItems) { if (orderItem == null) { continue; } var orderItemModel = _orderItemModelMapper.Map(orderItem); orderItemModel.PrintingEdition = _printingEditionModelMapper.Map(orderItem.PrintingEdition); orderItemModels.Add(orderItemModel); } var orderModel = _orderModelMapper.Map(order); orderModel.User = _userModelMapper.Map(order.User); orderModel.OrderItems = orderItemModels; responseFilterModel.Orders.Add(orderModel); } return(responseFilterModel); }
public OrderResponseModel GetOrdersOfFarmer(OrderRequestModel request) { OrderResponseModel response = new OrderResponseModel(); IOrderDataAccess _repository = new OrderDataAccess(); response.Orders = _repository.GetOrdersOfFamer(request.OrderRequest); return(response); }
public OrderResponseModel GetDeliveredOrders(OrderRequestModel request) { OrderResponseModel response = new OrderResponseModel(); IOrderDataAccess _repository = new OrderDataAccess(); response.Orders = _repository.GetDeliveredOrders(request.OrderRequest); return(response); }
public OrderResponseModel GetOrderDetailsById(OrderRequestModel request) { OrderResponseModel response = new OrderResponseModel(); IOrderDataAccess _repository = new OrderDataAccess(); response.OrderDetails = _repository.GetOrderDetailsById(request.OrderRequest); return(response); }
public void Present(OrderResponseModel order) { var viewModel = new OrderViewModel { id = order.id, state = order.state }; var json = JsonConvert.SerializeObject(viewModel); var bytes = Encoding.UTF8.GetBytes(json); _httpResponse.Body.WriteAsync(bytes); }
private static void PrintOrderDetails(OrderResponseModel orderResponse) { Console.WriteLine("Order Created Order Id: " + orderResponse.Id); foreach (var orderLine in orderResponse.Lines) { Console.WriteLine("Order Line: "); Console.WriteLine("-- ProductNumber: " + orderLine.ProductId); Console.WriteLine("-- ProductQuantity: " + orderLine.Quantity); Console.WriteLine("-- ProductStatus: " + orderLine.Status); } Console.WriteLine("======================="); }
public IActionResult GetById(Guid id) { ValidationResponse <Order> validationResponse = _orderService.GetById(id); if (validationResponse.Status == ValidationStatus.NotFound) { return(NotFound(validationResponse.Message)); } OrderResponseModel orderResponse = _mapper.Map <Order, OrderResponseModel>(validationResponse.ResponseData); return(Ok(orderResponse)); }
private static bool CheckOrderStatus(Guid orderId) { using (var client = new HttpClient()) { HttpResponseMessage response = client.GetAsync($"{url}/api/v1/checkout/status/{orderId}").Result; if (response.IsSuccessStatusCode) { OrderResponseModel orderResponse = response.Content.ReadAsAsync <OrderResponseModel>().Result; PrintOrderDetails(orderResponse); return(true); } } return(false); }
public OrderResponseModel Post([FromBody] OrderModel order) { ordersRepository.AddOrder(order); string filePath = Path.Combine(webRoot, "ImportantFile.txt"); OrderResponseModel model = new OrderResponseModel() { OrderReadyTime = DateTime.Now.AddMinutes(30), Items = order.Items, Filename = filePath, IsFileReadOnly = (new FileInfo(filePath)).IsReadOnly }; return(model); }
public IActionResult Post([FromBody] OrderRequestModel orderRequest) { Order order = _mapper.Map <OrderRequestModel, Order>(orderRequest); ValidationResponse <Order> validationResponse = _orderService.Add(order); if (validationResponse.Status == ValidationStatus.Failed) { return(BadRequest(validationResponse.Message)); } OrderResponseModel orderResponse = _mapper.Map <Order, OrderResponseModel>(validationResponse.ResponseData); return(CreatedAtAction("Get", new { id = orderResponse.Id }, orderResponse)); }
public OrderResponseModel Response(OrderModel orderModel) { OrderResponseModel order = new OrderResponseModel(); order.OrderId = orderModel.OrderId; order.CartId = orderModel.CartId; order.UserId = orderModel.UserId; order.AddressID = orderModel.AddressID; order.IsActive = orderModel.IsActive; order.IsPlaced = orderModel.IsPlaced; order.Quantity = orderModel.Quantity; order.TotalPrice = orderModel.TotalPrice; order.CreatedDate = orderModel.CreatedDate; order.ModificationDate = orderModel.ModificationDate; return(order); }
public List <OrderResponseModel> GetAllOrderValues() { try { List <OrderResponseModel> orderResponseList = new List <OrderResponseModel>(); var orderResponse = this.dbContext.Orders; foreach (var response in orderResponse) { OrderResponseModel order = new OrderResponseModel(); if (response.IsPlaced == "No") { order = Response(response); orderResponseList.Add(order); } } return(orderResponseList); } catch (Exception e) { throw new Exception(e.Message); } }
public IActionResult Put(Guid id, [FromBody] OrderRequestModel orderRequest) { Order order = _mapper.Map <OrderRequestModel, Order>(orderRequest); order.Id = id; ValidationResponse <Order> validationResponse = _orderService.Update(order); if (validationResponse.Status == ValidationStatus.NotFound) { return(NotFound(validationResponse.Message)); } if (validationResponse.Status == ValidationStatus.Failed) { return(BadRequest(validationResponse.Message)); } OrderResponseModel orderResponse = _mapper.Map <Order, OrderResponseModel>(validationResponse.ResponseData); return(Ok(orderResponse)); }
public static OrdersModelItem MapResponseModelToModelItem(OrderResponseModel model) { var responseModel = new OrdersModelItem { UserName = model.UserName, UserEmail = model.UserEmail, Id = model.OrderId, Description = model.Description, PaymentDate = model.OrderDate.ToShortDateString(), OrderStatus = (StatusEnum.StatusType)model.OrderStatus }; decimal amount = 0; var orderItemsModel = new List <OrderItemModelItem>(); foreach (var item in model.OrderItems) { amount += item.Amount; var orderItem = OrderItemMapper.MapEntityToModel(item); orderItemsModel.Add(orderItem); responseModel.TotalAmount = amount; } responseModel.OrderItems = orderItemsModel; return(responseModel); }
public OrderResponseManager() { redis = new RedisCacheManager(); factory = new ConnectionFactory() { HostName = Common.Constants.InternalHost }; var connection = factory.CreateConnection(); var channel = connection.CreateModel(); channel.ExchangeDeclare(exchange: Common.Constants.RabbitMQExchange, type: "direct"); channel.QueueDeclare(queue: Common.Constants.RabbitMQOrderQueueName, durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind(queue: Common.Constants.RabbitMQOrderQueueName, exchange: Common.Constants.RabbitMQExchange, routingKey: Common.Constants.RabbitMQOrderRoutingKey); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { byte[] body = ea.Body.ToArray(); string orderRequestStr = Encoding.UTF8.GetString(body); OrderRequestModel orderRequest = JsonConvert.DeserializeObject <OrderRequestModel>(orderRequestStr); while (!redis.SetKey(orderRequest.ProductId, "lock", TimeSpan.FromSeconds(3))) { Console.WriteLine("Waiting For Access To => {0}", orderRequest.ProductId); Thread.Sleep(100); } using (ECommerce2Context db = new ECommerce2Context()) { Product p = db.Products.FirstOrDefault(x => x.ProductId == orderRequest.ProductId); if (p != null) { OrderResponseModel orderResponse = new OrderResponseModel() { IsError = true, Quantity = orderRequest.Quantity, ProductId = orderRequest.ProductId, ProductName = p.ProductName }; if ((p.Quantity - orderRequest.Quantity) > 0) { Console.WriteLine("{0} x '{1}' Product Sold For (Customer Id = '{2}')", orderRequest.Quantity, p.ProductName, orderRequest.RequestCustomerId); p.Quantity -= orderRequest.Quantity; db.SaveChanges(); orderResponse.IsError = false; } else { Console.WriteLine("{0} x '{1}' Product Could't Sold (Customer Id = '{2}') - SQ: {3}", orderRequest.Quantity, p.ProductName, orderRequest.RequestCustomerId, p.Quantity); } string orderResponseStr = JsonConvert.SerializeObject(orderResponse); byte[] requestBody = Encoding.UTF8.GetBytes(orderResponseStr); try { channel.BasicPublish(exchange: Common.Constants.RabbitMQExchange, routingKey: Common.Constants.RabbitMQCustomerPrefix + orderRequest.RequestCustomerId, basicProperties: null, body: requestBody); } catch (Exception) { Console.WriteLine("Customer Gone Away => {0}", orderRequest.RequestCustomerId); } } else { Console.WriteLine("Product Cannot Found => {0} ", orderRequest.ProductId); } } redis.RemoveLockKey(orderRequest.ProductId);//RELASE LOCK }; channel.BasicConsume(queue: Common.Constants.RabbitMQOrderQueueName, autoAck: true, consumer: consumer); }
public async Task <IActionResult> Get([FromRoute] int id) { OrderResponseModel result = await _orderService.GetAsync(User.Identity.Name, id); return(Ok(result)); }
public async Task <IActionResult> Post(UpdateOrderStatusRequestModel model) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); var serviceModel = new UpdateOrderStatusServiceModel { OrderId = model.OrderId, OrderStatusId = model.OrderStatusId, Language = CultureInfo.CurrentCulture.Name, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value), Username = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value, IsSeller = this.User.IsInRole("Seller") }; var validator = new UpdateOrderStatusModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var order = await this.ordersService.SaveOrderStatusAsync(serviceModel); if (order != null) { var response = new OrderResponseModel { Id = order.Id, ClientId = order.ClientId, ClientName = order.ClientName, BillingAddressId = order.BillingAddressId, BillingCity = order.BillingCity, BillingCompany = order.BillingCompany, BillingCountryCode = order.BillingCountryCode, BillingFirstName = order.BillingFirstName, BillingLastName = order.BillingLastName, BillingPhone = order.BillingPhone, BillingPhonePrefix = order.BillingPhonePrefix, BillingPostCode = order.BillingPostCode, BillingRegion = order.BillingRegion, BillingStreet = order.BillingStreet, ShippingAddressId = order.ShippingAddressId, ShippingCity = order.ShippingCity, ShippingCompany = order.ShippingCompany, ShippingCountryCode = order.ShippingCountryCode, ShippingFirstName = order.ShippingFirstName, ShippingLastName = order.ShippingLastName, ShippingPhone = order.ShippingPhone, ShippingPhonePrefix = order.ShippingPhonePrefix, ShippingPostCode = order.ShippingPostCode, ShippingRegion = order.ShippingRegion, ShippingStreet = order.ShippingStreet, ExpectedDeliveryDate = order.ExpectedDeliveryDate, MoreInfo = order.MoreInfo, Reason = order.Reason, OrderStateId = order.OrderStateId, OrderStatusId = order.OrderStatusId, OrderStatusName = order.OrderStatusName, OrderItems = order.OrderItems.Select(x => new OrderItemResponseModel { ProductId = x.ProductId, ProductSku = x.ProductSku, ProductName = x.ProductName, PictureUrl = x.PictureUrl, Quantity = x.Quantity, ExternalReference = x.ExternalReference, ExpectedDeliveryFrom = x.ExpectedDeliveryFrom, ExpectedDeliveryTo = x.ExpectedDeliveryTo, MoreInfo = x.MoreInfo, LastModifiedDate = x.LastModifiedDate, CreatedDate = x.CreatedDate }), LastModifiedDate = order.LastModifiedDate, CreatedDate = order.CreatedDate }; return(this.StatusCode((int)HttpStatusCode.OK, response)); } else { return(this.StatusCode((int)HttpStatusCode.NotFound)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }