public static async Task <IActionResult> UpdateDriver([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "drivers")] HttpRequest req, ILogger log) { log.LogInformation("UpdateDriver triggered...."); try { await Utilities.ValidateToken(req); string requestBody = new StreamReader(req.Body).ReadToEnd(); DriverItem driver = JsonConvert.DeserializeObject <DriverItem>(requestBody); var persistenceService = ServiceFactory.GetPersistenceService(); return((ActionResult) new OkObjectResult(await persistenceService.UpsertDriver(driver, true))); } catch (Exception e) { var error = $"UpdateDriver failed: {e.Message}"; log.LogError(error); if (error.Contains(Constants.SECURITY_VALITION_ERROR)) { return(new StatusCodeResult(401)); } else { return(new BadRequestObjectResult(error)); } } }
public async Task <string> UpsertDriverLocation(DriverLocationItem location, bool isIgnoreChangeFeed = false) { var error = ""; string resourceId = ""; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } DriverItem driver = await RetrieveDriver(location.DriverCode); if (driver == null) { throw new Exception($"Unable to locate a driver with code {location.DriverCode}"); } // Just making sure... location.CollectionType = ItemCollectionTypes.DriverLocation; location.UpsertDate = DateTime.Now; if (location.Id == "") { location.Id = $"{location.DriverCode}-{location.CollectionType}-{Guid.NewGuid().ToString()}"; } //TODO: DriverLocationItem has no Code property, which is the PK 😬 var response = await(await GetCosmosContainer()).UpsertItemAsync(location); // Also update the driver latest location driver.Latitude = location.Latitude; driver.Longitude = location.Longitude; await UpsertDriver(driver, isIgnoreChangeFeed); if (!isIgnoreChangeFeed) { //TODO: This is one way we can react to changes in Cosmos and perhaps enqueue a message or whatever } } catch (Exception ex) { error = ex.Message; throw new Exception(ex.Message, ex); } finally { _loggerService.Log($"{LOG_TAG} - UpsertDriverLocation - Error: {error}"); } //TODO: Always returns empty string... return(resourceId); }
public async Task <string> UpsertDriverLocation(DriverLocationItem location, bool isIgnoreChangeFeed = false) { var error = ""; double cost = 0; string resourceId = ""; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } DriverItem driver = await RetrieveDriver(location.DriverCode); if (driver == null) { throw new Exception($"Unable to locate a driver with code {location.DriverCode}"); } // Just making sure... location.CollectionType = ItemCollectionTypes.DriverLocation; location.UpsertDate = DateTime.Now; if (location.Id == "") { location.Id = $"{location.DriverCode}-{location.CollectionType}-{Guid.NewGuid().ToString()}"; } var response = await(await GetDocDBClient(_settingService)).UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(_docDbDatabaseName, _docDbDigitalMainCollectionName), location); cost = response.RequestCharge; // Also update the driver latest location driver.Latitude = location.Latitude; driver.Longitude = location.Longitude; await UpsertDriver(driver, isIgnoreChangeFeed); if (!isIgnoreChangeFeed) { //TODO: This is one way we can react to changes in Cosmos and perhaps enqueue a message or whatever } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - UpsertDriverLocation - Error: {error}"); } return(resourceId); }
public async Task <IActionResult> OnGetAsync(long?id, string returnUrl) { if (id == null) { return(NotFound()); } ReturnUrl = returnUrl; DriverItem = await _context.Drivers.SingleOrDefaultAsync(m => m.Id == id); if (DriverItem == null) { return(NotFound()); } return(Page()); }
public async Task <DriverItem> UpsertDriver(DriverItem driver, bool isIgnoreChangeFeed = false) { var error = ""; double cost = 0; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... driver.CollectionType = ItemCollectionTypes.Driver; driver.UpsertDate = DateTime.Now; if (driver.Id == "") { if (string.IsNullOrEmpty(driver.Code)) { driver.Code = Utilities.GenerateRandomAlphaNumeric(8); } driver.Id = $"{driver.Code}-{driver.CollectionType}"; } var response = await(await GetDocDBClient(_settingService)).UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(_docDbDatabaseName, _docDbDigitalMainCollectionName), driver); cost = response.RequestCharge; if (!isIgnoreChangeFeed) { await _changeNotifierService.DriverChanged(driver); } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - UpsertDriver - Error: {error}"); } return(driver); }
public async Task <DriverItem> UpsertDriver(DriverItem driver, bool isIgnoreChangeFeed = false) { var error = ""; //double cost = 0; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... driver.CollectionType = ItemCollectionTypes.Driver; driver.UpsertDate = DateTime.Now; if (driver.Id == "") { if (string.IsNullOrEmpty(driver.Code)) { driver.Code = Utilities.GenerateRandomAlphaNumeric(8); } driver.Id = $"{driver.Code}-{driver.CollectionType}"; } var response = await(await GetCosmosContainer()).UpsertItemAsync(driver, new PartitionKey(driver.Code.ToUpper())); if (!isIgnoreChangeFeed) { await _changeNotifierService.DriverChanged(driver); } return(response.Resource); } catch (Exception ex) { error = ex.Message; throw new Exception(ex.Message, ex); } finally { _loggerService.Log($"{LOG_TAG} - UpsertDriver - Error: {error}"); } }
public async Task <IActionResult> OnPostAsync(long?id) { if (id == null) { return(NotFound()); } DriverItem = await _context.Drivers.FindAsync(id); if (DriverItem != null) { _context.Drivers.Remove(DriverItem); await _context.SaveChangesAsync(); } return(Redirect(Url.GetLocalUrl(ReturnUrl))); }
/// <summary> /// Initializes the driver item if needed. /// </summary> private void InitDriverItem(DriverItem driverItem) { if (!driverItem.IsInitialized) { driverItem.IsInitialized = true; if (ExtensionUtils.GetDriverView(adminContext, commApp, driverItem.DriverCode, out DriverView driverView, out string message)) { driverItem.Descr = BuildDriverDescr(driverView); driverItem.DriverView = driverView; } else { driverItem.Descr = message; driverItem.DriverView = null; } }
public DriverViewModel(DriverItem driver) { OriginalModel = driver; if (driver != null) { Id = driver.Id; Name = driver.Name; Gender = driver.Gender; FirstLicenseIssueDate = driver.FirstLicenseIssueDate; LicenseIssue = driver.LicenseIssueDate; ResidentType = driver.ResidentType; IdCardNumber = driver.IdCardNumber; License = driver.LicenseNumber; LicenseType = driver.LicenseType; ValidYears = driver.LicenseValidYears; LivingAddress = driver.LivingAddress; Tel = driver.Tel; Title = driver.Title; WarrantyCode = driver.WarrantyCode; TownId = driver.TownId; GroupId = driver.GroupId; PhotoDriverLicenseBase64 = driver.LicenseImage.ToBase64String(); PhotoIdCard1Base64 = driver.IdCardImage1.ToBase64String(); PhotoIdCard2Base64 = driver.IdCardImage2.ToBase64String(); PhotoAvatarBase64 = driver.AvatarImage.ToBase64String(); ExtraImage1Base64 = driver.ExtraImage1?.ToBase64String(); ExtraImage2Base64 = driver.ExtraImage2?.ToBase64String(); ExtraImage3Base64 = driver.ExtraImage3?.ToBase64String(); IsValid = driver.IsValid(); VehiclesRegistered = driver.Vehicles?.Count ?? 0; TownName = driver.Town?.Name; GroupName = driver.Group?.Name; } }
/// <summary> /// Initializes the driver item if needed. /// </summary> private void InitDriverItem(DriverItem driverItem) { if (!driverItem.IsInitialized) { driverItem.IsInitialized = true; try { KPView kpView = environment.GetKPView(driverItem.FilePath); driverItem.Descr = kpView.KPDescr?.Replace("\n", Environment.NewLine); driverItem.KPView = kpView; } catch (Exception ex) { driverItem.Descr = ex.Message; driverItem.KPView = null; } } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { var townlist = (await _townService.GetAvailableTownsEagerAsync(HttpContext.User)); ViewData["TownList"] = new SelectList(townlist, "Id", "Name"); if (townlist.Any()) { var groups = (await _groupService.ListGroupsForTownEagerAsync(HttpContext.User, townlist.First().Id)); ViewData["GroupList"] = new SelectList(groups, "Id", "Name"); } return(Page()); } var user = await _userManager.GetUserAsync(HttpContext.User); DriverItem.TownId = await _userManager.IsInRoleAsync(user, "TownManager") ? user.TownId : DriverItem.TownId; var driver = new DriverItem(); await DriverItem.FillDriverItemAsync(driver); driver.CreateBy = user.Id; driver.CreationDate = DateTime.Now; driver.Status = StatusType.OK; driver.IdCardImage1 = DriverItem.PhotoIdCard1.UpdateUserFile(driver.IdCardImage1, _context, VisibilityType.CurrentDriver, "身份证国徽面图片", DriverItem.TownId, DriverItem.GroupId); driver.IdCardImage2 = DriverItem.PhotoIdCard2.UpdateUserFile(driver.IdCardImage2, _context, VisibilityType.CurrentDriver, "身份证相片面图片", DriverItem.TownId, DriverItem.GroupId); driver.LicenseImage = DriverItem.PhotoDriverLicense.UpdateUserFile(driver.LicenseImage, _context, VisibilityType.CurrentDriver, "驾驶证照片", DriverItem.TownId, DriverItem.GroupId); driver.AvatarImage = DriverItem.PhotoAvatar.UpdateUserFile(driver.AvatarImage, _context, VisibilityType.CurrentDriver, "驾驶员图片", DriverItem.TownId, DriverItem.GroupId); driver.ExtraImage1 = DriverItem.ExtraImage1.UpdateUserFile(driver.ExtraImage1, _context, VisibilityType.CurrentDriver, "附加图片1", DriverItem.TownId, DriverItem.GroupId); driver.ExtraImage2 = DriverItem.ExtraImage2.UpdateUserFile(driver.ExtraImage2, _context, VisibilityType.CurrentDriver, "附加图片2", DriverItem.TownId, DriverItem.GroupId); driver.ExtraImage3 = DriverItem.ExtraImage3.UpdateUserFile(driver.ExtraImage3, _context, VisibilityType.CurrentDriver, "附加图片3", DriverItem.TownId, DriverItem.GroupId); _context.Drivers.Add(driver); await _context.SaveChangesAsync(); return(Redirect(Url.GetLocalUrl(ReturnUrl))); }
public DriverListViewModel(DriverItem t = null) { if (t != null) { Id = t.Id; Name = t.Name; IdCardNumber = t.IdCardNumber; License = t.LicenseNumber; LicenseType = t.LicenseType; LicenseIssueDate = t.LicenseIssueDate; LicenseValidYears = t.LicenseValidYears; Gender = t.Gender; VehiclesRegistered = t.Vehicles?.Count ?? 0; Tel = t.Tel; IsValid = t.IsValid(); TownName = t.Town?.Name; GroupName = t.Group?.Name; FirstLicenseIssueDate = t.FirstLicenseIssueDate; ResidentType = t.ResidentType; } }
public async Task FillDriverItemAsync(DriverItem driver) { driver.Name = this.Name; driver.Gender = this.Gender; driver.FirstLicenseIssueDate = this.FirstLicenseIssueDate; driver.LicenseIssueDate = this.LicenseIssue; driver.ResidentType = this.ResidentType; driver.IdCardNumber = this.IdCardNumber; driver.LicenseNumber = this.License; driver.LicenseType = this.LicenseType; driver.LicenseValidYears = this.ValidYears; driver.LivingAddress = this.LivingAddress; driver.Tel = this.Tel; driver.Title = this.Title; driver.WarrantyCode = this.WarrantyCode; driver.TownId = this.TownId; driver.GroupId = this.GroupId; }
private void setItems() { var newCollection = new ObservableCollection<INodeWrapper>(); foreach (var nDriver in DeviceConfiguration.NodeDriverChildren.Items) { var driver = FindItemByNodeId(nDriver.ID) as DriverItem; if (driver == null) { driver = new DriverItem(this, nDriver); HookupHandlers(driver); } newCollection.Add(driver); } Items = newCollection; }
public Task <DriverItem> UpsertDriver(DriverItem driver, bool isIgnoreChangeFeed = false) { throw new NotImplementedException(); }
public async Task DriverChanged(DriverItem driver) { //TODO: React to `Driver` changes }
void HookupHandlers(DriverItem driver) { driver.Parent = this; driver.Edited += new EditedHandler(Driver_Edited); driver.Deleted += new DeletedHandler(Driver_Deleted); }