示例#1
0
        private bool ValidateAlbum(Album album)
        {
            if (string.IsNullOrEmpty(album.Name))
            {
                _validationDictionary.AddError("Name", "Name field is not filled");
            }

            return _validationDictionary.IsValid;
        }
示例#2
0
 public void InsertOrUpdate(Album album)
 {
     if (album.ID == default(int))
     {
         // New entity
         context.Albums.Add(album);
     }
     else
     {
         // Existing entity
         context.Entry(album).State = EntityState.Modified;
     }
 }
示例#3
0
        public bool CreateAlbum(Album newAlbum)
        {
            // Validation logic
            if (!ValidateAlbum(newAlbum))
                return false;

            try
            {
                _repository.InsertOrUpdate(newAlbum);
                _repository.Save();
            }
            catch
            {
                return false;
            }
            return true;
        }