Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task <ResponseModel_PlaceOrder> PlaceOrderAsync(PlaceOrderRequestModel listModel)
        {
            var response = new ResponseModel_PlaceOrder
            {
                Success  = false,
                Messages = new List <string>()
            };

            if (listModel == null || listModel.Items == null || listModel.Items.Count == 0 && string.IsNullOrEmpty(listModel.Cords))
            {
                response.Messages.Add("Data not mapped");
                response.Data = listModel;
            }
            else if (listModel.Cords.Split('_').Length != 2)
            {
                response.Messages.Add("Invalid Cord format. Please specify in Lat_Lang .i.e. '32.202895_74.176716'");
                response.Data = listModel;
            }
            else
            {
                try
                {
                    var orderById = listModel.OrderPlacedById;
                    if (string.IsNullOrEmpty(listModel.OrderPlacedById))
                    {
                        var contextnew  = new ApplicationDbContext();
                        var userStore   = new UserStore <ApplicationUser>(contextnew);
                        var userManager = new UserManager <ApplicationUser>(userStore);
                        var user        = userManager.FindByName(User.Identity.Name);
                        orderById = user.Id;
                    }

                    var signalRUrl = ConfigurationManager.AppSettings["signalRHubUrl"];
                    var item       = OrderService.Place(listModel, orderById);
                    response.Data     = item.EstimatedTime;
                    response.OrderId  = item.OrderIds;
                    response.SerialNo = item.SerailNo;
                    response.Messages.Add("Success");
                    response.Success = true;

                    //get orders by serial no here
                    var _order = OrderService.GetOrderDetailsBySerialNo(item.SerailNo);
                    await SignalRService.NotifyNewOrdersReceivedAsync(_order.Orders, signalRUrl);
                }
                catch (Exception excep)
                {
                    response.Messages.Add("Something bad happened.");
                }
            }
            return(response);
        }