Example #1
0
        /// <summary>
        /// Returns a filterd list of Pictures from the directory, based on a database query.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts,
                                                       IEXIFModel exifParts)
        {
            var queryString =
                $"Select ID, FileName, fk_IPTC, fk_EXIF, fk_Camera, fk_Photographer from PictureModel";
            var liste = new List <IPictureModel>();

            using (var connection = new SqlConnection(ConnectionString))
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = queryString;

                    connection.Open();

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var model = new PictureModel();
                            int.TryParse(reader["ID"].ToString(), out var tempInt);
                            model.ID           = tempInt;
                            model.FileName     = reader["FileName"].ToString();
                            model.IPTC         = new IPTCModel();
                            model.EXIF         = new EXIFModel();
                            model.Camera       = reader["fk_Camera"] == DBNull.Value ? null : new CameraModel();
                            model.Photographer = reader["fk_Photographer"] == DBNull.Value ? null : new PhotographerModel();
                            liste.Add(model);
                        }
                    }
                }
            return(liste);
        }
Example #2
0
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            if (pictureTable.Count == 0)
            {
                PictureModel newPicture0;

                if (string.IsNullOrWhiteSpace(namePart))
                {
                    newPicture0 = new PictureModel("");
                }
                else
                {
                    newPicture0 = new PictureModel(namePart);
                }


                newPicture0.ID = 1;


                pictureTable.Add(newPicture0);
            }


            return(pictureTable);
        }
Example #3
0
        /// <summary>
        /// Returns a filterd list of Pictures from the directory, based on a database query.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, BIF.SWE2.Interfaces.Models.IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            if (namePart != null)
            {
                IPictureModel pi = new PictureModel("Blume.jpg");
                foreach (IPictureModel pm in picl)
                {
                    if (pm.FileName == pi.FileName)
                    {
                        pi.ID = pm.ID;
                    }
                }
                Save(pi);
            }

            if (!string.IsNullOrEmpty(namePart))
            {
                List <IPictureModel> result = new List <IPictureModel>();
                foreach (IPictureModel p in picl)
                {
                    if (p.FileName.ToLower().Contains(namePart.ToLower()))
                    {
                        result.Add(p);
                    }
                }
                return(result);
            }
            else
            {
                return(picl);
            }
        }
Example #4
0
 public PhotographerViewModel(IPhotographerModel mdl)
 {
     if (mdl != null)
     {
         PhotographerModel = mdl;
     }
 }
Example #5
0
        /// <summary>
        /// Saves all changes.
        /// </summary>
        /// <param name="photographer"></param>
        public void Save(IPhotographerModel photographer)
        {
            int max = 0;
            IPhotographerModel del = null;

            if (photographer.ID > 0)
            {
                foreach (IPhotographerModel p in phol)
                {
                    if (p.ID == photographer.ID)
                    {
                        del = p;
                        break;
                    }
                }
                phol.Remove(del); //Add errorhandling here
            }
            else
            {
                foreach (IPhotographerModel p in phol)
                {
                    if (p.ID > max)
                    {
                        max = p.ID;
                    }
                }
                photographer.ID = max + 1;
            }
            phol.Add(photographer);
        }
Example #6
0
        public void Update(IPhotographerModel photographer)
        {
            var output = $"Update photographer with ID \"{photographer.ID}\": {photographer.LastName} {photographer.FirstName}, born on {photographer.BirthDay}";

            if (photographer == null)
            {
                throw new ArgumentNullException(nameof(photographer));
            }
            Console.WriteLine(output);
            try
            {
                Conn.Open();
                PS.UpdatePhotographer.Parameters["@PG_ID"].Value     = photographer.ID;
                PS.UpdatePhotographer.Parameters["@FirstName"].Value = photographer.FirstName;
                PS.UpdatePhotographer.Parameters["@LastName"].Value  = photographer.LastName;
                PS.UpdatePhotographer.Parameters["@BirthDay"].Value  =
                    photographer.BirthDay != null ? (object)photographer.BirthDay : DBNull.Value;
                PS.UpdatePhotographer.Parameters["@Notes"].Value = photographer.Notes;
                PS.UpdatePhotographer.ExecuteNonQuery();
                Conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception(output, e);
            }
            finally
            {
                Conn.Close();
            }
        }
