コード例 #1
0
        public async Task <IActionResult> Edit(string id, RecordEditInputModel recordEditInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                var allGenres = await this.recordService.GetAllGenres().ToListAsync();

                this.ViewData["types"] = allGenres.Select(genre => new GenreCreateViewModel
                {
                    Name = genre.Name
                })
                                         .ToList();

                return(this.View(recordEditInputModel));
            }

            string pictureUrl = await this.cloudinaryService.UploadPictureAsync(recordEditInputModel.Picture, recordEditInputModel.AlbumName);

            RecordServiceModel recordCreate = AutoMapper.Mapper.Map <RecordServiceModel>(recordEditInputModel);

            recordCreate.Picture = pictureUrl;

            await this.recordService.Edit(id, recordCreate);

            return(this.Redirect("/"));
        }
コード例 #2
0
        public async Task Edit_WithCorrectData_ShouldEditProductCorrectly()
        {
            string errorMessagePrefix = "RecordService Edit() method does not work properly.";

            var context = ContextFactory.Initializer();

            await SeedData(context);

            this.recordService = new RecordService(context);

            RecordServiceModel expectedResult = context.Records.First().To <RecordServiceModel>();

            expectedResult.AlbumName    = "Editted_Name";
            expectedResult.Price        = 0.01M;
            expectedResult.DateProduced = DateTime.UtcNow;
            expectedResult.Picture      = "Editted_Picture";
            expectedResult.Genre        = context.Genres.Last().To <GenreServiceModel>();

            await this.recordService.Edit(expectedResult.Id, expectedResult);

            RecordServiceModel actualResult = context.Records.First().To <RecordServiceModel>();

            Assert.True(actualResult.AlbumName == expectedResult.AlbumName, errorMessagePrefix + " " + "AlbumName not editted properly.");
            Assert.True(actualResult.Price == expectedResult.Price, errorMessagePrefix + " " + "Price not editted properly.");
            Assert.True(actualResult.DateProduced == expectedResult.DateProduced, errorMessagePrefix + " " + "Manufactured On not editted properly.");
            Assert.True(actualResult.Picture == expectedResult.Picture, errorMessagePrefix + " " + "Picture not editted properly.");
            Assert.True(actualResult.Genre.Name == expectedResult.Genre.Name, errorMessagePrefix + " " + "Genre not editted properly.");
        }
コード例 #3
0
        public async Task Create_ShouldSuccessfullyCreateRecord()
        {
            string errorMessage = "RecordService Create() method does not work properly.";

            var context = ContextFactory.Initializer();

            await SeedData(context);

            this.recordService = new RecordService(context);

            RecordServiceModel testrecord = new RecordServiceModel
            {
                AlbumName    = "Indestructable",
                Artist       = "Disturbed",
                Price        = 45,
                DateProduced = DateTime.UtcNow,
                Picture      = "fake/pic",
                Genre        = new GenreServiceModel
                {
                    Name = "Metal"
                },
                Description = "Inside the fire"
            };

            bool actualResult = await this.recordService.Create(testrecord);

            Assert.True(actualResult, errorMessage);
        }
コード例 #4
0
        public async Task GetById_WithNonExistentId_ShouldReturnNull()
        {
            string errorMessage = "RecordService GetById() method does not work properly.";

            var context = ContextFactory.Initializer();

            await SeedData(context);

            this.recordService = new RecordService(context);

            RecordServiceModel actualData = await this.recordService.GetById("fakeIDd");

            Assert.True(actualData == null, errorMessage);
        }
コード例 #5
0
ファイル: RecordService.cs プロジェクト: Khin22/Final-Project
        public async Task <bool> Create(RecordServiceModel recordServiceModel)
        {
            Genre GenreFromDb =
                finalWebProjectDbContext.Genres
                .SingleOrDefault(productType => productType.Name == recordServiceModel.Genre.Name);

            Record record = AutoMapper.Mapper.Map <Record>(recordServiceModel);

            record.Genre = GenreFromDb;

            finalWebProjectDbContext.Records.Add(record);
            int result = await finalWebProjectDbContext.SaveChangesAsync();

            return(result > 0);
        }
コード例 #6
0
        public async Task Edit_ShouldPassSuccessfully()
        {
            string errorMessage = "ProductService Edit() method does not work properly.";

            var context = ContextFactory.Initializer();

            await SeedData(context);

            this.recordService = new RecordService(context);

            RecordServiceModel expectedResult = context.Records.First().To <RecordServiceModel>();

            bool actualResult = await this.recordService.Edit(expectedResult.Id, expectedResult);

            Assert.True(actualResult, errorMessage);
        }
コード例 #7
0
        public async Task GetById_Existing_ShouldReturnCorrectResult()
        {
            string errorMessage = "RecordService GetById() method does not work properly.";

            var context = ContextFactory.Initializer();

            await SeedData(context);

            this.recordService = new RecordService(context);

            RecordServiceModel expectedResults = context.Records.First().To <RecordServiceModel>();
            RecordServiceModel actualResult    = await this.recordService.GetById(expectedResults.Id);

            Assert.True(expectedResults.Id == actualResult.Id, errorMessage + " " + "Id is not returned properly.");
            Assert.True(expectedResults.AlbumName == actualResult.AlbumName, errorMessage + " " + "AlbumName is not returned properly.");
            Assert.True(expectedResults.Price == actualResult.Price, errorMessage + " " + "Price is not returned properly.");
            Assert.True(expectedResults.Picture == actualResult.Picture, errorMessage + " " + "Picture is not returned properly.");
            Assert.True(expectedResults.Genre.Name == actualResult.Genre.Name, errorMessage + " " + "Genre is not returned properly.");
        }
コード例 #8
0
ファイル: RecordService.cs プロジェクト: Khin22/Final-Project
        public async Task <bool> Edit(string id, RecordServiceModel recordServiceModel)
        {
            Genre GenreFromDb =
                finalWebProjectDbContext.Genres
                .SingleOrDefault(productType => productType.Name == recordServiceModel.Genre.Name);

            Record record = await this.finalWebProjectDbContext.Records.SingleOrDefaultAsync(records => records.Id == id);

            record.AlbumName    = recordServiceModel.AlbumName;
            record.Artist       = recordServiceModel.Artist;
            record.DateProduced = recordServiceModel.DateProduced;
            record.Price        = recordServiceModel.Price;
            record.Picture      = recordServiceModel.Picture;
            record.Quantity     = recordServiceModel.Quantity;
            record.Description  = recordServiceModel.Description;

            record.Genre = GenreFromDb;

            this.finalWebProjectDbContext.Records.Update(record);
            int result = await finalWebProjectDbContext.SaveChangesAsync();

            return(result > 0);
        }