/// <summary>
        /// Place order
        /// </summary>
        /// <param name="orderEntity">Order details</param>
        /// <returns>order id</returns>
        public int PlaceOrder(OrderEntity orderEntity)
        {
            DataLayer.Context.TblFoodOrder tblFoodOrder = _mapper.Map <DataLayer.Context.TblFoodOrder>(orderEntity);

            IList <DataLayer.Context.TblFoodOrderMapping> tblFoodOrderMappings = new List <DataLayer.Context.TblFoodOrderMapping>();

            try
            {
                int tblFoodOrderId = _placeOrderDbAccess.PlaceOrder(tblFoodOrder);
                foreach (OrderMenus orderMenu in orderEntity.OrderMenuDetails)
                {
                    tblFoodOrderMappings.Add(new DataLayer.Context.TblFoodOrderMapping()
                    {
                        TblFoodOrderId         = tblFoodOrderId,
                        TblMenuId              = orderMenu.MenuId,
                        Price                  = orderMenu.Price,
                        UserCreated            = 0,
                        RecordTimeStampCreated = DateTime.Now,
                        RecordTimeStamp        = DateTime.Now
                    });
                }

                _placeOrderDbAccess.FoodOrderMapping(tblFoodOrderMappings);
                return(tblFoodOrderId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// Place order
        /// </summary>
        /// <param name="orderEntity">Order details</param>
        /// <returns>order id</returns>
        public int PlaceOrder(OrderEntity orderEntity)
        {
            try
            {
                DataLayer.Context.TblFoodOrder tblFoodOrder = _mapper.Map <DataLayer.Context.TblFoodOrder>(orderEntity);
                tblFoodOrder.UserCreated = orderEntity.CustomerId;
                //calculate total price
                tblFoodOrder.TotalPrice = TotalPrice(orderEntity);
                var OrderID = _placeOrderDbAccess.PlaceOrder(tblFoodOrder);

                List <DataLayer.Context.TblFoodOrderMapping> tblFoodOrderMappings = new List <DataLayer.Context.TblFoodOrderMapping>();

                foreach (OrderMenus orderMenu in orderEntity.OrderMenuDetails)
                {
                    tblFoodOrderMappings.Add(new DataLayer.Context.TblFoodOrderMapping()
                    {
                        TblFoodOrderId         = OrderID,
                        TblMenuId              = orderMenu.MenuId,
                        Price                  = orderMenu.Price,
                        UserCreated            = orderEntity.CustomerId,
                        RecordTimeStampCreated = DateTime.Now
                    });
                }

                return(_placeOrderDbAccess.PlaceOrderMappingTable(tblFoodOrderMappings));
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
コード例 #3
0
        /// <summary>
        /// Place order
        /// </summary>
        /// <param name="orderEntity">Order details</param>
        /// <returns>order id</returns>
        public int PlaceOrder(OrderEntity orderEntity)
        {
            DataLayer.Context.TblFoodOrder tblFoodOrder = _mapper.Map <DataLayer.Context.TblFoodOrder>(orderEntity);

            IList <DataLayer.Context.TblFoodOrderMapping> tblFoodOrderMappings = new List <DataLayer.Context.TblFoodOrderMapping>();

            foreach (OrderMenus orderMenu in orderEntity.OrderMenuDetails)
            {
                tblFoodOrderMappings.Add(new DataLayer.Context.TblFoodOrderMapping()
                {
                    TblFoodOrderId         = 0,
                    TblMenuId              = orderMenu.MenuId,
                    Price                  = orderMenu.Price,
                    UserCreated            = 0,
                    RecordTimeStampCreated = DateTime.Now
                });
            }

            return(_placeOrderDbAccess.PlaceOrder(tblFoodOrder));
        }
コード例 #4
0
        /// <summary>
        /// Place order
        /// </summary>
        /// <param name="orderEntity">Order details</param>
        /// <returns>order id</returns>
        public async Task <int> PlaceOrder(OrderEntity orderEntity)
        {
            try
            {
                DataLayer.Context.TblFoodOrder tblFoodOrder = _mapper.Map <DataLayer.Context.TblFoodOrder>(orderEntity);

                IList <DataLayer.Context.TblFoodOrderMapping> tblFoodOrderMappings = new List <DataLayer.Context.TblFoodOrderMapping>();
                List <CartItemsSenderDetails> orderPlacedItems = new List <CartItemsSenderDetails>();

                foreach (OrderMenus orderMenu in orderEntity.OrderMenuDetails)
                {
                    //Mapping to DbContext model
                    tblFoodOrderMappings.Add(new DataLayer.Context.TblFoodOrderMapping()
                    {
                        TblFoodOrderId         = 0,
                        TblMenuId              = orderMenu.MenuId,
                        Price                  = orderMenu.Price,
                        Active                 = true,
                        UserCreated            = 0,
                        RecordTimeStampCreated = DateTime.Now
                    });
                    //Mapping to business model to use for pre-validation
                    orderPlacedItems.Add(new CartItemsSenderDetails()
                    {
                        RestaurantId = orderEntity.RestaurantId,
                        MenuId       = orderMenu.MenuId,
                        Quantity     = orderMenu.Quantity
                    });
                }

                //Validation for Restaurant Id & Menu Id && item's quantity available or not
                foreach (var item in orderPlacedItems)
                {
                    CartItems cartItem;
                    string    serializedPlacedOrderItems = JsonConvert.SerializeObject(item);
                    using (HttpClient httpClient = new HttpClient())
                    {
                        StringContent       stringContent       = new StringContent(serializedPlacedOrderItems, Encoding.UTF8, "application/json");
                        HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"http://localhost:10601/api/InsertDetailsCheck/", stringContent);

                        if (httpResponseMessage.IsSuccessStatusCode)
                        {
                            string json = await httpResponseMessage.Content.ReadAsStringAsync();

                            cartItem = JsonConvert.DeserializeObject <CartItems>(json);
                        }
                        else
                        {
                            throw new Exception($"No menu present for Restaurant {orderEntity.RestaurantId} and Menu {item.MenuId}");
                        }
                    }

                    if (!cartItem.IsItemAvailable)
                    {
                        throw new Exception($"Cannot add {item.Quantity} for Menu {item.MenuId}. Atmost {cartItem.Quantity} can be added.");
                    }
                }

                //Saving data for Food Order master table
                int tblFoodOrderId = _placeOrderDbAccess.PlaceOrder(tblFoodOrder);

                if (tblFoodOrderId < 1)
                {
                    throw new Exception("Error in placing an order");
                }

                foreach (var tblFoodOrderMapping in tblFoodOrderMappings)
                {
                    tblFoodOrderMapping.TblFoodOrderId = tblFoodOrderId;
                }

                //Saving Food order item details
                bool result = _placeOrderDbAccess.PlaceOrderMapping(tblFoodOrderMappings);

                if (!result)
                {
                    throw new Exception("Error in placing order for food items");
                }

                //Using service bus to update database in Search service's table
                foreach (var item in orderPlacedItems)
                {
                    string json = JsonConvert.SerializeObject(item);
                    await _messenger.SendMessageAsync(json);
                }

                //Checking & dis-activating the cartMaster Id, if there's any
                if (orderEntity.CartMasterId > 0)
                {
                    _cartRepository.UpdateCartMaster(1);
                }

                return(tblFoodOrderId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }