public async Task InsertAsync(ContractFileSession item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } var toCheck = await context.ContractFileSessions.FindAsync(item.Id); if (toCheck != null) { await RemoveIfExpired(toCheck); } var res = await context.ContractFileSessions.FindAsync(item.Id); if (res != null) { throw new AlreadyExistsException(nameof(ContractFileSession) + " " + item.Id); } await context.ContractFileSessions.AddAsync(item); await context.SaveChangesAsync(); }
public async Task <ActionResult> InitiateSessionAsync(string id, List <IFormFile> contractFile) { if (contractFile == null) { throw new ArgumentNullException(nameof(contractFile)); } var fileContentBuilder = new StringBuilder(); using (var reader = new StreamReader(contractFile.Single().OpenReadStream())) { while (reader.Peek() >= 0) { fileContentBuilder.AppendLine(await reader.ReadLineAsync()); } } var newItem = new ContractFileSession() { Id = id, SerializedContract = fileContentBuilder.ToString() }; return(await InsertAsync(newItem)); }
public async Task <ActionResult> InsertAsync(ContractFileSession item) { try { await facade.InsertAsync(item); return(Ok()); } catch (AlreadyExistsException e) { return(BadRequest(e)); } }
public async Task Update_CheckExpired() { using var contextBuilder = new ContractEditorDbTestBuilder(); try { var contract = new ContractFileSession() { Id = "expired" }; await Facade(contextBuilder).UpdateAsync(contract); Assert.Fail(); } catch (NotFoundException) { } }
public async Task <ActionResult> UpdateAsync(ContractFileSession item) { try { await facade.UpdateAsync(item); return(Ok()); } catch (NotFoundException) { return(NotFound()); } catch (BadRequestException e) { return(BadRequest(e)); } }
async Task CreateNewContractAsync() { var newContract = new EditorContract(); var newSession = ContractFileSession.FromContract(newContract); newSession.Id = newSessionId; Loading = true; try { await ContractFileSessionService.InsertAsync(newSession); NavigationManager.NavigateTo("/ContractFileSession/" + newSession.Id); } catch (Exception) { newContractAlertController.AddAlert("Something went wrong :(", AlertScheme.Danger); } Loading = false; }
public async Task UpdateAsync(ContractFileSession item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (item.Id == default) { throw new BadRequestException("Id should not be default"); } var toCheck = await context.ContractFileSessions .AsNoTracking() .Where(e => e.Id == item.Id) .SingleOrDefaultAsync(); if (toCheck == null) { throw new NotFoundException(nameof(ContractFileSession) + " " + item.Id); } if (toCheck.IsExpired()) { await RemoveIfExpired(item); throw new NotFoundException(nameof(ContractFileSession) + " " + item.Id); } if (toCheck.ExpirationDate != item.ExpirationDate) { throw new BadRequestException("Expiration dates do not match"); } context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); }
public Task UpdateAsync(ContractFileSession item) => repository.UpdateAsync(item);
public Task InsertAsync(ContractFileSession item) => repository.InsertAsync(item);
public async Task RemoveIfExpired(ContractFileSession session) { await RemoveExpiredSessionsAsync(new ContractFileSession[] { session }); }