public async Task UpdateCurrentUserInfo(UserInfo userInfo) { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { var crypto = PinnacleApp.Get <ICryptographyService>(); userInfo.DevicePIN = crypto.Encrypt(_pinCryptographicKey, userInfo.DevicePIN); await _client.InvokeApiAsync( "UserInfo/Put", new StringContent( JsonConvert.SerializeObject(userInfo), Encoding.UTF8, "application/json" ), HttpMethod.Put, null, null ); } else { throw new System.Exception("No Internet connectivity - avoid this operation"); } }
public UserModel(Account model) { _model = model; mobileServiceUser = new MobileServiceUser(model.Username) { MobileServiceAuthenticationToken = Token }; _authService = PinnacleApp.Get <IAuthService>(); }
public async Task IssueDeliveryNotification( ISalesOrderWorkItemRepository salesOrderWorkItemRepository, ISalesOrderRepository salesOrderRepository, string salesOrderNumber, bool sendToCustomer, bool sendToSalesRep ) { var salesOrder = await salesOrderRepository.TryGetSalesOrder(salesOrderNumber).ConfigureAwait(false); if ( salesOrder == null || (string.IsNullOrWhiteSpace(salesOrder.SalesRepMobileNumber) && (string.IsNullOrWhiteSpace(salesOrder.CustomerMobileNumber))) ) { return; } var workItems = await salesOrderWorkItemRepository.TryGetSalesOrderWorkItems(salesOrderNumber).ConfigureAwait(false); // No work items (weird), do nothing. if (workItems.Count == 0) { return; } var notesWorkItemTable = await PinnacleApp.Get <ICloudService>().GetTableAsync <NoteWorkItem>(); var noteItems = (await notesWorkItemTable.ReadItemsAsync( 0, int.MaxValue, item => item.NoteParentFk == salesOrderNumber ).ConfigureAwait(false)).ToList(); var salesOrderDelivery = BuildDeliveryRecord(salesOrder, workItems, noteItems, sendToCustomer, sendToSalesRep); var deliveryString = JsonConvert.SerializeObject(salesOrderDelivery); if (_networkService.IsConnected) { //await SendMessage(deliveryString).ConfigureAwait(false); await ProcessUnsentDeliveryNotification().ConfigureAwait(false); } else { await _salesOrderDeliveryRepository.CreateAsync(new SalesOrderDeliveryString { Body = deliveryString }).ConfigureAwait(false); } }
/// <inheritdoc /> public async Task <SalesOrderWorkItem> TryUpdateSalesOrderWorkItem( SalesOrderWorkItem salesOrderWorkItem ) { try { var table = await GetCloudTable().ConfigureAwait(false); // Add the user here var userName = PinnacleApp.Get <IAuthService>().CurrentUser.Name; return(await table.UpdateItemAsync(salesOrderWorkItem).ConfigureAwait(false)); } catch (Exception ex) { _logService.WriteErrorLogEntry($"Failed to update SalesOrderWorkItem ({salesOrderWorkItem?.Id}): {ex}"); ex.Report(); return(null); } }
/// <summary> /// Set the provided SalesOrderWorkItem insance to delivered. This is done by updating the /// item delivered latitude and longitude properties as well as its status. /// </summary> /// <param name="salesOrderWorkItemRepository">An ISalesOrderWorkItemRepository instnace.</param> /// <param name="salesOrderWorkItem">The item to set as delivered.</param> /// <param name="position">The location of the device at the time of delivery.</param> /// <returns>An asynchronous Task.</returns> private static async Task SetSalesOrderWorkItemToDelivered( ISalesOrderWorkItemRepository salesOrderWorkItemRepository, SalesOrderWorkItem salesOrderWorkItem, Location position, string deliveredByUser ) { salesOrderWorkItem.DeliveredLatitude = position?.Latitude ?? 0; salesOrderWorkItem.DeliveredLongitude = position?.Longitude ?? 0; salesOrderWorkItem.DeliveredBy = deliveredByUser; salesOrderWorkItem.DeliveredByName = PinnacleApp.Get <IAuthService>().CurrentUser.Name; salesOrderWorkItem.DeliveredWhen = DateTime.UtcNow; if (salesOrderWorkItem.DeliveredQuantity == 0) { salesOrderWorkItem.DeliveredQuantity = salesOrderWorkItem.PickedQuantity; } salesOrderWorkItem.Status = SalesOrderWorkItemStatus.Delivered; await salesOrderWorkItemRepository .TryUpdateSalesOrderWorkItem(salesOrderWorkItem).ConfigureAwait(false); }
private async Task <SalesOrderWorkItem> TryUpdateSalesOrderWorkItem( SalesOrderWorkflow salesOrderWorkflow, string salesOrderWorkItemId, string lotNumber, decimal updatedItemQuantity, decimal quantityTaken ) { var workItem = await TryGetSalesOrderWorkItem(salesOrderWorkItemId).ConfigureAwait(false); // No work item, nothing to update. if (workItem == null) { return(null); } workItem.LotNumber = lotNumber; workItem.DeliveredQuantity = workItem.IsLotControlled ? quantityTaken : updatedItemQuantity; // reset the posted to GP flag because we are updating the workitem again. workItem.PostedToGp = false; // set username if (salesOrderWorkflow == SalesOrderWorkflow.Pick) { workItem.PickedByName = PinnacleApp.Get <IAuthService>().CurrentUser.Name; } else { workItem.DeliveredByName = PinnacleApp.Get <IAuthService>().CurrentUser.Name; } return(await TryUpdateSalesOrderWorkItem(workItem).ConfigureAwait(false)); }
private AccountStore GetAccountStore() { return(PinnacleApp.Get <IPlatform>().GetAccountStore()); }
/// <inheritdoc /> public async Task <SalesOrderWorkItem> TryCreateSalesOrderWorkItem( ISalesOrderRepository salesOrderRepository, ISalesOrderItemRepository salesOrderItemRepository, ILotRepository lotRepository, string salesOrderNumber, string salesOrderItemNumber, int seq, string salesOrderItemLotNumber, string updatedLotNumber, decimal itemQuantity, decimal updatedItemQuantity, decimal quantityTaken ) { // Read all dependencies for creating a new work item. var salesOrder = await salesOrderRepository.TryGetSalesOrder(salesOrderNumber).ConfigureAwait(false); var adjustedSalesOrderItem = await salesOrderItemRepository .TryGetAdjustedSalesOrderItem( this, salesOrderNumber, salesOrderItemNumber, salesOrderItemLotNumber, seq ).ConfigureAwait(false); var lot = await lotRepository.TryGetLot( updatedLotNumber ?? salesOrderItemLotNumber, salesOrderItemNumber ).ConfigureAwait(false); var setSequenceNumberToZero = await ItemExistsWithSalesOrderNumberAndSequence( salesOrderNumber, adjustedSalesOrderItem.Seq ).ConfigureAwait(false); var userName = PinnacleApp.Get <IAuthService>().CurrentUser.Name; // Try to insert the newly created record. var workItem = SalesOrderWorkItemFactory.CreateSalesOrderWorkItem( setSequenceNumberToZero, salesOrder, adjustedSalesOrderItem, lot, itemQuantity, updatedItemQuantity, quantityTaken, _configurationService.GetString(_userIdConfigKey), userName ); try { var table = await GetCloudTable().ConfigureAwait(false); return(await table.CreateItemAsync(workItem).ConfigureAwait(false)); } catch (Exception ex) { _logService.WriteErrorLogEntry($"Failed to upsert SalesOrderWorkItem instance: {ex}"); ex.Report(); return(null); } }