public static TrackingNotification Create(IRepositoryLocator locator, TrackingNotificationDto dto, DispatchNote dispatchNote) { var instance = Mapper.Map <TrackingNotification>(dto); instance.DispatchNote = dispatchNote; return(locator.Save(instance)); }
private void SendNotification(TrackingResponse response) { using (var client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/json"; var notificationDto = new TrackingNotificationDto { Distance = response.Distance, DistanceMetric = response.DistanceMetric, Duration = response.Duration, DurationMetric = response.DurationMetric, Latitude = response.Latitude, Longitude = response.Longitude, TruckRegistration = response.TruckRegistration, Id = Guid.NewGuid() }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(notificationDto); var result = client.UploadString(GetTrackingNotificationUri(), json); var dto = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackingResponseDto>(result); response.NotificationWasCreated = dto.Accepted; response.RequestGuid = dto.NotificationId; response.DispatchNoteId = dto.DispatchNoteId; response.Error = dto.Error; var r = dto; } }
private TrackingResponseDto CreateTrackingNotificationImpl(IRepositoryLocator locator, TrackingNotificationDto dto) { var response = new TrackingResponseDto { Accepted = false, NotificationId = dto.Id, DispatchNoteId = 0, Error = string.Empty }; // see if we can fetch dispatch note var dispatchNote = locator.FindAll<DispatchNote>() .FirstOrDefault(d => d.TruckReg.Equals(dto.TruckRegistration, StringComparison.InvariantCultureIgnoreCase)); if (dispatchNote == null) { response.Error = "DispatchNote was not found with Truck Registration: " + dto.TruckRegistration; return response; } response.DispatchNoteId = dispatchNote.Id; // dispatch found and it is valid response = dispatchNote.CreateTrackingNotification(locator, dto, response); if (response.Accepted) { var dispatchEvent = Mapper.Map<DispatchEventBase>(dispatchNote); CreateDispatchEvent(dispatchEvent); } return response; }
public TrackingResponseDto CreateTrackingNotification(TrackingNotificationDto dto) { var response = TrackingAdapter.CreateTrackingNotification(dto); if (response.DispatchNoteId > 0) { var hubContext = GlobalHost.ConnectionManager.GetHubContext<LiteDispatchHub>(); hubContext.Clients.All.updateDispatch(response.DispatchNoteId); } return response; }
public TrackingResponseDto CreateTrackingNotification(TrackingNotificationDto dto) { var response = TrackingAdapter.CreateTrackingNotification(dto); if (response.DispatchNoteId > 0) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <LiteDispatchHub>(); hubContext.Clients.All.updateDispatch(response.DispatchNoteId); } return(response); }
public static TrackingNotification Create(IRepositoryLocator locator, TrackingNotificationDto dto, DispatchNote dispatchNote) { var instance = Mapper.Map<TrackingNotification>(dto); instance.DispatchNote = dispatchNote; return locator.Save(instance); }
public TrackingResponseDto CreateTrackingNotification(TrackingNotificationDto dto) { return ExecuteCommand(locator => CreateTrackingNotificationImpl(locator, dto)); }
public TrackingResponseDto CreateTrackingNotification(IRepositoryLocator locator, TrackingNotificationDto dto, TrackingResponseDto response) { if (!(DispatchNoteStatus == New | DispatchNoteStatus == InTransit)) { response.Error = "DispatchNote was found but its status was not new or in-transit, it was: " + DispatchNoteStatus; return(response); } if (DispatchNoteStatus == New) { DispatchNoteStatus = InTransit; } LastUpdate = DateTime.Now; var trackingNotification = TrackingNotification.Create(locator, dto, this); LastTrackingNotification = trackingNotification; response.Accepted = true; return(response); }
private TrackingResponseDto CreateTrackingNotificationImpl(IRepositoryLocator locator, TrackingNotificationDto dto) { var response = new TrackingResponseDto { Accepted = false, NotificationId = dto.Id, DispatchNoteId = 0, Error = string.Empty }; // see if we can fetch dispatch note var dispatchNote = locator.FindAll <DispatchNote>() .FirstOrDefault(d => d.TruckReg.Equals(dto.TruckRegistration, StringComparison.InvariantCultureIgnoreCase)); if (dispatchNote == null) { response.Error = "DispatchNote was not found with Truck Registration: " + dto.TruckRegistration; return(response); } response.DispatchNoteId = dispatchNote.Id; // dispatch found and it is valid response = dispatchNote.CreateTrackingNotification(locator, dto, response); if (response.Accepted) { var dispatchEvent = Mapper.Map <DispatchEventBase>(dispatchNote); CreateDispatchEvent(dispatchEvent); } return(response); }
public TrackingResponseDto CreateTrackingNotification(TrackingNotificationDto dto) { return(ExecuteCommand(locator => CreateTrackingNotificationImpl(locator, dto))); }