HospitalConnectedLayer.HospitalDAL.GetTemplate C# (CSharp) Method

GetTemplate() public method

public GetTemplate ( string title ) : Template
title string
return Shared.Template
        public Template GetTemplate(string title)
        {
            OpenConnection();
            _command.CommandText = "SELECT * FROM Templates WHERE Title = @Title";

            _command.Parameters.Add(GetParam("@Title", title));

            Template template = null;
            var binFormatter = new ListBinaryFormatter<string>();

            try
            {
                using (DbDataReader dataReader = _command.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        template = new Template(binFormatter.Deserialize((byte[]) dataReader["Data"]), title);
                    }
                }
                //LOGGING
                Logger.Info("Template was obtained");
            }
            catch (Exception ex)
            {
                //LOGGING
                Logger.Error("Can't get template!",ex);
                throw new InvalidOperationException("Can't get template!");
            }
            finally
            {
                CloseConnection();
            }

            return template;
        }

Usage Example

Ejemplo n.º 1
0
 public void AddandGetTemplate_TwoTemplates_ShouldPass(Template template)
 {
     var dataStorage = new HospitalDAL(_dataProvider, _connectionString);
     dataStorage.AddTemplate(template);
     Template expected = dataStorage.GetTemplate(template.Title);
     Assert.NotEqual(expected, null);
 }