Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public static CorrectionView Map(this CorrectionModel source)
 => new CorrectionView
 {
     Id            = source.Id,
     Language      = source.Language,
     Profile       = source.Profile,
     IncorrectText = source.IncorrectText,
     CorrectText   = source.CorrectText
 };
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 public AddCorrectionRequest(CorrectionModel correctionModel)
 {
     Correction = correctionModel;
 }
Exemplo n.º 6
0
 public UpdateCorrectionRequest(CorrectionModel correctionModel)
 {
     Correction = correctionModel;
 }