public IActionResult Create([FromBody] OrderReportReplaysCreate model)
 {
     try
     {
         var result = _orderReportReplaysService.Create(model);
         return(Ok(result));
     }
     catch (System.Exception e)
     {
         return(BadRequest(e));
     }
 }
示例#2
0
        public IActionResult Create(OrderReportReplaysCreate model)
        {
            long        userId   = _principalService.GetUserId();
            long        clientId = _db.Clients.FirstOrDefault(x => x.UserId == userId).Id;
            OrderReport report   = _db.OrderReports.Where(x => x.Id == model.OrderReportId)
                                   .Include(x => x.CreatedBy)
                                   .ThenInclude(y => y.User)
                                   .Include(x => x.Order)
                                   .ThenInclude(x => x.Record)
                                   .FirstOrDefault();
            Driver driver = _db.Drivers.FirstOrDefault(x => x.Id == report.Order.Record.DriverId);

            OrderReportReplaye orderReportReplay = new OrderReportReplaye
            {
                IsActive        = true,
                CreatedById     = clientId,
                CreatedAt       = DateTime.Now,
                ClientComment   = model.ClientComments,
                DriverLatitude  = (double)report.CreatedBy.User.Latitude,
                DriverLongitude = (double)report.CreatedBy.User.Longitude,
                OrderReportId   = model.OrderReportId
            };

            _db.OrderReportReplayes.Add(orderReportReplay);
            _db.SaveChanges();
            PushNotificationInput pushNotificationInput = new PushNotificationInput
            {
                UserId = driver.UserId,
                title  = "رد على البلاغ ",
                body   = "تم الرد على البلاغ",
                data   = new
                {
                    orderId = report.OrderId,
                }
            };

            _pushNotificationService.PushNotification(pushNotificationInput);
            DataBase.Entities.Notification notification = new DataBase.Entities.Notification
            {
                Title            = "رد على بلاغ",
                Body             = "تم تقديم رد على بلاغ على طلب رقم " + report.OrderId + " رقم الهاتف : " + report.Order.DeliveryPhoneNumber + "نص الرد : " + model.ClientComments,
                Target           = NotificationTarget.Tracker,
                NotificationGuid = Guid.NewGuid()
            };
            _db.Notifications.Add(notification);
            _db.SaveChanges();
            return(new OkObjectResult(true));
        }