public async Task <ActionResult <OrdersDto> > GetordersById(int id) { var order = await _ordersRepository.GetById(id); ICollection <OrderDetailsDto> odds = new List <OrderDetailsDto>(); foreach (var item in order.OrderDetails) { var product = await _productRepository.GetProductById(item.ProductId); //Console.WriteLine("###############################" + item.ProductId); OrderDetailsDto o = new OrderDetailsDto { Id = item.Id, Product = product, CartQty = item.CartQty, ProductPrice = item.productPrice }; odds.Add(o); } OrdersDto newOrder = new OrdersDto { Id = order.Id, UserType = order.UserType, OrderDetails = odds, AppUser = order.AppUser, ContactDetails = order.ContactDetail, OrderStatus = order.OrderStatus, CreatedDate = order.CreatedDate, LastUpdated = order.LastUpdated }; return(newOrder); }
public async Task <IActionResult> GetCustomerOrderDetails( [FromRoute] Guid orderId) { OrderDetailsDto orderDetails = await _mediator.Send(new GetCustomerOrderDetailsQuery(orderId)); return(Ok(orderDetails)); }
//post order details public int PostOrderDetails(OrderDetailsDto detail) { try { var result = (from r in appDbContext.OrderDetails where (r.UserId == detail.UserId) select r).ToList(); if (result.Count == 0) { var info = new OrderDetails { UserId = detail.UserId, DeliverTo = detail.DeliverTo, ContactNo = detail.ContactNo, DeliveryAddress = detail.DeliveryAddress, Pincode = detail.Pincode, }; appDbContext.OrderDetails.Add(info); appDbContext.SaveChanges(); return(1); } else { return(0); } } catch (Exception ex) { throw; } }
public async Task UpdateAsync(OrderDetailsDto dto) { var entity = await _orderDetailsRepository.GetAsync(dto.Order.Id); entity.ProductId = dto.Product.Id; entity.Quantity = dto.Quantity; await _orderDetailsRepository.UpdateAsync(entity); }
public IHttpActionResult PutOrderDetails(int id, OrderDetailsDto orderDetails) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _orderDetailsService.Update(id, orderDetails); return(StatusCode(HttpStatusCode.NoContent)); }
private static OrderDetailsDto CreateOrderDetailsDto(short quantity = 0) { var dto = new OrderDetailsDto { Id = Id, Quantity = quantity }; return(dto); }
public IHttpActionResult Get(int id) { OrderDetailsDto orderDetails = _orderDetailsService.GetById(id); if (orderDetails == null) { return(NotFound()); } return(Ok(orderDetails)); }
public IHttpActionResult PostOrderDetails(OrderDetailsDto orderDetails) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _orderDetailsService.Add(orderDetails); return(CreatedAtRoute("DefaultApi", new { id = orderDetails.OrderId }, orderDetails)); }
private string CreateBody(OrderDetailsDto lastOrderDetailElement, OrderDto orderDto, UserForEmailDto userForEmailDto) { //var webRoot = _webHostEnvironment.WebRootPath; //get wwwroot folder var pathToFile = _webHostEnvironment.WebRootPath + Path.DirectorySeparatorChar.ToString() + "Templates" + Path.DirectorySeparatorChar.ToString() + "EmailTemplates" + Path.DirectorySeparatorChar.ToString() + "OrderConfirmationMail.html"; string emailBody = string.Empty; using (StreamReader reader = new StreamReader(pathToFile)) { emailBody = reader.ReadToEnd(); } //Replacing parameters emailBody = emailBody.Replace("{FirstName}", userForEmailDto.FirstName); emailBody = emailBody.Replace("{LastName}", userForEmailDto.LastName); emailBody = emailBody.Replace("{UserAddress}", userForEmailDto.UserAddress); emailBody = emailBody.Replace("{UserAddress2}", userForEmailDto.UserAddress2); emailBody = emailBody.Replace("{State}", userForEmailDto.State); emailBody = emailBody.Replace("{Country}", userForEmailDto.Country); emailBody = emailBody.Replace("{Zip}", userForEmailDto.Zip); emailBody = emailBody.Replace("{ReceiverFirstName}", orderDto.ReceiverFirstName); emailBody = emailBody.Replace("{ReceiverLastName}", orderDto.ReceiverLastName); emailBody = emailBody.Replace("{ReceiverAddress}", orderDto.ReceiverAddress); emailBody = emailBody.Replace("{ReceiverAddress2}", orderDto.ReceiverAddress2); emailBody = emailBody.Replace("{ReceiverState}", orderDto.ReceiverState); emailBody = emailBody.Replace("{ReceiverCountry}", orderDto.ReceiverCountry); emailBody = emailBody.Replace("{ReceiverZip}", orderDto.ReceiverZip.ToString()); emailBody = emailBody.Replace("{OrderId}", lastOrderDetailElement.OrderId.ToString()); emailBody = emailBody.Replace("{OrderDate}", lastOrderDetailElement.OrderDate.ToString()); emailBody = emailBody.Replace("{OrderTotal}", orderDto.OrderTotal.ToString()); //Ordered products List <OrderedProductsDto> orderedProductsDto = orderDto.OrderedProductsDto; for (int i = 0; i < orderedProductsDto.Count; i++) { emailBody = emailBody.Replace("{ProductName}", orderedProductsDto[i].ProductName); emailBody = emailBody.Replace("{Qty}", orderedProductsDto[i].Qty.ToString()); emailBody = emailBody.Replace("{Price}", orderedProductsDto[i].Price.ToString()); emailBody = emailBody.Replace("{TotalPriceForProduct}", (orderedProductsDto[i].Qty * orderedProductsDto[i].Price).ToString()); } return(emailBody); }
public static void CopyFromEntity(OrderDetailsDto dto, Order order, string agentAdminMob, bool withDetails) { dto.order_id = order.OrdrID; dto.invoice_number = order.InvoiceNumber; // driver_details : driver_name, driver_image dto.order_date = Common.ToDateFormat(order.OrderDate); // product_details : product_name, quantity, unit_price, sub_total, product_promo, shipping_cost, shipping_promo dto.order_time = order.OrderTime; dto.delivery_date = Common.ToDateFormat(order.DeliveryDate); dto.time_slot_name = order.MDeliverySlot.SlotName; dto.grand_total = order.GrandTotal; dto.order_status = order.MOrderStatu.OrderStatus; dto.agentadmin_mobile = agentAdminMob; OrderDelivery odel = order.OrderDeliveries.Count > 0 ? order.OrderDeliveries.First() : null; if (odel != null) { dto.delivery_status = odel.MDeliveryStatu.DeliveryStatus; if (odel.Driver != null) { DriverDetailsDto drvDto = new DriverDetailsDto(); dto.driver_details = drvDto; CopyFromEntity(drvDto, odel.Driver); //drvDto.driver_name = odel.Driver.DriverName; //drvDto.driver_image = odel.Driver.ProfileImage; } } if (order.OrderDetails.Count > 0) { List <OrderDetail> odetLst = order.OrderDetails.ToList(); dto.product_details = new ProductsDto[odetLst.Count]; for (int i = 0; i < odetLst.Count; i++) { ProductsDto prodDto = new ProductsDto(); CopyFromEntity(prodDto, odetLst[i]); dto.product_details[i] = prodDto; } } dto.has_exchange = (order.OrderPrdocuctExchanges.Count > 0 ? 1 : 0); if (dto.has_exchange == 1) { if (dto.exchange == null) { dto.exchange = new List <ExchangeDto>(); } foreach (var item in order.OrderPrdocuctExchanges) { ExchangeDto exDto = new ExchangeDto(); CopyFromEntity(exDto, item); dto.exchange.Add(exDto); } } }
public void PlaceOrder() { //get the list List <CartVM> cart = Session["cart"] as List <CartVM>; // get username string username = User.Identity.Name; //declare order int orderId = 0; using (Db db = new Db()) { //init OrderDto OrderDto orderDto = new OrderDto(); //get user id var q = db.Users.FirstOrDefault(x => x.Username == username); int userId = q.Id; //add to orderDTO and save //orderDto.OrderId = orderId; orderDto.UserId = userId; orderDto.CreatedAt = DateTime.Now; db.Orders.Add(orderDto); db.SaveChanges(); //get inserted id orderId = orderDto.OrderId; //init orderDetailsDto OrderDetailsDto orderDetails = new OrderDetailsDto(); //add to orderDetailsDto foreach (var item in cart) { orderDetails.OrderId = orderId; orderDetails.UserId = userId; orderDetails.ProductId = item.ProductId; orderDetails.Quantity = item.Quantity; db.OrderDetails.Add(orderDetails); db.SaveChanges(); } } //email admin var client = new SmtpClient("smtp.mailtrap.io", 2525) { Credentials = new NetworkCredential("fad7a9d4597328", "d2265eb88adc2f"), EnableSsl = true }; client.Send("*****@*****.**", "*****@*****.**", "New Order", "you have a new order & order number is:-" + orderId); //reset session Session["cart"] = null; }
public async Task <IActionResult> CreateOrder([FromBody] CreateOrderDto form) { var order = await _orderService.Create(form, await _usersService.GetCurrentUserAsync()); if (order != null) { return(StatusCodeAndDtoWrapper.BuildGeneric(OrderDetailsDto.Build(order))); } else { return(StatusCodeAndDtoWrapper.BuildErrorResponse("Something went wrong")); } }
public async Task <IActionResult> GetOrdersById(long id) { var order = await _orderService.FetchById(id, includeOrderItems : true, includeAddress : true); if (order == null) { return(StatusCodeAndDtoWrapper.BuildGeneric(new ErrorDtoResponse("Not Found"), statusCode: 404)); } //return NotFound(); return(new StatusCodeAndDtoWrapper(OrderDetailsDto.Build(order, false))); }
private async Task CreateDetailsAsync(string gameKey, string orderId) { var gameDto = await _gameService.GetByKeyAsync(gameKey); var detailsDto = new OrderDetailsDto { GameId = gameDto.Id, Price = gameDto.Price, Discount = gameDto.Discount, OrderId = orderId }; await _orderDetailsService.CreateAsync(detailsDto); }
public void Update(int id, OrderDetailsDto orderDetails) { using (var uow = new UnitOfWork()) { OrderDetails orderDetailsDb = new OrderDetails() { BookId = orderDetails.BookId, OrderId = orderDetails.OrderId, Price = orderDetails.Price, Quantity = orderDetails.Quantity }; uow.OrderDetailsRepository.Update(orderDetailsDb); uow.SaveChanges(); } }
public OrderDetailsDto GetById(int id) { using (var uow = new UnitOfWork()) { var getOrderDetails = uow.OrderDetailsRepository.GetById(id); OrderDetailsDto orderDetails = new OrderDetailsDto() { OrderId = getOrderDetails.OrderId, BookId = getOrderDetails.BookId, Price = getOrderDetails.Price, Quantity = getOrderDetails.Quantity }; return(orderDetails); } }
public void ShouldReturnOrderDetails() { var orderDetails = new OrderDetails( productId: 1, price: 10, quantity: 2, discount: 0); _mock.Setup(m => m.OrderDetails.Get(It.IsAny <int>())) .Returns(orderDetails); OrderDetailsDto orderDetailsDto = _service.Get(It.IsAny <int>()); Assert.IsTrue(orderDetailsDto.Equals(orderDetails.ToDto())); }
public void TestInitialize() { orderDetailsDto = new OrderDetailsDto() { OrderId = 1, OrderItemId = 1, ProductId = 1, ProductPrice = "rs.50", Quantity = 1, UserId = 1 }; _mockUnitofWork = new Mock <IUnitofWork>(); _mockOrderRepository = new Mock <IOrderRepository>(); _mockOrderRepository.Setup(m => m.GetOrder(2)).ReturnsAsync(orderDetailsDto); _mockUnitofWork.Setup(m => m.OrderRepository).Returns(_mockOrderRepository.Object); }
public ActionResult ProcessOrder(FormCollection form) { List <CartDto> listCart = (List <CartDto>)Session[strCart]; OrderDto order = new OrderDto() { CustomerName = form["cusName"], CustomerSurname = form["cusSurname"], CustomerPhone = form["cusPhone"], CustomerEmail = form["cusEmail"], CustomerAddress = form["cusAddress"], OrderDate = DateTime.Now, PaymentType = "Cash", Status = "Processing" }; HttpResponseMessage responseOrder = WebApiClient.PostAsJsonAsync("Orders", order).Result; TempData["SuccessMessage"] = "Saved Successfully"; //Thread.Sleep(3000); HttpResponseMessage response = WebApiClient.GetAsync("Orders").Result; var ordersList = response.Content.ReadAsAsync <IEnumerable <BookDto> >().Result; int orederId = 0; foreach (var item in ordersList) { orederId = item.Id; } foreach (CartDto cart in listCart) { OrderDetailsDto orderDetails = new OrderDetailsDto() { OrderId = orederId, BookId = cart.Book.Id, Price = cart.Book.Price, Quantity = cart.Quantity }; HttpResponseMessage responseOrderBooks = GlobalVariables.WebApiClient.PostAsJsonAsync("OrderDetails", orderDetails).Result; TempData["SuccessMessage"] = "Saved Successfully"; } Session.Remove(strCart); return(View("OrderSuccess")); }
public async Task <ActionResult <OrderDetailsDto> > GetOrdersAsync(int userId) { var user = await usersClient.GetUserAsync(userId).ConfigureAwait(false); if (user == null) { return(BadRequest($"User with id:{userId} doesn't exist")); } var orders = await ordersClient.GetOrdersAsync(userId).ConfigureAwait(false); var orderDetails = new OrderDetailsDto { User = user, Orders = orders }; return(Ok(orderDetails)); }
public bool Put(int id, [FromBody] OrderDetailsDto edit) { if (id != null && edit != null) { var r = ordersService.updateDeliveryDetails(id, edit); if (r == "Updated") { return(true); } else { return(false); } } else { return(false); } }
public bool Post([FromBody] OrderDetailsDto add) { if (add != null) { var deliveryDetails = ordersService.PostOrderDetails(add); if (deliveryDetails == 1) { return(true); } else { return(false); } } else { return(false); } }
// GET: Admin/Dashboard/DeleteOrder/id public ActionResult DeleteOrder(int id) { using (Db db = new Db()) { // Get the order OrderDetailsDto order = db.OrderDetails.Find(id); // Remove the order db.OrderDetails.Remove(order); // Save db.SaveChanges(); OrderDto dto = db.Orders.Find(id); db.Orders.Remove(dto); db.SaveChanges(); } // Redirect return(RedirectToAction("Index")); }
//update delivery details public string updateDeliveryDetails(int id, OrderDetailsDto chng) { try { var update = appDbContext.OrderDetails.Where(x => x.Id == id).SingleOrDefault(); update.UserId = chng.UserId; update.DeliverTo = chng.DeliverTo; update.ContactNo = chng.ContactNo; update.DeliveryAddress = chng.DeliveryAddress; update.Pincode = chng.Pincode; appDbContext.SaveChanges(); return("Updated"); } catch (Exception ex) { throw; } }
public async Task CreateAsync(OrderDetailsDto orderDetailsDto) { if (orderDetailsDto == null) { throw new InvalidServiceOperationException("Is null dto"); } var orderDetails = _mapper.Map <OrderDetails>(orderDetailsDto); await ValidateQuantityAsync(orderDetails); var gameDto = await _gameService.GetByIdAsync(orderDetailsDto.GameId); orderDetails.Price = gameDto.Price; orderDetails.Discount = gameDto.Discount; await _orderDetailsDecorator.AddAsync(orderDetails); await _unitOfWork.CommitAsync(); }
public void PlaceOrder() { //Get cart list List <CartVM> cart = Session["cart"] as List <CartVM>; //Get user id string userName = User.Identity.Name; //Init OrdedrDto OrderDto orderDto = new OrderDto(); //Get user id var userId = _uRepo.getUserId(userName); //Add to OrderDTO and save orderDto.UserId = userId; orderDto.CreatedAt = DateTime.Now; _gRepo.Add(orderDto); _gRepo.SaveAll(); //Get inserted id int orderId = orderDto.OrderId; //Init OrderDetailsDTO OrderDetailsDto orderDetailsDto = new OrderDetailsDto(); // Add to OrderDetailsDTO foreach (var item in cart) { orderDetailsDto.OrderId = orderId; orderDetailsDto.UserId = userId; orderDetailsDto.ProductId = item.ProductId; orderDetailsDto.Quantity = item.Quantity; _gRepo.Add(orderDetailsDto); _gRepo.SaveAll(); } var client = new SmtpClient("smtp.mailtrap.io", 2525) { Credentials = new NetworkCredential("02c5e09f50c8c8", "57922e19980353"), EnableSsl = true }; client.Send("*****@*****.**", "*****@*****.**", "New Order", "You have a new order. Order number " + orderId); Session["cart"] = null; }
public async Task <IEnumerable <OrderDetailsDto> > SendEmailData(OrderDto orderDto) { UserForEmailDto userForEmailDto = await _unitOfWork.PaymentRepository.UserDetailsForEmail(orderDto); IEnumerable <OrderDetailsDto> orderDetailsDto = _unitOfWork.PaymentRepository.OrderHistoryData(orderDto); // Get last element of orderDetailsDto to get orderId and OrderDate OrderDetailsDto lastOrderDetailElement = orderDetailsDto.First(); string emailBody = CreateBody(lastOrderDetailElement, orderDto, userForEmailDto); //var message = new Message(new string[] { "*****@*****.**" }, "Test Email async with attachment", // "This is the content from our Email with attachment"); var message = new Message(new string[] { userForEmailDto.UserEmail }, "Autumn Store_Proof of Purchase", emailBody); await _emailSender.SendEmailAsync(message); // return order history return(orderDetailsDto); }
public async Task PlaceOrder_Test() { string customerEmail = "*****@*****.**"; CustomerDto customer = await CommandsExecutor.Execute(new RegisterCustomerCommand(customerEmail, "Sample Customer")); List <ProductDto> products = new List <ProductDto>(); Guid productId = Guid.Parse("9DB6E474-AE74-4CF5-A0DC-BA23A42E2566"); products.Add(new ProductDto(productId, 2)); Guid orderId = await CommandsExecutor.Execute(new PlaceCustomerOrderCommand(customer.Id, products, "EUR")); OrderDetailsDto orderDetails = await QueriesExecutor.Execute(new GetCustomerOrderDetailsQuery(orderId)); Assert.That(orderDetails, Is.Not.Null); Assert.That(orderDetails.Value, Is.EqualTo(70)); Assert.That(orderDetails.Products.Count, Is.EqualTo(1)); Assert.That(orderDetails.Products[0].Quantity, Is.EqualTo(2)); Assert.That(orderDetails.Products[0].Id, Is.EqualTo(productId)); SqlConnection connection = new SqlConnection(ConnectionString); List <OutboxMessageDto> messagesList = await OutboxMessagesHelper.GetOutboxMessages(connection); Assert.That(messagesList.Count, Is.EqualTo(3)); CustomerRegisteredNotification customerRegisteredNotification = OutboxMessagesHelper.Deserialize <CustomerRegisteredNotification>(messagesList[0]); Assert.That(customerRegisteredNotification.CustomerId, Is.EqualTo(new CustomerId(customer.Id))); OrderPlacedNotification orderPlaced = OutboxMessagesHelper.Deserialize <OrderPlacedNotification>(messagesList[1]); Assert.That(orderPlaced.OrderId, Is.EqualTo(new OrderId(orderId))); PaymentCreatedNotification paymentCreated = OutboxMessagesHelper.Deserialize <PaymentCreatedNotification>(messagesList[2]); Assert.That(paymentCreated, Is.Not.Null); }
/// <summary> /// /// </summary> /// <param name="orderId"></param> /// <returns></returns> /// <exception cref="AppException"></exception> public async Task <OrderDetailsDto> GetOrderInfoAsync(int orderId) { var orderDetails = new OrderDetailsDto { OrderId = orderId }; var supplierType = await _supplierInfoService.GetSupplierTypeAsync(orderId); switch (supplierType) { case SupplierInfoService.SupplierType.Restaurant: orderDetails.OrderItems = GetRestaurantMenusItemsList(orderId); var restaurantQuery = _dbContext.RestaurantMenuItem_Order .FirstOrDefault(x => x.OrderId == orderId); orderDetails.SupplierId = restaurantQuery?.RestaurantMenuItem.RestaurantMenu.RestaurantId; break; case SupplierInfoService.SupplierType.Store: orderDetails.OrderItems = GetStoreProductsList(orderId); var storeQuery = _dbContext.StoreProduct_Order .FirstOrDefault(x => x.OrderId == orderId); orderDetails.SupplierId = storeQuery?.StoreProduct.StoreId; break; case SupplierInfoService.SupplierType.Undefined: default: throw new AppException(AppMessage.UndefinedSupplier); } orderDetails.SubTotal = orderDetails.OrderItems.Sum(x => x.SubTotal); orderDetails.DeliveryCost = _dbContext.Orders.FirstOrDefault(x => x.Id == orderId)?.DeliveryCost ?? 0; orderDetails.Total = orderDetails.SubTotal + orderDetails.DeliveryCost; return(orderDetails); }
public async Task UpdateAsync(OrderDetailsDto orderDetailsDto) { if (orderDetailsDto == null) { throw new InvalidServiceOperationException("Is null dto"); } var exists = await _orderDetailsDecorator.AnyAsync(od => od.Id == orderDetailsDto.Id); if (!exists) { throw new EntityNotFoundException <OrderDetails>(orderDetailsDto.Id); } var details = _mapper.Map <OrderDetails>(orderDetailsDto); if (details.Quantity == 0) { await _orderDetailsDecorator.DeleteAsync(details.Id); await _unitOfWork.CommitAsync(); return; } await ValidateQuantityAsync(details); var game = await _gameService.GetByIdAsync(orderDetailsDto.GameId); details.Price = game.Price; details.Discount = game.Discount; await _orderDetailsDecorator.UpdateAsync(details); await _unitOfWork.CommitAsync(); }