public async Task <IActionResult> PostCollection([FromBody] CollectionDTO collectionDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var collection = await collectionRepository.Add(collectionDTO);

            if (collection == null)
            {
                return(BadRequest());
            }

            CollectionDTO colDTO = new CollectionDTO();

            colDTO.CollectionId       = collection.CollectionId;
            colDTO.collectionName     = collection.collectionName;
            colDTO.aestheticParameter = collection.aestheticParameter;
            colDTO.products           = new List <ProductDTO>();

            foreach (CollectionProduct cp in collection.CollectionProducts)
            {
                ProductDTO productDTO = productToDTO(cp.Product);
                colDTO.products.Add(productDTO);
            }

            return(CreatedAtAction("PostCollection", colDTO));
        }
        public void User_Can_Add_Collection()
        {
            // Get a userId
            int userId = 1;

            // Create a new collection
            Collection collection = new Collection()
            {
                UserId           = 1,
                CategorizationId = 1,
                Name             = "New stuff",
                Description      = "New lame description.",
                Pinned           = false,
                CreationDate     = DateTime.Now - TimeSpan.FromDays(10)
            };

            // Instantiate CollectionRepo
            var repo = new CollectionRepository(_context);

            // Add collection
            repo.Add(collection);

            // Get new count of all collections
            var count = repo.Get(userId).Count;

            // User with Id 1 should have 3
            Assert.True(count == 3);
        }
        public IActionResult Post(Collection collection)
        {
            collection.CreateDateTime = DateTime.Now;
            var currentUser = GetCurrentUserProfile();

            collection.UserProfileId = currentUser.Id;

            _collectionRepository.Add(collection);
            return(CreatedAtAction(nameof(Get), new { id = collection.Id }, collection));
        }
Esempio n. 4
0
        public async Task TestMerge()
        {
            var repo = new CollectionRepository <Book>();

            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });
            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });
            repo.Add(new Book {
                Id = 0, Title = "Book first."
            });

            var repoB = new CollectionRepository <Book>();

            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });
            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });
            repoB.Add(new Book {
                Id = 0, Title = "Book second."
            });

            var remote = new ObjectRemoteWithWorkSpace <CollectionWorkSpace <Book> >(repo, true, true);
            await remote.AttachAsync(repoB);

            Assert.AreEqual(6, repo.WorkSpace.Count());
            Assert.AreEqual(6, repoB.WorkSpace.Count());
            Assert.AreEqual("Book first.", string.Join(' ', repo.WorkSpace[0].Title));
            Assert.AreEqual("Book second.", string.Join(' ', repoB.WorkSpace[3].Title));

            await Task.Delay(50);

            Assert.AreEqual(6, repo.WorkSpace.Count());
            Assert.AreEqual(6, repoB.WorkSpace.Count());
            Assert.AreEqual("Book first.", string.Join(' ', repo.WorkSpace[0].Title));
            Assert.AreEqual("Book second.", string.Join(' ', repoB.WorkSpace[3].Title));
        }
Esempio n. 5
0
        /// <summary>
        /// The actual Work to be done.
        /// </summary>
        protected override void Execute()
        {
            collection collection = null;

            switch (Request.WellKnownModificationType)
            {
            case Core.Enums.WellKnownModificationType.Add:

                collection = Util.ConvertToCollection(Request.CollectionModel);

                CollectionRepository.Add(collection);
                CollectionRepository.Save();


                SubseryRepository.Add(new subsery()
                {
                    CollectionId  = collection.Id,
                    SubseriesName = "N/A"
                });

                SubseryRepository.Save();

                break;

            case Core.Enums.WellKnownModificationType.Edit:

                collection = CollectionRepository.GetCollecrtionToEdit(Request.CollectionModel.Id);

                collection = Util.ConvertToCollection(collection, Request.CollectionModel);

                CollectionRepository.Edit(collection);
                CollectionRepository.Save();

                break;

            default:
                break;
            }

            Response = new ResponseModel()
            {
                IsOperationSuccess = true
            };
        }
        public void User_Can_Delete_Collection()
        {
            // Get an object that's in the database
            var collectionToAdd = new Collection()
            {
                UserId           = 1,
                CategorizationId = 1,
                Name             = "New Collection to Axe",
                Description      = "Blah",
                Pinned           = false,
                CreationDate     = DateTime.Now - TimeSpan.FromDays(15)
            };

            // Add collectionToAdd to collectionDetailsVm
            var collectionDetails = new CollectionDetailsViewModel
            {
                Collection         = collectionToAdd,
                ProjectCollections = new List <ProjectCollection>(),
                Words = new List <Word>()
            };

            // Instantiate CollectionRepo
            var repo = new CollectionRepository(_context);

            // Get a count of Collections for UserId 1
            var count = repo.Get(1).Count;

            // Add new collection
            repo.Add(collectionToAdd);

            // Get a new count
            var countAfterAdd = repo.Get(1).Count;

            // Attempt to delete the collection
            repo.Delete(collectionDetails);

            // New count after deleting
            var countAfterDeletion = repo.Get(1).Count;

            // We successfully added one collection
            Assert.True(count < countAfterAdd);
            // We successfully deleted one collection
            Assert.True(count == countAfterDeletion);
        }