Example #7
0
        /// <summary>
        /// Saves all changes of one photographer to the database.
        /// </summary>
        /// <param name="photographer"></param>
        public void Save(IPhotographerModel photographer)
        {
            var query = String.Empty;

            if (Exists(photographer))
            {
                query = "UPDATE dbo.PhotographerModel " +
                        "SET FirstName = @firstname, LastName = @lastname, Birthday = @birthday, Notes = @notes " +
                        "WHERE ID = @id;";
            }
            else
            {
                query = "INSERT INTO dbo.PhotographerModel(FirstName, LastName, Birthday, Notes)"
                        + "VALUES(@firstname, @lastname, @birthday, @notes);";
            }

            // Create and prepare an SQL statement.
            var firstnameParam =
                new SqlParameter("@firstname", SqlDbType.VarChar, 100)
            {
                Value = photographer.FirstName
            };
            var lastnameParam =
                new SqlParameter("@lastname", SqlDbType.VarChar, 50)
            {
                Value = photographer.LastName
            };
            var birthdayParam =
                new SqlParameter("@birthday", SqlDbType.DateTime)
            {
                Value = photographer.BirthDay
            };
            var notesParam = new SqlParameter("@notes", SqlDbType.Text)
            {
                Value = photographer.Notes
            };

            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                var command = new SqlCommand(null, connection)
                {
                    CommandText = query
                };

                command.Parameters.Add(firstnameParam);
                command.Parameters.Add(lastnameParam);
                command.Parameters.Add(birthdayParam);
                command.Parameters.Add(notesParam);

                // Call Prepare after setting the Commandtext and Parameters.
                command.Prepare();

                // Change parameter values and call ExecuteNonQuery.
                command.ExecuteScalar();
                connection.Close();
            }
        }
Example #8
0
 /// <summary>
 /// Returns a filterd list of Pictures from the directory, based on a database query.
 /// </summary>
 /// <returns></returns>
 public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts,
                                                IIPTCModel iptcParts, IEXIFModel exifParts)
 {
     if (namePart == null && photographerParts == null && iptcParts == null && exifParts == null)
     {
         return(Pictures);
     }
     return(Pictures.Where(x => x.FileName == namePart));
 }
Example #9
0
        public void mock_dal_should_return_fake_Photographers_data_by_ID()
        {
            IDataAccessLayer dal = ueb.GetDataAccessLayer();

            AssertNotNull("GetDataAccessLayer", dal);

            IPhotographerModel obj = dal.GetPhotographer(1234);

            AssertNotNull("dal.GetPhotographer", obj);
        }
Example #10
0
        public void bl_should_return_Photographer_by_ID()
        {
            IBusinessLayer bl = ueb.GetBusinessLayer();

            AssertNotNull("GetBusinessLayer", bl);

            IPhotographerModel obj = bl.GetPhotographer(1234);

            AssertNotNull("bl.GetPhotographer", obj);
        }
Example #11
0
 /// <summary>
 /// returns picture based on filter criteria
 /// only namePart relevant - everything else will be ignored
 /// returns all pictures if namePart is null
 /// </summary>
 /// <param name="namePart"></param>
 /// <param name="photographerParts"></param>
 /// <param name="iptcParts"></param>
 /// <param name="exifParts"></param>
 /// <returns></returns>
 public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, BIF.SWE2.Interfaces.Models.IIPTCModel iptcParts, IEXIFModel exifParts)
 {
     if (String.IsNullOrEmpty(namePart))
     {
         return(UnfilteredPictures());
     }
     else
     {
         return(FilteredPictures(namePart));
     }
 }
Example #12
0
 /// <summary>
 /// save photographer model to database
 /// </summary>
 /// <param name="photographer"></param>
 public void Save(IPhotographerModel photographer)
 {
     if (_Photographers.ContainsKey(photographer.ID))
     {
         UpdatePhotographer(photographer);
     }
     else
     {
         InsertPhotograper(photographer);
     }
 }
Example #13
0
 public void Update(IPhotographerModel photographer)
 {
     try
     {
         _dal.Update(photographer);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Example #14
0
 public PhotographerViewModel(IPhotographerModel mdl)
 {
     if (mdl == null)
     {
         return;
     }
     ID        = mdl.ID;
     FirstName = mdl.FirstName;
     LastName  = mdl.LastName;
     BirthDay  = mdl.BirthDay;
     Notes     = mdl.Notes;
 }
Example #15
0
 public PhotographerViewModel(IPhotographerModel photographer)
 {
     if (photographer == null)
     {
         return;
     }
     this.ID        = photographer.ID;
     this.BirthDay  = photographer.BirthDay;
     this.FirstName = photographer.FirstName;
     this.LastName  = photographer.LastName;
     this.Notes     = photographer.Notes;
 }
Example #16
0
        private IPhotographerViewModel GetViewModel()
        {
            IPhotographerModel mdl = ueb.GetEmptyPhotographerModel();

            AssertNotNull("GetEmptyPhotographerModel", mdl);

            IPhotographerViewModel vmdl = ueb.GetPhotographerViewModel(mdl);

            AssertNotNull("GetPhotographerViewModel", vmdl);

            return(vmdl);
        }
Example #17
0
 public override IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts,
                                                         IEXIFModel exifParts)
 {
     if (namePart == "blume")
     {
         return new List <IPictureModel>()
                {
                    new PictureModel()
                }
     }
     ;
     return(_mockPictureModelList);
 }
Example #18
0
 public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts, IEXIFModel exifParts)
 {
     try
     {
         return(_dal.GetPictures(namePart, photographerParts, iptcParts, exifParts));
     }
     catch (Exception e)
     {
         log.Error(e);
         Console.WriteLine(e);
         throw;
     }
 }
