public async Task <IActionResult> Add([FromBody] ClipboardAddBindingModel collection) { try { var model = _mapper.Map <ClipboardAddSchema>(collection); var query = new ClipboardGetFirstSchema { AccountId = CurrentAccount.Id, Content = model.Content }; var duplicated = await _clipboardService.FirstAsync(query).ConfigureAwait(true); if (duplicated == null) { await _clipboardService.AddAsync(model).ConfigureAwait(true); return(Ok()); } return(BadRequest(_localizer[DataTransferer.DuplicatedValueFound().Message])); } catch (Exception ex) { Log.Error(ex, ex.Source); return(Problem()); } }
public void Add() { var clipboard = new ClipboardAddSchema { AccountId = 21, DeviceId = 17, TypeId = ContentType.txt.ToInt(), Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("Content")), CreatedAt = DateTime.Now, StatusId = Status.Active.ToInt() }; var clipboardId = _clipboardService.AddAsync(clipboard).GetAwaiter().GetResult(); Assert.IsTrue(clipboard.StatusCode == 200); Assert.IsTrue(clipboardId > 0); }