Пример #1
0
        public async Task <int> Add(Task entity)
        {
            entity.DateCreated = DateTime.Now;
            var sql = "INSERT INTO [Tasks]([Name],[Description],[Status],[DueDate],[DateCreated],[DateModified]) VALUES (@Name,@Description,@Status,@DueDate,@DateCreated,@DateModified)";

            using (var con = new SqlConnection(_configuration.GetConnectionString("connectionstring")))
            {
                con.Open();
                var affectedRows = await con.ExecuteAsync(sql, entity);

                return(affectedRows);
            }
        }
Пример #2
0
        public async Task <int> Update(Task entity)
        {
            entity.DateCreated = DateTime.Now;
            var sql = "UPDATE [Tasks]" +
                      "SET [Name]=@Name,[Description]=@Description,[Status]=@Status,[DueDate]=@DueDate,[DateCreated]=@DateCreated,[DateModified]=@DateModified WHERE Id=@Id";

            using (var con = new SqlConnection(_configuration.GetConnectionString("connectionstring")))
            {
                con.Open();
                var affectedRows = await con.ExecuteAsync(sql, entity);

                return(affectedRows);
            }
        }