public async Task AddPostAsync(AddRequestDto addRequest) { var filePath = string.Empty; var fileSnapshotImagePath = string.Empty; // todo dodaj && addRequest.UserNickname != null jak bedzie logowanie if (addRequest.EncodedFile != null && addRequest.FileName != null) { var encryptedFile = new EncryptedFile(addRequest); await encryptedFile.DecryptAndSaveFile(); encryptedFile.GenerateAndSaveSnapshot(); filePath = encryptedFile.FilePath; fileSnapshotImagePath = encryptedFile.SnapshotImagePath; } var post = new Post( addRequest.Title.ToLower().RemoveDiacritics(), addRequest.Description.ToLower().RemoveDiacritics(), addRequest.School, addRequest.MaterialType, fileSnapshotImagePath, filePath, addRequest.UserNickname); await this.postRepository.AddAsync(post); }
public void AddPastMin() { var request = new AddRequestDto() { Start = decimal.MinValue, Amount = -100 }; var result = controller.Add(request); var controllerResult = result as ObjectResult; // assert Assert.NotNull(controllerResult); Assert.Equal(500, controllerResult.StatusCode); }
public void AddValidNumbers(decimal start, decimal amount, decimal expected) { // act var request = new AddRequestDto() { Start = start, Amount = amount }; var result = controller.Add(request); var okResult = result as OkObjectResult; // assert Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); Assert.Equal(expected, okResult.Value); }
public EncryptedFile(AddRequestDto request) { if (this.CalcBase64SizeInKBytes(request.EncodedFile) > 10000) { throw new Exception(Strings.fizeSizeIsTooBig); } var base64Strings = request.EncodedFile.Split(','); this.FileName = request.FileName; this.FileType = base64Strings[0]; this.Base64File = base64Strings[1]; // this.UserNickname = request.UserNickname; }
public IActionResult Add(AddRequestDto request) { var operation = $"{request.Start} + { request.Amount}"; try { logger.LogInformation($"Add request received: {operation}"); var result = calcService.Add(request.Start, request.Amount); logger.LogInformation($"Result for {operation} = {result}"); return(Ok(result)); } catch (Exception ex) { logger.LogError(ex, $"Error processing {operation}"); return(StatusCode(500, "Error: " + ex.Message)); } }
public async Task <AddRequestDto> AddRequest(RequestDto dto) { var addRequestDto = new AddRequestDto(); var request = _mapper.Map <Request>(dto); var notification = request.ValidationErrors(); if (notification.HasErrors()) { addRequestDto.Notification = notification; return(addRequestDto); } _requestRepository.Add(request); await _requestRepository.Commit(); addRequestDto.Id = request.Id; return(_mapper.Map <AddRequestDto>(request)); }
public async Task <IActionResult> AddAsync([FromBody] AddRequestDto addRequest) { await this.postService.AddPostAsync(addRequest); return(this.Ok()); }