コード例 #1
0
        public ActionResult CreateManual(CreateManualViewModel model)
        {
            Manual manual = new Manual()
            {
                AuthorId    = model.AuthorId,
                Title       = mark.Transform(model.Title),
                Description = mark.Transform(model.Description),
                Photo       = model.Photo,
                Category    = model.Category,
                ReleaseDate = DateTime.Today,
                LastUpdate  = DateTime.Today
            };
            EntityEntry <Manual> e = context.Manuals.Add(manual);

            context.SaveChanges();
            Manual i = e.Entity;

            string[] tags = model.Tags.Split(',');
            foreach (string t in tags)
            {
                Tag fTag = null;

                if (context.Tags.Where(dt => dt.Name == t).ToList().Count != 0)
                {
                    fTag = context.Tags.Where(dt => dt.Name == t).ToList().First();
                }

                if (fTag != null)
                {
                    context.ManualTags.Add(new ManualTag()
                    {
                        TagId = fTag.TagId, ManualId = i.ManualId
                    });
                }
                else
                {
                    EntityEntry <Tag> added = context.Tags.Add(new Tag()
                    {
                        Name = t
                    });
                    context.SaveChanges();
                    Tag aTag = added.Entity;
                    context.ManualTags.Add(new ManualTag()
                    {
                        TagId = aTag.TagId, ManualId = i.ManualId
                    });
                }
            }
            context.SaveChanges();
            CreateViewModel newModel = new CreateViewModel()
            {
                Manual   = i,
                AuthorId = i.AuthorId,
                Tags     = tags.ToList(),
                Steps    = new List <Step>()
            };

            return(View("Create", newModel));
        }
コード例 #2
0
        public async Task <IActionResult> Create(CreateManualViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var room = await _context.Manuals.FirstOrDefaultAsync(u =>
                                                                      u.Title == model.Title &&
                                                                      u.UserCreator == _userManager.GetUserName(HttpContext.User));

                //TODO BUG IF Title null fix please
                if (room == null && model.Title != null)
                {
                    var manual = new Manual
                    {
                        Themes           = model.Themes,
                        Tags             = model.Tags,
                        Body             = model.Content,
                        Title            = model.Title,
                        ShortDescription = model.ShortDescription,
                        CreatedDate      = DateTime.Now,
                        UserCreator      = _userManager.GetUserName(HttpContext.User),
                        ManualImage      = model.Image
                    };

                    var user = await _userManager.GetUserAsync(User);

                    await _context.Manuals.AddAsync(manual);

                    user.Manuals = ConcatManuals(user.Manuals, manual.Title);
                    await _context.SaveChangesAsync();

                    _logger.LogInformation($"User {manual.UserCreator} created a new manual.");
                    return(RedirectToAction("Index", "Manual"));
                }
                else
                {
                    ModelState.AddModelError("", "Sorry, you already created such a manual");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
 public Task <IActionResult> EditSaveChange(CreateManualViewModel model, string returnUrl = null)
 {
     return(null);
 }