public void Update(DailyReportSymptom dailyReportSymptom)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        UPDATE DailyReportSymptom
                           SET DailyReportId = @DailyReportId,
                               SymptomId = @SymptomId,
                               Comment = @Comment,
                               Urgency = @Urgency
                         WHERE Id = @Id";

                    DbUtils.AddParameter(cmd, "@DailyReportId", dailyReportSymptom.DailyReportId);
                    DbUtils.AddParameter(cmd, "@SymptomId", dailyReportSymptom.SymptomId);
                    DbUtils.AddParameter(cmd, "@Comment", dailyReportSymptom.Comment);
                    DbUtils.AddParameter(cmd, "@Urgency", dailyReportSymptom.Urgency);
                    DbUtils.AddParameter(cmd, "@Id", dailyReportSymptom.Id);

                    cmd.ExecuteNonQuery();
                }
            }
        }
示例#2
0
        public IActionResult Put(int id, DailyReportSymptom dailyReportSymptom)
        {
            if (id != dailyReportSymptom.Id)
            {
                return(BadRequest());
            }

            _dailyReportSymptomRepository.Update(dailyReportSymptom);
            return(NoContent());
        }
        public DailyReportSymptom GetDailyReportSymptomById(int dailyReportSymptomId)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        SELECT drs.Id, drs.DailyReportId, drs.SymptomId, drs.Comment, drs.Urgency,
                        s.Name
                        FROM DailyReportSymptom drs
                        LEFT JOIN Symptom s ON s.Id = drs.SymptomId
                        WHERE drs.Id = @Id";

                    cmd.Parameters.AddWithValue("@Id", dailyReportSymptomId);
                    var reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        DailyReportSymptom dailyReportSymptom = new DailyReportSymptom()
                        {
                            Id            = DbUtils.GetInt(reader, "Id"),
                            DailyReportId = DbUtils.GetInt(reader, "DailyReportId"),
                            SymptomId     = DbUtils.GetInt(reader, "SymptomId"),
                            Comment       = DbUtils.GetString(reader, "Comment"),
                            Urgency       = DbUtils.GetInt(reader, "Urgency"),
                            Symptom       = new Symptom()
                            {
                                Name = DbUtils.GetString(reader, "Name")
                            },
                        };
                        reader.Close();
                        return(dailyReportSymptom);
                    }
                    else
                    {
                        reader.Close();
                        return(null);
                    }
                }
            }
        }
        public void Add(DailyReportSymptom dailyReportSymptom)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                            INSERT INTO DailyReportSymptom (DailyReportId, SymptomId, Comment, Urgency)
                            OUTPUT INSERTED.ID
                            VALUES (@DailyReportId, @SymptomId, @Comment, @Urgency)";

                    DbUtils.AddParameter(cmd, "@DailyReportId", dailyReportSymptom.DailyReportId);
                    DbUtils.AddParameter(cmd, "@SymptomId", dailyReportSymptom.SymptomId);
                    DbUtils.AddParameter(cmd, "@Comment", dailyReportSymptom.Comment);
                    DbUtils.AddParameter(cmd, "@Urgency", dailyReportSymptom.Urgency);


                    dailyReportSymptom.Id = (int)cmd.ExecuteScalar();
                }
            }
        }
示例#5
0
 public IActionResult DailyReport(DailyReportSymptom dailyReportSymptom)
 {
     _dailyReportSymptomRepository.Add(dailyReportSymptom);
     return(NoContent());
 }