private async void cmdUploadChummerFile_Click(object sender, EventArgs e) { ResultSINnerPut res = await Utils.UploadChummerFileAsync(MySINnersUsercontrol.MyCE); if (!res.CallSuccess) { throw new NotImplementedException(res.ErrorText); } }
public async Task <ActionResult <ResultSINnerPut> > PutSIN([FromRoute] Guid id, IFormFile uploadedFile) { ResultSINnerPut res; ApplicationUser user = null; SINner dbsinner = null; try { var sin = await _context.SINners.Include(a => a.SINnerMetaData.Visibility.UserRights).FirstOrDefaultAsync(a => a.Id == id); if (sin == null) { var e = new ArgumentException("Sinner with Id " + id + " not found!"); res = new ResultSINnerPut(e); return(NotFound(res)); } user = await _signInManager.UserManager.FindByNameAsync(User.Identity.Name); dbsinner = await CheckIfUpdateSINnerFile(id, user); if (dbsinner == null) { var e = new NoUserRightException("You may not edit this (existing) sinner with id " + id + "."); res = new ResultSINnerPut(e); return(Conflict(res)); } sin.GoogleDriveFileId = dbsinner.GoogleDriveFileId; if (user == null) { var e = new NoUserRightException("User not found!"); res = new ResultSINnerPut(e); return(NotFound(res)); } sin.DownloadUrl = Startup.GDrive.StoreXmlInCloud(sin, uploadedFile); dbsinner.DownloadUrl = sin.DownloadUrl; //_context.Entry(dbsinner).CurrentValues.SetValues(sin); try { var tc = new Microsoft.ApplicationInsights.TelemetryClient(); Microsoft.ApplicationInsights.DataContracts.EventTelemetry telemetry = new Microsoft.ApplicationInsights.DataContracts.EventTelemetry("PutStoreXmlInCloud"); telemetry.Properties.Add("User", user.Email); telemetry.Properties.Add("SINnerId", sin.Id.ToString()); telemetry.Properties.Add("FileName", uploadedFile.FileName?.ToString()); telemetry.Metrics.Add("FileSize", uploadedFile.Length); tc.TrackEvent(telemetry); } catch (Exception e) { _logger.LogError(e.ToString()); } try { int x = await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { res = new ResultSINnerPut(e); return(Conflict(res)); } res = new ResultSINnerPut(sin); return(Ok(res)); } catch (NoUserRightException e) { res = new ResultSINnerPut(e); return(BadRequest(res)); } catch (Exception e) { try { var tc = new Microsoft.ApplicationInsights.TelemetryClient(); Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry telemetry = new Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry(e); telemetry.Properties.Add("User", user?.Email); telemetry.Properties.Add("SINnerId", dbsinner?.Id?.ToString()); telemetry.Properties.Add("FileName", uploadedFile.FileName?.ToString()); telemetry.Metrics.Add("FileSize", uploadedFile.Length); tc.TrackException(telemetry); } catch (Exception ex) { _logger.LogError(ex.ToString()); } res = new ResultSINnerPut(e); return(BadRequest(res)); } }