Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("id,FirstName,LastName,EmailAdress,ProductSerial")] Submission submission)
        {
            if (ModelState.IsValid)
            {
                IQueryable <Submission> Submissions = from s in _context.Submission
                                                      where s.ProductSerial == submission.ProductSerial
                                                      select s;
                IQueryable <PurchasedProduct> ValidSerials = from s in _context.PurchasedProduct
                                                             where s.ProductSerial == submission.ProductSerial
                                                             select s;

                if (Submissions.Count() < 2 && ValidSerials.Count() > 0)
                {
                    _context.Add(submission);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("ErrorPage", "Home", new { contentId = 3 }));
                }
            }
            return(View(submission));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,Email,Serial")] DrawEntry drawEntry)
        {
            if (id != drawEntry.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(drawEntry);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DrawEntryExists(drawEntry.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Submissions)));
            }
            return(View(drawEntry));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Number,ReleaseDate")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public async Task SubmissionWithMaxEntries()
        {
            Guid serial = Guid.NewGuid();
            AcmeCorporationContext context    = getInMemDB("MaxEntriesOnOneSerial");
            SubmissionsController  controller = new SubmissionsController(context);

            Submission mock1 = MockSubmission(serial);
            Submission mock2 = MockSubmission(serial);
            Submission mock3 = MockSubmission(serial);

            await context.Submission.AddAsync(mock1);

            await context.Submission.AddAsync(mock2);

            await context.PurchasedProduct.AddAsync(new PurchasedProduct
            {
                ProductSerial = serial
            });

            await context.SaveChangesAsync();

            IActionResult result = await controller.Create(mock3);

            RedirectToActionResult actionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("ErrorPage", actionResult.ActionName);
            Assert.Equal("Home", actionResult.ControllerName);
            Assert.Equal(3, actionResult.RouteValues["contentId"]);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PostDrawEntry([FromForm][Bind("ID,FirstName,LastName,Email,Serial,Age")] DrawEntry drawEntry)
        {
            if (ModelState.IsValid & IsSerialAsync(drawEntry.Serial).Result & drawEntry.Age >= 18)
            {
                _context.DrawEntry.Add(drawEntry);
                await _context.SaveChangesAsync();

                return(StatusCode(201));
            }
            return(StatusCode(400));
        }
        public async Task SubmissionWithNoErrors()
        {
            Guid serial = Guid.NewGuid();
            AcmeCorporationContext context    = getInMemDB("Submit");
            SubmissionsController  controller = new SubmissionsController(context);

            Submission mock  = MockSubmission(serial);
            Submission mock1 = MockSubmission(serial);

            await context.PurchasedProduct.AddAsync(new PurchasedProduct
            {
                ProductSerial = serial
            });

            await context.SaveChangesAsync();

            await controller.Create(mock);

            await controller.Create(mock1);

            Assert.Equal(2, await context.Submission.CountAsync());
        }