Example #19
0
 public void Save(IPhotographerModel photographer)
 {
     try
     {
         _dal.Save(photographer);
     }
     catch (Exception e)
     {
         log.Error(e);
         Console.WriteLine(e.Message);
         throw;
     }
 }
Example #20
0
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            if (String.IsNullOrEmpty(namePart))
            {
                return(PictureList.Values);
            }
            List <IPictureModel> filteredList = new List <IPictureModel>();

            if (namePart == "blume")
            {
                filteredList.Add(new PictureModel());
            }
            return(filteredList);
        }
Example #21
0
        /// <summary>
        /// Returns a filterd list of Pictures from the directory, based on a database query.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts,
                                                       IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            Connect();

            var list    = new List <IPictureModel>();
            var command = new SqlCommand(
                @"SELECT Pictures.ID as picture_id, Filename, Make, FNumber, ExposureTime, ISOValue, Flash, ExposureProgram, Keywords, Caption, ByLine, CopyrightNotice, Headline
                FROM Pictures 
                INNER JOIN EXIF 
                ON Pictures.ID = EXIF.ID
                INNER JOIN IPTC
                ON Pictures.ID = IPTC.ID", Connection);
            var reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    //var EXIF = (string)reader["EXIF"];
                    //var IPTC = (string)reader["IPTC"];
                    list.Add(new PictureModel((string)reader["FileName"])
                    {
                        ID   = (int)reader["picture_id"],
                        EXIF = new EXIFModel()
                        {
                            Make            = (string)reader["Make"],
                            FNumber         = (decimal)reader["FNumber"],
                            ExposureTime    = (decimal)reader["ExposureTime"],
                            ISOValue        = (decimal)reader["ISOValue"],
                            Flash           = (bool)reader["Flash"],
                            ExposureProgram = (ExposurePrograms)reader["ExposureProgram"]
                        },
                        IPTC = new IPTCModel()
                        {
                            Keywords        = (string)reader["Keywords"],
                            ByLine          = (string)reader["ByLine"],
                            Caption         = (string)reader["Caption"],
                            CopyrightNotice = (string)reader["CopyrightNotice"],
                            Headline        = (string)reader["Headline"],
                        }
                    });
                }
            }

            Disconnect();

            return(list);
        }
Example #22
0
        public void bl_should_get_Photographer()
        {
            IBusinessLayer bl = ueb.GetBusinessLayer();

            AssertNotNull("GetBusinessLayer", bl);

            IEnumerable <IPhotographerModel> lst = bl.GetPhotographers();

            AssertNotNull("bl.GetPhotographers", lst);
            AssertTrue("bl.GetPhotographers returned nothing", lst.Count() > 0);

            IPhotographerModel mdl  = lst.First();
            IPhotographerModel test = bl.GetPhotographer(mdl.ID);

            AssertNotNull("bl.GetPhotographer", test);
        }
Example #23
0
        /// <summary>
        /// Check if photographer already exists in db
        /// </summary>
        /// <param name="photographer"></param>
        /// <returns></returns>
        internal bool Exists(IPhotographerModel photographer)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                var cmd = new SqlCommand("SELECT COUNT(*) FROM PhotographerModel WHERE ID = @ID;", connection);

                cmd.Parameters.AddWithValue("@ID", photographer.ID);

                var pCount = (int)cmd.ExecuteScalar();

                connection.Close();

                return(pCount == 1);
            }
        }
Example #24
0
        public void Save(IPhotographerModel photographer)
        {
            if (Photographers.Any(x => x.ID == photographer.ID))
            {
                var apply = Photographers.First(x => x.ID == photographer.ID);
                apply.FirstName = photographer.FirstName;
                apply.LastName  = photographer.LastName;
                apply.BirthDay  = photographer.BirthDay;
                apply.Notes     = photographer.Notes;
            }
            else
            {
                Photographers.Add((PhotographerModel)photographer);
            }

            Task.Run(() => _dal.Save(photographer));
        }
