public async Task <IActionResult> AssignRecordToDriver(RecordAssignInput input) { Record record = await _db.Records.FirstOrDefaultAsync(x => x.RecordGuid == input.RecordId); record.DriverId = input.DriverId; long userId = _db.Drivers.FirstOrDefault(y => y.Id == input.DriverId).UserId; _db.Entry(record).State = EntityState.Modified; var result = await _db.SaveChangesAsync(); if (result == 1) { PushNotificationInput pushNotificationInput = new PushNotificationInput { UserId = userId, title = "كشف جديد", body = "تم تعيين كشف جديد لك", }; await _pushNotificationService.PushNotification(pushNotificationInput); return(new OkObjectResult(1)); } throw new Exception("حصل خطأ"); }
public async Task <IActionResult> SendPushNotification([FromBody] PushNotificationInput input) { try { var result = await _pushNotificationService.PushNotification(input); return(Ok(result)); } catch (Exception) { return(BadRequest("حصل خطأ")); } }
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)); }
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); }
public HttpResponseMessage PushNotificationDetails(PushNotification ViewModel) { ViewModel.CreatedDate = DateTime.Now.ToUniversalTime(); PushNotificationResponse response = new PushNotificationResponse(); try { response = pushNotificationService.PushNotification(new PushNotificationRequest() { PushNotification = ViewModel }); } catch (Exception ex) { response.Message = ex.Message; } return(Request.BuildResponse(response)); }
public Order Update(OrderUpdate model) { Order order = _db.Orders .Include(c => c.Record) .Include(c => c.Client) .Include(a => a.Area) .ThenInclude(a => a.AreaGroup) .Where(x => x.Id == model.Id).FirstOrDefault(); long userId = _principalService.GetUserId(); order.Address = model.Address; order.AreaId = model.AreaId; order.ClientId = model.ClientId; order.ClientStatus = model.ClientStatus; order.DeliveryPhoneNumber = model.DeliveryNumber; order.OrderItemTypeDescription = model.OrderItemDescription; order.OrderStatusId = model.OrderStatusId; order.OrderTotalPrice = model.OrderTotalPrice; order.PolicyNumber = model.PolicyNumber; order.OrderDate = model.OrderDate; order.AddedPrice = model.AddedPrice; CalculateRevenueForOrder(order); Record record = _db.Records.FirstOrDefault(x => x.AreaGroupId == order.Area.AreaGroupId && x.RecordDate == model.OrderDate); if (record != null) { order.RecordId = record.Id; } else { Record newRecord = new Record { AreaGroupId = order.Area.AreaGroupId, CreatedAt = DateTime.Now, CreatedById = userId, RecordDate = order.OrderDate, RecordGuid = Guid.NewGuid(), IsActive = true }; _db.Records.Add(newRecord); _db.SaveChanges(); order.RecordId = newRecord.Id; } _db.Entry(order).State = EntityState.Modified; _db.SaveChanges(); if (order.OrderStatusId == (int)OrderStatusEnum.Completed) { PushNotificationInput pushNotificationInput = new PushNotificationInput(); pushNotificationInput.UserId = order.Client.UserId; pushNotificationInput.title = "تم توصيل طلبك "; pushNotificationInput.body = "تم توصيل طلبك بنجاح"; pushNotificationInput.data = new { orderId = order.Id }; _pushNotificationService.PushNotification(pushNotificationInput); } return(order); }