public async Task <IActionResult> CreatePlatform([FromBody] PlatformCreate platformToCreate)
        {
            if (platformToCreate == null)
            {
                throw new ArgumentNullException(nameof(platformToCreate));
            }

            if (!Authorize(platformToCreate))
            {
                return(Unauthorized());
            }

            if (await _context.Platforms.Where(x => x.PlatformName == platformToCreate.PlatformName).AnyAsync())
            {
                return(Ok());
            }

            _context.Platforms.Add(new DbPlatform
            {
                PlatformName = platformToCreate.PlatformName
            });

            await _context.SaveChangesAsync();

            return(Ok());
        }
        public bool CreatePlatform(PlatformCreate model)
        {
            var entity =
                new Platform
            {
                Brand        = model.Brand,
                PlatformName = model.PlatformName,
                ReleaseDate  = model.ReleaseDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Platforms.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #3
0
        public bool CreatePlatform(PlatformCreate model)
        {
            var entity =
                new Platform()
            {
                Title        = model.Title,
                Description  = model.Description,
                Manufacturor = model.Manufacturor,
                ReleaseYear  = model.ReleaseYear
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Platforms.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #4
0
        public ActionResult Create(PlatformCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreatePlatformService();

            if (service.CreatePlatform(model))
            {
                TempData["SaveResult"] = "Your Platform was created.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Ash, you cannot use this item at this time.");

            return(View(model));
        }
        public ActionResult Create(PlatformCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var svc = CreatePlatformService();

            if (svc.CreatePlatform(model))
            {
                TempData["SaveResult"] = "Platform was successfully added to database!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "An error occurred while attempting to add the platform to the database - changes not saved.");
            return(View(model));
        }