예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("FanFictionId,BookTitle,EssayTitle,Comments,ApprovalRating")] FanFiction fanFiction)
        {
            if (id != fanFiction.FanFictionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fanFiction);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FanFictionExists(fanFiction.FanFictionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fanFiction));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("FanFictionId,BookTitle,EssayTitle,Comments,ApprovalRating")] FanFiction fanFiction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(fanFiction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(fanFiction));
        }
예제 #3
0
        public FanFiction CreateFanfic(User user, FanficCreatingInputModel model)
        {
            var fanfic = new FanFiction()
            {
                Author      = user,
                Name        = model.Name,
                Description = model.Description,
                Category    = appDbContext.Categories.Single(c => c.Name == model.Category)
            };

            appDbContext.FanFictions.Add(fanfic);
            appDbContext.SaveChanges();
            return(fanfic);
        }