コード例 #1
0
        public async Task<bool> Delete(int id)
        {
            ArtPiece artPiece = _context.ArtPieces.Where(p => p.ID == id).FirstOrDefault();
            if (artPiece != null)
            {
                Uri uri = new Uri(artPiece.ImageUri);
                string filename = Path.GetFileName(uri.LocalPath);

                try
                {
                    _context.ArtPieces.Remove(artPiece);
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    if (ex is DbUpdateException || ex is DbUpdateConcurrencyException)
                    {
                        return false;
                    }
                    throw;
                }

                var blob = blobContainer.GetBlockBlobReference(filename);
                await blob.DeleteIfExistsAsync();
                return true;
            }
            return false;
        }
コード例 #2
0
 public bool Update(ArtPiece artPiece)
 {
     try
     {
         _context.ArtPieces.Update(artPiece);
         _context.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         if (ex is DbUpdateException || ex is DbUpdateConcurrencyException)
         {
             return false;
         }
         throw;
     }
 }
コード例 #3
0
ファイル: ArtPieceFactory.cs プロジェクト: pfigiel/UFArt
        public ArtPieceCreationViewModel CreateViewModel(ArtPiece artPiece, ITextAssetsRepository textRepo,
                                                         ITechniqueRepository techniqueRepo, string languageCode, bool success)
        {
            var viewModel = new ArtPieceCreationViewModel(techniqueRepo, textRepo)
            {
                Id             = artPiece.ID,
                Name           = _textRepo.GetTranslatedValue(artPiece.Name, languageCode),
                Dimensions     = artPiece.Dimensions,
                Description    = _textRepo.GetTranslatedValue(artPiece.Description, languageCode),
                Technique      = _textRepo.GetTranslatedValue(artPiece.Technique.Name, languageCode),
                ImageUri       = artPiece.ImageUri,
                ForSale        = artPiece.ForSale,
                CreationDate   = artPiece.CreationDate,
                AdditionalInfo = _textRepo.GetTranslatedValue(artPiece.AdditionalInfo, languageCode),
                Language       = languageCode,
                SuccessFlag    = success
            };

            return(viewModel);
        }
コード例 #4
0
ファイル: ArtPieceFactory.cs プロジェクト: pfigiel/UFArt
        public ArtPiece CreateArtPiece(ArtPieceCreationViewModel viewModel)
        {
            var artPiece  = new ArtPiece();
            var technique = new Technique();

            var nameAsset = new TextAsset()
            {
                Key = "art_piece_name"
            };
            var descriptionAsset = new TextAsset()
            {
                Key = "art_piece_description"
            };
            var additionalInfoAsset = new TextAsset()
            {
                Key = "art_piece_additional_info"
            };

            return(AssignValues(viewModel.Language, nameAsset, descriptionAsset, additionalInfoAsset, technique, viewModel, artPiece));
        }
コード例 #5
0
ファイル: ArtPieceFactory.cs プロジェクト: pfigiel/UFArt
        private ArtPiece AssignValues(string languageCode, TextAsset nameAsset, TextAsset descriptionAsset,
                                      TextAsset additionalInfoAsset, Technique technique, ArtPieceCreationViewModel viewModel, ArtPiece artPiece)
        {
            switch (languageCode)
            {
            case "pl":
                nameAsset.Value_pl           = viewModel.Name;
                descriptionAsset.Value_pl    = viewModel.Description;
                additionalInfoAsset.Value_pl = viewModel.AdditionalInfo;
                technique = _techniqueRepo.Techniques.Where(t => t.Name.Value_pl == viewModel.Technique).FirstOrDefault();
                break;

            case "en":
                nameAsset.Value_en           = viewModel.Name;
                descriptionAsset.Value_en    = viewModel.Description;
                additionalInfoAsset.Value_en = viewModel.AdditionalInfo;
                technique = _techniqueRepo.Techniques.Where(t => t.Name.Value_en == viewModel.Technique).FirstOrDefault();
                break;
            }

            _textRepo.SaveAsset(nameAsset);
            _textRepo.SaveAsset(descriptionAsset);
            _textRepo.SaveAsset(additionalInfoAsset);

            artPiece.AdditionalInfo = additionalInfoAsset;
            artPiece.CreationDate   = viewModel.CreationDate;
            artPiece.Description    = descriptionAsset;
            artPiece.Dimensions     = viewModel.Dimensions;
            artPiece.Technique      = technique;
            artPiece.ImageUri       = viewModel.ImageUri;
            artPiece.ForSale        = viewModel.ForSale;
            artPiece.Name           = nameAsset;

            return(artPiece);
        }