Ejemplo n.º 1
0
        public Quote AddQuote(Quote newQuote, IList<int> zanyIds, int userId, IList<byte[]> files)
        {
            Quote quote = context.Quotes.Create();

            quote.AddedOn = newQuote.AddedOn;
            quote.Description = newQuote.Description;
            quote.GameId = newQuote.GameId;
            quote.QuoteText = newQuote.QuoteText;
            quote.UpdatedById = newQuote.UpdatedById;
            quote.UpdatedOn = newQuote.AddedOn; // updated and added dates are the same for creation
            quote.Zanies = zanyRepo.GetZanies(zanyIds);

            if (files != null && files.Count > 0)
            {
                Game quoteGame = gameRepo.GetGame(quote.GameId);

                if (quoteGame != null)
                {
                    newQuote.MediaItems = new List<MediaItem>();

                    // add media items
                    for(int i=0; i < files.Count; i++)
                    {
                        quote.MediaItems.Add(
                            mediaRepo.AddMediaItem(
                                files.ElementAt(i)
                                , this.CreateQuoteMediaFileName(
                                    newQuote.Description
                                    , newQuote.GameId
                                    , ".png"
                                    , i.ToString())
                                , quoteGame.ShortName));
                    }
                }
            }

            context.Quotes.Add(quote);
            context.SaveChanges();

            return quote;
        }
Ejemplo n.º 2
0
        private List<Quote> GetGameQuotes(DirectoryInfo dir, FileInfo titleFile, string gameName)
        {
            List<Quote> retval = new List<Quote>();

            var files = dir.GetFiles()
                                .Where(x => x.FullName.Equals(titleFile.FullName) == false)
                                .Where(x => x.Extension.Equals(".png") || x.Extension.Equals(".jpg") || x.Extension.Equals(".gif"));

            for (int i = 0; i < files.Count(); i++)
            {
                var quote = new Quote();
                string mediaUri = this.UploadMediaFile(files.ElementAt(i), gameName + "_quote" + i, gameName);
                var quoteItem = new MediaItem() { MediaType = MediaTypes.Image, FileUrl = mediaUri };
                quote.MediaItems.Add(quoteItem);

                // init the quote
                quote.ContributorId = 1;

                retval.Add(quote);
            }

            return retval;
        }