Example #25
0
        /// <summary>
        /// Saves all changes.
        /// </summary>
        /// <param name="photographer"></param>
        public void Save(IPhotographerModel photographer)
        {
            var maxPhotographerId = 1;

            if (_photographerModels.Contains(photographer))
            {
                return;
            }

            _photographerModels.Add(photographer);

            foreach (var _photographer in _photographerModels)
            {
                _photographer.ID   = maxPhotographerId;
                maxPhotographerId += 1;
            }
        }
Example #26
0
        public void mock_dal_should_delete_Photographer()
        {
            IDataAccessLayer dal = ueb.GetDataAccessLayer();

            AssertNotNull("GetDataAccessLayer", dal);

            IEnumerable <IPhotographerModel> lst = dal.GetPhotographers();

            AssertNotNull("dal.GetPhotographers", lst);
            AssertTrue("dal.GetPhotographers returned nothing", lst.Count() > 0);

            IPhotographerModel mdl = lst.First();

            dal.DeletePhotographer(mdl.ID);
            IEnumerable <IPhotographerModel> lst2 = dal.GetPhotographers();

            AssertFalse("Photographer was not deleted", lst2.Contains(mdl));
        }
Example #27
0
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            if (namePart != null && namePart != string.Empty)
            {
                List <IPictureModel> filteredPictures = new List <IPictureModel>();

                foreach (KeyValuePair <int, IPictureModel> item in pictures)
                {
                    if (item.Value.FileName.ToLower().Contains(namePart))
                    {
                        filteredPictures.Add(item.Value);
                    }
                }
                return(filteredPictures);
            }

            return(new List <IPictureModel>(pictures.Values));
        }
Example #28
0
        public void bl_should_save_Photographer_and_set_new_id()
        {
            IBusinessLayer bl = ueb.GetBusinessLayer();

            AssertNotNull("GetBusinessLayer", bl);

            IPhotographerModel obj = ueb.GetEmptyPhotographerModel();

            AssertNotNull("GetEmptyPhotographerModel", obj);

            String firstName = "Michael" + new Random().Next(100);

            obj.FirstName = firstName;
            obj.LastName  = "Testinger";

            bl.Save(obj);

            AssertTrue("obj.ID > 0", obj.ID > 0);
        }
Example #29
0
        public void PhotographerViewModel_should_reflect_Model()
        {
            IPhotographerModel mdl = ueb.GetEmptyPhotographerModel();

            AssertNotNull("GetEmptyPhotographerModel", mdl);

            var dt = DateTime.Today.AddYears(-36);

            mdl.FirstName = "Bernhard";
            mdl.LastName  = "Testinger";
            mdl.BirthDay  = dt;

            IPhotographerViewModel vmdl = ueb.GetPhotographerViewModel(mdl);

            AssertNotNull("GetPhotographerViewModel", vmdl);
            AssertEquals("Bernhard", vmdl.FirstName);
            AssertEquals("Testinger", vmdl.LastName);
            AssertEquals(dt, vmdl.BirthDay);
        }
Example #30
0
        /// <summary>
        /// Returns a filterd list of Pictures from the directory, based on a database query.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts,
                                                       IEXIFModel exifParts)
        {
            List <IPictureModel> pictureModels = new List <IPictureModel>();
            //Alle Filenamen holen die sich im angegebenen Verzeichnis finden
            IEnumerable <string> pathFiles = Directory.EnumerateFiles(_dataAccessLayerFactory.PicturePath);
            //Erstelle eine Liste und füge mit einer foreach Schleife die gefunden Files von pathFiles und füge die einzelnen Elemente der Liste hinzu
            List <string> files = pathFiles.Select(Path.GetFileName).ToList();

            if (string.IsNullOrEmpty(namePart))
            {
                //Alle Pictures ausgeben
                foreach (var pictureFile in files)
                {
                    Save(new PictureModel(pictureFile));
                }

                pictureModels = _pictureModels;
            }
            else
            {
                _pictureModels.Add(new PictureModel("Blume.jpg"));
                //Nach den Pictures suchen die den namen haben
                foreach (var pictureModel in _pictureModels)
                {
                    if (files.Contains(pictureModel.FileName))
                    {
                        continue;
                    }
                    files.Add(pictureModel.FileName);
                }
                //geh alle einträge durch und suche nach übereinstimmungen
                foreach (var pictureFile in files)
                {
                    if (pictureFile.ToUpper().Contains(namePart.ToUpper()))
                    {
                        pictureModels.Add(new PictureModel(pictureFile));
                    }
                }
            }

            return(pictureModels);
        }