示例#1
0
        public void AddStratigraphyAndAddToSample(Stratigraphy stratigraphy)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        INSERT INTO Stratigraphy (UserProfileId, ReportId, CreateDate, Notes)
                        OUTPUT INSERTED.ID
                        VALUES (@UserProfileId, @ReportId, GETDATE(), @Notes)";

                    DbUtils.AddParameter(cmd, "@UserProfileId", stratigraphy.UserProfileId);
                    DbUtils.AddParameter(cmd, "@ReportId", stratigraphy.ReportId);
                    //DbUtils.AddParameter(cmd, "@CreateDate", stratigraphy.CreateDate);
                    DbUtils.AddParameter(cmd, "@Notes", stratigraphy.Notes);

                    stratigraphy.Id = (int)cmd.ExecuteScalar();

                    cmd.CommandText = @"
                                    UPDATE Sample
                                    SET StratigraphyId = @StratigraphyId
                                    WHERE Id = @Id;
                                            ";
                    DbUtils.AddParameter(cmd, "@StratigraphyId", stratigraphy.Id);
                    DbUtils.AddParameter(cmd, "@Id", stratigraphy.InitialSampleId);
                    cmd.ExecuteScalar();
                }
            }
        }
示例#2
0
        public Stratigraphy GetStratigraphyById(int Id)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT Id, UserProfileId, ReportId, CreateDate, Notes FROM Stratigraphy
                                        WHERE Id = @Id;";

                    DbUtils.AddParameter(cmd, "@Id", Id);

                    var reader = cmd.ExecuteReader();


                    Stratigraphy stratigraphy = null;
                    if (reader.Read())
                    {
                        stratigraphy = new Stratigraphy()
                        {
                            Id            = DbUtils.GetInt(reader, "Id"),
                            UserProfileId = DbUtils.GetInt(reader, "UserProfileId"),
                            ReportId      = DbUtils.GetInt(reader, "ReportId"),
                            CreateDate    = DbUtils.GetDateTime(reader, "CreateDate"),
                            Notes         = DbUtils.GetString(reader, "Notes")
                        };
                    }

                    reader.Close();

                    return(stratigraphy);
                }
            }
        }
        public IActionResult Post(Stratigraphy stratigraphy)
        {
            var currentUserProfile = GetCurrentUserProfile();

            stratigraphy.UserProfileId = currentUserProfile.Id;
            _stratigraphyRepository.AddStratigraphyAndAddToSample(stratigraphy);
            return(CreatedAtAction("Get", new { id = stratigraphy.Id }, stratigraphy));
        }
        public IActionResult Put(int id, Stratigraphy stratigraphy)
        {
            var currentUserProfile = GetCurrentUserProfile();
            var dbStratigraphy     = _stratigraphyRepository.GetStratigraphyById(id);

            if (dbStratigraphy.UserProfileId == currentUserProfile.Id)
            {
                if (id != stratigraphy.Id)
                {
                    return(BadRequest());
                }

                _stratigraphyRepository.Update(stratigraphy);

                return(Ok());
            }
            else
            {
                return(Unauthorized());
            }
        }
示例#5
0
        public void Update(Stratigraphy stratigraphy)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        UPDATE Stratigraphy
                        SET Notes = @Notes
                        WHERE Id = @Id";

                    //DbUtils.AddParameter(cmd, "@UserProfileId", stratigraphy.UserProfileId);
                    //DbUtils.AddParameter(cmd, "@ReportId", stratigraphy.ReportId);
                    //DbUtils.AddParameter(cmd, "@CreateDate", stratigraphy.CreateDate);
                    DbUtils.AddParameter(cmd, "@Notes", stratigraphy.Notes);
                    DbUtils.AddParameter(cmd, "@Id", stratigraphy.Id);

                    cmd.ExecuteNonQuery();
                }
            }
        }