HospitalConnectedLayer.HospitalDAL.AddTemplate C# (CSharp) Method

AddTemplate() public method

public AddTemplate ( Template template ) : void
template Shared.Template
return void
        public void AddTemplate(Template template)
        {
            OpenConnection();
            var binFormatter = new ListBinaryFormatter<string>();

            _command.CommandText = "INSERT INTO Templates(Title, Data) VALUES(@Title, @Data)";

            _command.Parameters.Add(GetParam("@Title", template.Title));
            _command.Parameters.Add(GetParam("@Data", binFormatter.Serialize(template.Data)));

            try
            {
                _command.ExecuteNonQuery();
                //LOGGING
                Logger.Info("Template was added");
            }
            catch (SqlException ex)
            {
                //LOGGING
                Logger.Error("This template already exists!",ex);
                throw new InvalidOperationException("This template already exists!");
            }
            catch (Exception ex)
            {
                //LOGGING
                Logger.Error("Can't add template!",ex);
                throw new InvalidOperationException("Can't add template!");
            }
            finally
            {
                CloseConnection();
            }
        }

Usage Example

Ejemplo n.º 1
0
 public void GetTemplates_DBWithValues_ShouldPass()
 {
     var dataStorage = new HospitalDAL(_dataProvider, _connectionString);
     dataStorage.AddTemplate(new Template(new List<string> { "alcohol", "drugs" }, "Alcho2 Test"));
     int templatesCount = dataStorage.GetTemplates().Count;
     Assert.True(templatesCount >= 1);
 }
All Usage Examples Of HospitalConnectedLayer.HospitalDAL::AddTemplate