public async Task <IActionResult> Create(GroupCreateViewModel groupCreateViewModel) { if (ModelState.IsValid) { //Create Group _context.Groups.Add(groupCreateViewModel.Group); await _context.SaveChangesAsync(); //Create Group-Categories relations Group newGroupCreated = await _context.Groups.Where(g => g.Name == groupCreateViewModel.Group.Name).FirstOrDefaultAsync(); foreach (int idCategoryGroup in groupCreateViewModel.GroupCategories) { Group_GroupCategory groupCategories = new Group_GroupCategory { GroupId = newGroupCreated.Id, GroupCategoryId = idCategoryGroup }; _context.Group_GroupCategories.Add(groupCategories); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(groupCreateViewModel)); }
public ActionResult Create(GroupCreateViewModel model) //public ActionResult Create([Bind(Include = "Id,UserId,GroupId")] UserToGroup userToGroup) { if (ModelState.IsValid) { var newGroup = new Group { Name = model.Group.Name }; var newUserToGroup = new UserToGroup { UserId = model.CurrentUserId, GroupId = newGroup.Id, AcceptedInvite = true }; var newGroupToEvent = new GroupToEvents { GroupId = newGroup.Id, EventId = model.Event.Id }; db.Groups.Add(newGroup); db.UserToGroups.Add(newUserToGroup); db.GroupToEvents.Add(newGroupToEvent); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GroupId = new SelectList(db.Groups, "Id", "Name"); ViewBag.EventId = new SelectList(db.Events, "Id", "Name"); return(View()); }
public async Task <IActionResult> Create(GroupCreateViewModel group) { int newGroupId; string userSignedIn; if (!ModelState.IsValid) { return(View(group)); } using (var dbContextTransaction = _context.Database.BeginTransaction()) { try { await CreatesNewGroup(group); newGroupId = await CreatesGroupCategories(group); userSignedIn = await CreatesCoordinatorUserByDefault(newGroupId); await _context.SaveChangesAsync(); dbContextTransaction.Commit(); await _azureBlobManager.UploadFile(group.GroupImage, newGroupId + "/groupimage/"); await SendNewGroupMessageToEventQueue(newGroupId, group); return(RedirectToAction("Index", "Groups", new { userId = userSignedIn })); } catch (Exception e) { dbContextTransaction.Rollback(); _logger.LogError($"EXCEPCIÓN: {e.Message}"); return(View(group)); } } }
public ActionResult Create(GroupCreateViewModel model) { if (ModelState.IsValid) { try { var id = User.Identity.GetUserId(); ObjectId oId = new ObjectId(id); Group group = new Group { Creator = oId, Description = model.Description, CreationTime = DateTime.Now, Name = model.Name, Members = new Dictionary <MongoDB.Bson.ObjectId, GroupPermissionType>() { { oId, GroupPermissionType.Owner } } }; _groupManager.AddGroup(group); return(RedirectToAction("Index", "Home")); } catch (Exception) { return(RedirectToAction("Index", "Home")); } } else { return(View()); } }
//GET: Create public ActionResult Create() { var groupCreateModel = new GroupCreateViewModel(); groupCreateModel.Members = new List <string>(); return(View(groupCreateModel)); }
// GET: Attendee/Create public ActionResult Create() { GroupCreateViewModel groupCreateModel = new GroupCreateViewModel(); groupCreateModel.CurrentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); groupCreateModel.Events = new SelectList(db.Events, "Id", "Name"); return(View(groupCreateModel)); }
public async Task <IActionResult> Create() { GroupCreateViewModel model = new GroupCreateViewModel { GroupCategoriesSelected = new List <int> { 1 }, GroupCategoriesList = GetGroupCategories() }; return(View(model)); }
public ActionResult Create(GroupCreateViewModel model) { if (ModelState.IsValid) { if (Facade.CreateGroup(User.Identity.GetUserId(), model.Name)) { TempData["message"] = string.Format("Group was created successfully!"); return(RedirectToAction("Index")); } } TempData["message"] = string.Format("Creation failed!"); return(View(model)); }
private async Task <int> CreatesGroupCategories(GroupCreateViewModel group) { int newGroupId = (await _context.Groups.FirstOrDefaultAsync(g => g.Name == group.GroupInfo.Name)).Id; foreach (int categorySelected in group.GroupCategoriesSelected) { _context.Group_GroupCategories.Add(new Group_GroupCategory() { GroupId = newGroupId, GroupCategoryId = categorySelected }); } return(newGroupId); }
public IActionResult Post(GroupCreateViewModel model) { if (this.ModelState.IsValid) { Group group = model.ToEntity(); var repo = this.Storage.GetRepository <IGroupRepository>(); repo.Create(group, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = true })); } return(BadRequest(new { success = false })); }
private async Task CreatesNewGroup(GroupCreateViewModel group) { Group newGroup = new Group { Name = group.GroupInfo.Name, AboutUs = group.GroupInfo.AboutUs, City = group.GroupInfo.City, Country = group.GroupInfo.Country, CreationDate = DateTime.Now, }; _context.Groups.Add(newGroup); await _context.SaveChangesAsync(); }
private async Task SendNewGroupMessageToEventQueue(int newGroupId, GroupCreateViewModel group) { StringBuilder groupCategories = new StringBuilder(); foreach (int groupCategory in group.GroupCategoriesSelected) { groupCategories.Append(";" + groupCategory); } string newGroupDetailsURI = HttpContext.Request.GetDisplayUrl().Replace("Create", $"Details/{newGroupId}"); string message = $"{EventQueueMessages.GROUP_CREATED};{newGroupId};{newGroupDetailsURI}{groupCategories.ToString()}"; await _eventQueueService.SendMessageAsync(message); var dictionay = new Dictionary <string, string>(); dictionay.Add("Queue Message", message); _telemetryClient.TrackEvent("UserInteraction", dictionay); }
public ActionResult Create([Bind(Include = "GroupName,GroupImage,Members")] GroupCreateViewModel groupCreateModel) { if (ModelState.IsValid) { var group = new Group() { Members = new List <ApplicationUser>() }; group.GroupName = groupCreateModel.GroupName; //adding current user to the group var user = db.Users.Find(User.Identity.GetUserId()); //var user = UserManager.FindById(User.Identity.GetUserId()); group.Members.Add(user); //adding all provided users to the group foreach (var email in groupCreateModel.Members) { var member = db.Users.Where(m => m.Email == email).SingleOrDefault(); //var member = UserManager.FindByEmail(email); if (member == null) { ModelState.AddModelError("InvalidUser", "Users with such email don't exist"); return(View(groupCreateModel)); } group.Members.Add(member); } if (groupCreateModel.GroupImage != null) { //Creating filename and path for a picture string pic = System.IO.Path.GetFileName(groupCreateModel.GroupImage.FileName); string path = System.IO.Path.Combine(Server.MapPath("/Assets/Images/GroupPics/"), pic); //saving image on a server and adding path to db groupCreateModel.GroupImage.SaveAs(path); group.GroupImage = "/Assets/Images/GroupPics/" + pic; } db.Groups.Add(group); db.SaveChanges(); return(RedirectToAction("Groups")); } return(View(groupCreateModel)); }
public IActionResult CreateGroup(GroupCreateViewModel input) { var context = new OnlineWebPortalDbContext(); ChurchGroup group = new ChurchGroup(); if (ModelState.IsValid && (input.GroupName != null)) { group.GroupName = input.GroupName; group.GroupDescription = input.GroupDescription; group.MeetingDay = input.MeetingDay; group.StartTime = input.StartTime; group.EndTime = input.EndTime; group.Location = input.Location; group.LeaderName = input.LeaderName; group.LeaderProfile = input.LeaderProfile; context.Add(group); context.SaveChanges(); return(RedirectToAction("FindGroup", "Group")); } return(View()); }
public ActionResult Create(GroupCreateViewModel model) { if (ModelState.IsValid) { var result = groupService.Add(new GroupModel { Name = model.Name, Description = model.Description }, CurrentUserId); if (result) { return(RedirectToAction("Index", "Group")); } else { ModelState.AddModelError("", "Group creation failed"); } } return(View(model)); }
// GET: Groups/Create public ActionResult Create() { GroupCreateViewModel model = new GroupCreateViewModel(); return(View(model)); }
public CreateGroupPageView() : base() { NewGroup = new GroupCreateViewModel(); }