public CorrectionView Render(CorrectionModel correction) { var view = correction.Map(); view.Links.Add(_linkRenderer.Render(new Link { ActionName = nameof(ToolController.GetCorrectionById), Method = HttpMethod.Get, Rel = RelTypes.Self, Parameters = new { language = correction.Language, profile = correction.Profile, id = correction.Id } })); if (_userHelper.IsAdmin) { view.Links.Add(_linkRenderer.Render(new Link { ActionName = nameof(ToolController.UpdateCorrection), Method = HttpMethod.Put, Rel = RelTypes.Update, Parameters = new { language = correction.Language, profile = correction.Profile, id = correction.Id } })); view.Links.Add(_linkRenderer.Render(new Link { ActionName = nameof(ToolController.DeleteCorrection), Method = HttpMethod.Delete, Rel = RelTypes.Delete, Parameters = new { language = correction.Language, profile = correction.Profile, id = correction.Id } })); } return(view); }
public static CorrectionView Map(this CorrectionModel source) => new CorrectionView { Id = source.Id, Language = source.Language, Profile = source.Profile, IncorrectText = source.IncorrectText, CorrectText = source.CorrectText };
public async Task <CorrectionModel> UpdateCorrection(CorrectionModel correction, CancellationToken cancellationToken) { using (var connection = _connectionProvider.GetConnection()) { var sql = @"Update Corrections Set IncorrectText = @IncorrectText, CorrectText = @CorrectionText Where Id = @Id"; var command = new CommandDefinition(sql, new { Id = correction.Id, IncorrectText = correction.IncorrectText, CorrectionText = correction.CorrectText }, cancellationToken: cancellationToken); await connection.ExecuteScalarAsync <int>(command); return(await GetCorrection(correction.Id, cancellationToken)); } }
public async Task <CorrectionModel> AddCorrection(CorrectionModel correction, CancellationToken cancellationToken) { var id = 0; using (var connection = _connectionProvider.GetConnection()) { var sql = @"Insert Into Corrections(Language, Profile, IncorrectText, CorrectText) Output Inserted.Id VALUES(@Language, @Profile, @IncorrectText, @CorrectText);"; var command = new CommandDefinition(sql, new { Language = correction.Language, Profile = correction.Profile, IncorrectText = correction.IncorrectText, CorrectText = correction.CorrectText }, cancellationToken: cancellationToken); id = await connection.ExecuteScalarAsync <int>(command); } return(await GetCorrection(id, cancellationToken)); }
public AddCorrectionRequest(CorrectionModel correctionModel) { Correction = correctionModel; }
public UpdateCorrectionRequest(CorrectionModel correctionModel) { Correction = correctionModel; }