public async Task <IActionResult> Create([Bind("Id,Name,Private,GroupCategory,IconPath")] GroupDescription groupDescription) { if (ModelState.IsValid) { _db.Create(groupDescription); _db.Save(); return(RedirectToAction(nameof(Index))); } ViewData["GroupCategory"] = new SelectList(_db.GetCategories(), "Id", "Name", groupDescription.GroupCategory); return(View(groupDescription)); }
public async Task <bool> CreateGroup(GroupModel group, string email) { var some_group = _groupRepo.GetElementByName(group.Name); if (some_group == null) { string path; if (group.Image != null) // Файл загружен { string expansion = group.Image.FileName.Substring(group.Image.FileName.LastIndexOf(".")); path = "/img/group_icons/" + Guid.NewGuid() + expansion; using (var fileStream = new FileStream(_appEnviron.WebRootPath + path, FileMode.Create)) { await group.Image.CopyToAsync(fileStream); } } else { path = "/img/group_icons/default_image.png"; // Ставится стоковое изображение } // Создаётся группа _groupRepo.Create(new GroupDescription { Name = group.Name, Private = group.Private, IconPath = path }); _groupRepo.Save(); // Создание связи _participationRepo.Create(new Participation { GroupId = _groupRepo.GetElementByName(group.Name).Id, UserId = _userRepo.GetElementByEmail(email).Id, Role = 2 });; _participationRepo.Save(); return(true); } else { return(false); } }