public IActionResult Create([FromBody] OrderReportCreate model) { try { OrderReport result = _orderReportService.Create(model); return(Ok(true)); } catch (System.Exception e) { return(BadRequest(e)); } }
public OrderReport Create(OrderReportCreate model) { long userId = _principalService.GetUserId(); //ApplicationUser user = _userManager.Users.Where(x => x.Id == userId).FirstOrDefault(); long driverId = _db.Drivers.FirstOrDefault(x => x.UserId == userId).Id; Order order = _db.Orders.Where(x => x.Id == model.OrderId) .Include(x => x.Client).ThenInclude(x => x.User).FirstOrDefault(); //Order number not order guid OrderReport orderReport = new OrderReport { IsActive = true, CreatedById = driverId, CreatedAt = DateTime.Now, DriverComments = model.DriverComments, Latitude = model.Latitude, Longitude = model.Longitude, OrderId = model.OrderId, OrderReportGuid = Guid.NewGuid() }; _db.OrderReports.Add(orderReport); _db.SaveChanges(); if (order != null) { PushNotificationInput pushNotificationInput = new PushNotificationInput { UserId = order.Client.User.Id, title = "بلاغ جديد", body = "تم تقديم بلاغ على طلبك", data = new { orderId = orderReport.OrderId, } }; _pushNotificationService.PushNotification(pushNotificationInput); DataBase.Entities.Notification notification = new DataBase.Entities.Notification { Title = "بلاغ جديد", Body = "تم تقديم بلاغ على طلب رقم " + order.Id + " رقم الهاتف : " + order.DeliveryPhoneNumber + "نص البلاغ : " + orderReport.DriverComments, Target = NotificationTarget.Tracker, NotificationGuid = Guid.NewGuid() }; _db.Notifications.Add(notification); _db.SaveChanges(); } return(orderReport); }