コード例 #1
0
        public ResponseModel ApplyForOrder(ApplyByRiderRequestmodel model)
        {
            var response = new ResponseModel
            {
                Success  = false,
                Messages = new List <string>()
            };

            if (model == null || string.IsNullOrEmpty(model.OrderId) || string.IsNullOrEmpty(model.UserId))
            {
                response.Messages.Add("Data not mapped");
                response.Data = model;
            }
            else
            {
                try
                {
                    var res = OrderService.ApplyToOrder_ByRider(model);
                    if (res.isSuccesss)
                    {
                        response.Success = true;
                        response.Messages.Add(res.Message);
                    }
                    else
                    {
                        response.Messages.Add(res.Message);
                    }
                }
                catch (Exception excep)
                {
                    response.Messages.Add("Something bad happened.");
                }
            }
            return(response);
        }
コード例 #2
0
ファイル: OrderService.cs プロジェクト: BaqerNaqvi/DVS-dmn
        public static ApplyRiderResponse ApplyToOrder_ByRider(ApplyByRiderRequestmodel model)
        {
            string newStatus = "";

            using (var dbContext = new DeliversEntities())
            {
                var order = dbContext.Orders.FirstOrDefault(o => o.Id.ToString() == model.OrderId);
                if (order != null)
                {
                    //  var combinedOrders = dbContext.Orders.Where(o => o.SerialNo == order.SerialNo).ToList();
                    //  var ifSomeoneAppliedAlready = combinedOrders.Any(o => o.Status != OrderHistoryEnu.ConfirmedByRestaurant.Value);
                    var ifSomeoneAppliedAlready = order.Status != OrderHistoryEnu.ConfirmedByRestaurant.Value;
                    if (ifSomeoneAppliedAlready)
                    {
                        return(new ApplyRiderResponse
                        {
                            isSuccesss = false,
                            Message = "Order has been assigned to some other rider."
                        });
                    }

                    var notAvaialbeORders = 0;

                    var combinedOrders = new List <Order> {
                        order
                    };                                               // this one

                    foreach (var dbO in combinedOrders)
                    {
                        newStatus = OrderHistoryEnu.ConfirmedByRider.Value;
                        if (dbO.Status != OrderHistoryEnu.ConfirmedByRestaurant.Value)
                        {
                            notAvaialbeORders++;
                            continue;
                        }

                        dbO.Status    = newStatus;
                        dbO.PickedBy  = model.UserId;
                        dbO.UpdatedAt = CommonService.GetSystemTime();

                        var currentHis = dbContext.OrderHistories.FirstOrDefault(d => d.OrderId.ToString() == dbO.Id.ToString() && d.IsCurrent);
                        if (currentHis != null)
                        {
                            currentHis.IsCurrent = false;
                        }

                        dbContext.OrderHistories.Add(new OrderHistory
                        {
                            OrderId   = dbO.Id,
                            DateTime  = CommonService.GetSystemTime(),
                            Status    = newStatus,
                            IsCurrent = true
                        });
                    }
                    if (notAvaialbeORders == 0)
                    {
                        dbContext.SaveChanges();
                        notAvaialbeORders = 0;
                        // generate notifications
                        NotificationService.ProcessNotificationRequest(newStatus, order.Id);
                        return(new ApplyRiderResponse
                        {
                            isSuccesss = true,
                            Message = "Order has been assigned to you."
                        });
                    }
                    else
                    {
                        return(new ApplyRiderResponse
                        {
                            isSuccesss = false,
                            Message = "Order/part of order has been assigned to some other rider."
                        });
                    }
                }
                return(new ApplyRiderResponse
                {
                    isSuccesss = false,
                    Message = "Order does not exist."
                });
            }
        }