Beispiel #1
0
        public async Task <IActionResult> Create(Group model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Whitespace fix
            model.Name = model.Name.Trim();

            if (_context.Groups.Any(g => g.Name.ToLower() == model.Name.ToLower()))
            {
                StatusMessage = $"Error: A group already has this name!";
                return(RedirectToAction("Index", controllerName: "Home"));
            }

            if (_context.ForumCategories.Any(g => g.CategoryID.ToLower() == model.Name.ToLower()))
            {
                StatusMessage = $"Error: A forum Category is already using this name!";
                return(RedirectToAction("Index", controllerName: "Home"));
            }

            if (String.IsNullOrWhiteSpace(model.Owner_Id))
            {
                StatusMessage = $"Error: Owner could not be found! Try again.";
                return(RedirectToAction("Index", controllerName: "Home"));
            }

            model.Api_Key = Guid.NewGuid().ToString();

            _context.Add(model);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(View), new { groupid = model.Id }));
        }