Exemplo n.º 1
0
        public FanFiction UpdateFanfic(User user, FanficCreatingInputModel model)
        {
            var fanfic = appDbContext.FanFictions.Find(model.FanficId);

            fanfic.Name        = model.Name;
            fanfic.Category    = appDbContext.Categories.Single(c => c.Name == model.Category);
            fanfic.Description = model.Description;
            appDbContext.SaveChanges();
            return(fanfic);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateOrEdit(FanficCreatingInputModel model)
        {
            var author = await userManager.FindByNameAsync(User.Identity.Name);

            FanFiction fanfic;

            if (model.IsUpdating)
            {
                fanfic = fanficService.UpdateFanfic(author, model);
            }
            else
            {
                fanfic = fanficService.CreateFanfic(author, model);
            }
            return(Redirect("/Fanfic/CreateOrEditChapter/?fanficId=" + fanfic.Id + "&number=0"));
        }