Пример #1
0
        public async Task <IActionResult> PutGroupComments(int id, GroupComments groupComments)
        {
            if (id != groupComments.GroupCommentId)
            {
                return(BadRequest());
            }

            _context.Entry(groupComments).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupCommentsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <GroupComments> > PostGroupComments(GroupComments groupComments)
        {
            _context.GroupComments.Add(groupComments);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroupComments", new { id = groupComments.GroupCommentId }, groupComments));
        }
        public void CreateGroupComment(GroupComments groupComment)
        {
            DbCommand command = SqlConncetionHelper.Connection.CreateCommand();

            DbParameter groupIdParameter = command.CreateParameter();

            groupIdParameter.DbType        = System.Data.DbType.Int32;
            groupIdParameter.IsNullable    = false;
            groupIdParameter.ParameterName = "@GroupId";
            groupIdParameter.Value         = groupComment.GroupId;

            DbParameter userIdParameter = command.CreateParameter();

            userIdParameter.DbType        = System.Data.DbType.Int32;
            userIdParameter.IsNullable    = false;
            userIdParameter.ParameterName = "@UserId";
            userIdParameter.Value         = groupComment.UserId;

            DbParameter textParameter = command.CreateParameter();

            textParameter.DbType        = System.Data.DbType.String;
            textParameter.IsNullable    = false;
            textParameter.ParameterName = "@Text";
            textParameter.Value         = groupComment.Text;

            command.Parameters.AddRange(new DbParameter[] { groupIdParameter, userIdParameter, textParameter });
            command.CommandText = @"INSERT INTO [dbo].[group_comments]([group_id],[user_id],[comment_text]) VALUES
                                        (@GroupId, @UserId, @Text)";

            SqlConncetionHelper.ExecuteCommands(command);
        }