private string calculateURL(AlternativesSelection selection) { string newUrl; if (!selection.Url.Contains("?")) { // no params newUrl = selection.Url + "?fm__selection_viewguid=" + selection.ViewGuid; } else { // params exists newUrl = selection.Url + "&fm__selection_viewguid=" + selection.ViewGuid; } return(newUrl); }
public async Task <IActionResult> ClientModulePostAlternativesSelection([FromRoute] Guid projectCode, [FromBody] AlternativesSelectionPostBase boundObject, ApiVersion version) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var projectDB = await _context.Projects.FirstOrDefaultAsync(p => p.Code == projectCode); if (projectDB == null) { return(Conflict(new { header = "Please contact the website admin.", subheader = "", text = "The project-id '" + projectCode + "' is not registered." })); } else if (projectDB.IsPaused) { return(Conflict(new { header = "Please be patient.", subheader = "", text = "This page is currently paused for feedback." })); } if (!String.IsNullOrEmpty(boundObject.IotaAddress)) { if (!IOTAHelper.IsAddress(boundObject.IotaAddress)) { return(BadRequest(new { header = "Input error", subheader = "", text = "The submitted IOTA address is not a valid address, please check it." })); } } if (!String.IsNullOrEmpty(boundObject.Email)) { if (!_regexUtil.IsValidEmail(boundObject.Email)) { return(BadRequest(new { header = "Input error", subheader = "", text = "The submitted email address is not a valid address, please check it." })); } } if (boundObject.Url.EndsWith("/")) { boundObject.Url.Remove(boundObject.Url.Length - 1); } AlternativesSelection selection = new AlternativesSelection() { Name = boundObject.Name, Email = boundObject.Email, IotaAddress = boundObject.IotaAddress, Sent = boundObject.Sent, AreaInfoItems = boundObject.AreaInfoItems, Url = boundObject.Url, ViewGuid = GUIDHelper.CreateCryptographicallySecureGuid(), // a test if same ViewGuid already exists would be good ProjectId = projectDB.Id }; _context.AlternativesSelections.Add(selection); await _context.SaveChangesAsync(); var domainDB = await _context.Domains.FirstOrDefaultAsync(d => d.Id == projectDB.DomainId); if (domainDB != null) { await _hubContext.Clients.All.SendAsync("AlternativesSelectionAdded", new { authIdentifier = domainDB.UserAuthIdentifier, domain = domainDB.Url, projectName = projectDB.Name, domainId = domainDB.Id, projectId = projectDB.Id, alternativesSelectionId = selection.Id, sent = selection.Sent }); // would be better to take an extra (temporary) identifier, that the client-side stores } return(CreatedAtAction(nameof(ClientModuleGetByViewID), new { projectCode, viewGuid = selection.ViewGuid, version = $"{version}" }, selection)); }