Exemple #1
0
        public ActionResult <Order> CreateOrder(Order order)
        {
            _repoOrder.CreateOrder(order);
            _repoCust.SaveChanges();

            return(Ok());
        }
        public ActionResult <OrderReadDto> CreateOrder(OrderCreateDto orderCreateDto)
        {
            var orderModel = _mapper.Map <order>(orderCreateDto);

            _order.CreateOrder(orderModel);
            _order.SaveChanges();

            var orderReadDto = _mapper.Map <OrderReadDto>(orderModel);

            return(CreatedAtRoute(nameof(GetOrderById), new { Id = orderReadDto.OrderId }, orderReadDto));
        }
Exemple #3
0
        public async Task <ActionResult <UserManagerResponse> > createOrder([FromBody] OrderCreateDto orderDto)
        {
            if (ModelState.IsValid)
            {
                var    user  = User.FindFirst(ClaimTypes.NameIdentifier);
                Orders order = _mapper.Map <Orders>(orderDto);
                order.OrderClientId = user.Value;

                //first product name & image
                int firstProductId = orderDto.products[0].ProductId;

                var result = await _orderRepo.CreateOrder(order, firstProductId); //either order number will be returned or a -1 on exception

                if (!result.IsSuccessful)
                {
                    return(result);
                }

                int orderId = int.Parse(result.Message);

                var OrderDetails = _mapper.Map <OrderDetails>(orderDto.orderDetails);
                OrderDetails.DatePlaced = orderDto.DatePlaced;

                var orderProducts = _mapper.Map <IEnumerable <OrderProducts> >(orderDto.products);


                result = await _orderRepo.CreateOrder(OrderDetails, orderProducts, orderId);

                if (!result.IsSuccessful)
                {
                    return(result);
                }

                return(result);
            }
            return(new UserManagerResponse
            {
                IsSuccessful = false,
                Message = "The model is Invalid"
            });
        }
        public IActionResult CreateOrder([FromBody] Order order)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            Order createdOrder = _orders.CreateOrder(order);

            return(CreatedAtAction(
                       nameof(GetOrder), new { id = createdOrder.Id }, createdOrder));
        }
        public ActionResult CreateOrder(List <OrderCreateDto> listCreateOrder)
        {
            List <Order> listOrder = new List <Order>();

            foreach (OrderCreateDto orderCreate in listCreateOrder)
            {
                listOrder.Add(_mapper.Map <Order>(orderCreate));
                listOrder.Last().Date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            _repositoryOrder.CreateOrder(listOrder);
            _repositoryOrder.SaveChange();

            return(StatusCode(StatusCodes.Status200OK, new { status = "success", message = "this order has been validated" }));
        }
Exemple #6
0
        public IActionResult CheckOut(Order order)
        {
            var items = _shopingRepo.GetShopingCards();

            _shopingRepo.ShopingCards = items;
            if (_shopingRepo.ShopingCards.Count == 0)
            {
                ModelState.AddModelError("", "Your card is empty, please add some products.");
            }

            if (ModelState.IsValid)
            {
                _orderRepo.CreateOrder(order);
                _shopingRepo.ClearCard();
                return(RedirectToAction("CheckOutComplete"));
            }
            return(View(order));
        }
Exemple #7
0
        public IActionResult Checkout(Order order)
        {
            var items = _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItems = items;

            if (_shoppingCart.ShoppingCartItems.Count == 0)
            {
                ModelState.AddModelError("", "Empty cart, add headphones");
            }

            if (ModelState.IsValid)
            {
                _orderRepo.CreateOrder(order);
                _shoppingCart.ClearCart();
                return(RedirectToAction("CheckoutComplete"));
            }
            return(View(order));
        }
        public IActionResult Checkout(Order order)
        {
            var items = _booking.GetBookingItems();

            _booking.BookingItems = items;

            if (_booking.BookingItems.Count == 0)
            {
                ModelState.AddModelError("", "There are no holidays booked at this time");
            }

            if (ModelState.IsValid)
            {
                _orderRepo.CreateOrder(order);
                _booking.ClearBook();
                return(RedirectToAction("CheckoutComplete"));
            }

            return(View(order));
        }
Exemple #9
0
 public Order AddOrder(Order order)
 {
     if (order.Address == null)
     {
         throw new Exception("Address is required.");
     }
     else if (order.ProductQuantity.Count == 0)
     {
         throw new Exception("Order must have at least one product.");
     }
     else if (order.User == null)
     {
         throw new Exception("Order must have a User.");
     }
     else if (order.Total <= 0)
     {
         throw new Exception("Total value is wrong.");
     }
     else
     {
         return(_orderRepo.CreateOrder(order));
     }
 }
Exemple #10
0
        public async Task <ActionResult> Post(ViewModelOrder order)
        {
            _logger.LogInformation("Post Order", order);

            if (ModelState.IsValid && order.Botfield == null)
            {
                var findClient = await _clientRepo.ClientFindByEmail(order.Email);

                if (findClient == null)
                {
                    findClient = await _clientRepo.CreateClient(new Clients()
                    {
                        Email     = order.Email,
                        Phone     = order.Phone,
                        LastName  = order.ClientLastName,
                        FirstName = order.ClientFirstName
                    });

                    var createKadett = await _kadettRepo.CreateKadett(new Kadett()
                    {
                        LastName      = order.KadettLastName,
                        FirstName     = order.KadettFirstName,
                        KadettInKader = order.KadettInKader
                    });

                    var createOrder = await _orderRepo.CreateOrder(new Orders()
                    {
                        Bemerkung = order.Bemerkung,
                        OrderDate = DateTime.Now,
                        Client    = findClient,
                        Kadett    = createKadett
                    });

                    foreach (var ticket in order.Tickets)
                    {
                        Ticket ticketMatch = await _ticketRepo.GetByType(ticket.Type);

                        if (ticketMatch == null)
                        {
                            return(BadRequest());
                        }

                        var ticketOrder = await _ticketOrderRepo.CreateTicketOrder(new TicketOrder()
                        {
                            Order    = createOrder,
                            Ticket   = ticketMatch,
                            Quantity = ticket.Quantity,
                            Day      = ticket.Day
                        });
                    }
                    var email = await _clientRepo.ClientFindByEmail(order.Email);

                    if (email == null)
                    {
                        await _context.SaveChangesAsync();

                        if (!HostingEnvironment.IsDevelopment())
                        {
                            await _emailSenderService.SendEmailAsync(order.Email);
                        }
                        return(Ok());
                    }
                }
                return(Conflict());
            }
            return(ValidationProblem());
        }
Exemple #11
0
        public ActionResult AddToDatabase(OrderViewModel formResponse)
        {
            // variabel for seats
            int seats = 0;

            // Looking for session in cart
            CartModel cart = (CartModel)Session["Cart"];

            if (cart == null)
            {
                return(RedirectToAction("CartEmpty"));
            }

            // Put data from form into Order class
            Order orderFromForm = formResponse.Order;

            // find existing order
            Order existingOrder = _orderRepo.FindOrder(formResponse.Order.Email);

            // If there is no order, there will be one created with the information
            if (existingOrder == null)
            {
                // Creating Account Order
                _orderRepo.CreateOrder(orderFromForm);
                // Now that an id had been created for order, the id can be passed into orderitem.
                orderFromForm = _orderRepo.FindOrder(formResponse.Order.Email);
                for (int i = 0; i < cart.OrderItems.Count; i++)
                {
                    // Giving OrderItem a Orderid from the form
                    cart.OrderItems[i].OrderID = orderFromForm.ID;

                    // Creating a new Order Item
                    _orderRepo.CreateOrderItem(cart.OrderItems[i]);

                    // Changing the amount of seats
                    seats = cart.OrderItems[i].Event.SeatsAvailable - cart.OrderItems[i].Amount;

                    //Assign value to event
                    cart.OrderItems[i].Event.SeatsAvailable = seats;

                    // Update in the database
                    _orderRepo.UpDateEvent(cart.OrderItems[i].Event);
                }
            }
            // passing the order id in the orderitem and creating database record
            else
            {
                // In this case there already is a AccountOrder
                for (int i = 0; i < cart.OrderItems.Count; i++)
                {
                    // Giving OrderItem a Orderid from the form
                    cart.OrderItems[i].OrderID = existingOrder.ID;

                    // Creating a new Order Item
                    _orderRepo.CreateOrderItem(cart.OrderItems[i]);

                    // cart.OrderItems[i].Event.ID =

                    // Changing the amount of seats
                    seats = cart.OrderItems[i].Event.SeatsAvailable - cart.OrderItems[i].Amount;

                    //Assign value to event
                    cart.OrderItems[i].Event.SeatsAvailable = seats;

                    // Update in the database
                    _orderRepo.UpDateEvent(cart.OrderItems[i].Event);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
 public IActionResult Checkout(Order order)
 {
     orderRepo.CreateOrder(order);
     return(RedirectToAction("OrderComplete"));
 }
        public Order CreateOrder(Order data)
        {
            return(_orderRepo.CreateOrder(data));

            ;
        }
 public async Task <bool> CreateOrder(OrderInfo orderInfo)
 {
     return(await _orderRepo.CreateOrder(orderInfo));
 }