Пример #1
0
 public ResultImageModel(ImageInCard img)
 {
     ImageId  = img.ImageId;
     Name     = img.Image.Name;
     Source   = img.Image.Source;
     CardSide = img.CardSide;
 }
Пример #2
0
 public ResultImageModel(ImageInCard img)
 {
     ImageId     = img.ImageId;
     Owner       = img.Image.Owner;
     Name        = img.Image.Name;
     Description = img.Image.Description;
     Source      = img.Image.Source;
     CardSide    = img.CardSide;
 }
Пример #3
0
        private async Task AddImageAsync(Guid cardId, Guid imageId, int cardSide, List <ImageInCard> cardImageList)
        {
            var imageFromDb = dbContext.Images.Where(img => img.Id == imageId).Single();    //To be reviewed: it sounds stupid that we have to load the whole image info, with the blob, while we only need an id???
            var img         = new ImageInCard()
            {
                ImageId = imageId, Image = imageFromDb, CardId = cardId, CardSide = cardSide
            };
            await dbContext.ImagesInCards.AddAsync(img);

            cardImageList.Add(img);
        }
Пример #4
0
        private void AddImage(Guid cardId, Guid imageId, int cardSide, List <ImageInCard> cardImageList)
        {
            var imageFromDb = DbContext.Images.Where(img => img.Id == imageId).Single();
            var img         = new ImageInCard()
            {
                ImageId = imageId, Image = imageFromDb, CardId = cardId, CardSide = cardSide
            };

            DbContext.ImagesInCards.Add(img);
            cardImageList.Add(img);
        }
Пример #5
0
        public static async Task <Card> CreateAsync(DbContextOptions <MemCheckDbContext> testDB,
                                                    Guid versionCreatorId, DateTime?versionDate = null, IEnumerable <Guid>?userWithViewIds = null, Guid?language = null, IEnumerable <Guid>?tagIds = null,
                                                    string?frontSide = null, string?backSide = null, string?additionalInfo = null,
                                                    IEnumerable <Guid>?frontSideImages = null, IEnumerable <Guid>?additionalSideImages = null,
                                                    string?versionDescription          = null)
        {
            //userWithViewIds null means public card

            using var dbContext = new MemCheckDbContext(testDB);
            var creator = await dbContext.Users.Where(u => u.Id == versionCreatorId).SingleAsync();

            var result = new Card
            {
                VersionCreator     = creator,
                FrontSide          = frontSide ?? RandomHelper.String(),
                BackSide           = backSide ?? RandomHelper.String(),
                AdditionalInfo     = additionalInfo ?? RandomHelper.String(),
                VersionDescription = versionDescription ?? RandomHelper.String(),
                VersionType        = CardVersionType.Creation
            };

            if (language == null)
            {
                language = await CardLanguagHelper.CreateAsync(testDB);
            }
            result.CardLanguage = await dbContext.CardLanguages.SingleAsync(l => l.Id == language);

            if (versionDate != null)
            {
                result.InitialCreationUtcDate = versionDate.Value;
                result.VersionUtcDate         = versionDate.Value;
            }
            dbContext.Cards.Add(result);

            var usersWithView = new List <UserWithViewOnCard>();

            if (userWithViewIds != null && userWithViewIds.Any())
            {
                Assert.IsTrue(userWithViewIds.Any(id => id == versionCreatorId), "Version creator must be allowed to view");
                foreach (var userWithViewId in userWithViewIds)
                {
                    var userWithView = new UserWithViewOnCard {
                        CardId = result.Id, UserId = userWithViewId
                    };
                    dbContext.UsersWithViewOnCards.Add(userWithView);
                    usersWithView.Add(userWithView);
                }
            }
            result.UsersWithView = usersWithView;

            var tags = new List <TagInCard>();

            if (tagIds != null)
            {
                foreach (var tagId in tagIds)
                {
                    var tagInCard = new TagInCard
                    {
                        CardId = result.Id,
                        TagId  = tagId
                    };
                    dbContext.TagsInCards.Add(tagInCard);
                    tags.Add(tagInCard);
                }
            }
            result.TagsInCards = tags;

            var images = new List <ImageInCard>();

            if (frontSideImages != null)
            {
                foreach (var frontSideImage in frontSideImages)
                {
                    var img = new ImageInCard()
                    {
                        ImageId = frontSideImage, CardId = result.Id, CardSide = ImageInCard.FrontSide
                    };
                    dbContext.ImagesInCards.Add(img);
                    images.Add(img);
                }
            }
            if (additionalSideImages != null)
            {
                foreach (var additionalSideImage in additionalSideImages)
                {
                    var img = new ImageInCard()
                    {
                        ImageId = additionalSideImage, CardId = result.Id, CardSide = ImageInCard.AdditionalInfo
                    };
                    dbContext.ImagesInCards.Add(img);
                    images.Add(img);
                }
            }
            result.Images = images;

            await dbContext.SaveChangesAsync();

            return(result);
        }