// GET: CompanyPushNotifications/Create public IActionResult Create() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); CompanyPushNotificationViewModel s = new CompanyPushNotificationViewModel(); s.SentAt = DateTime.Now; s.CompanyID = _user.CompanyID; s.UserID = _user.ID; s.SenderName = _user.Name; DataAccessLayer dla = new DataAccessLayer(_context); string deptID = _user.Categories; // Add group checkboxes var listOfAllGroups = dla.GetListGroups(_user.CompanyID); foreach (var seg in listOfAllGroups) { s.AvailableGroups.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add topic checkboxes var listOfAllTopics = dla.GetListTopics(_user.CompanyID); foreach (var seg in listOfAllTopics) { s.AvailableTopics.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add type checkboxes var listOfAllTypeOfUser = dla.GetListTypeOfUser(_user.CompanyID); foreach (var seg in listOfAllTypeOfUser) { s.AvailableTypeOfUser.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add language checkboxes var listOfAllLanguages = dla.GetListLanguages(_user.CompanyID, _rlo); foreach (var seg in listOfAllLanguages) { s.AvailableLanguages.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Get location dropdown data s.Countries = dla.GetCountries(); s.States = dla.GetNullStatesOrCities(); s.Cities = dla.GetNullStatesOrCities(); return(View(s)); }
public async Task <IActionResult> Create(CompanyPushNotificationViewModel cpnVM) { if (ModelState.IsValid) { var cpn = new CompanyPushNotification(); _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); //MessageTitle,MessageBody,MessageType,SentAt,SenderName,Languages,Groups,Topics,TypeOfUser,Country,State,City cpn.MessageTitle = cpnVM.MessageTitle; cpn.MessageType = cpnVM.MessageType; cpn.MessageBody = cpnVM.MessageBody; cpn.SenderName = _user.Name; cpn.SentAt = DateTime.Now; cpn.CompanyID = _user.CompanyID; cpn.UserID = _user.ID; cpn.Languages = string.Join("|", cpnVM.SelectedLanguages); cpn.Groups = string.Join("|", cpnVM.SelectedGroups); cpn.Topics = string.Join("|", cpnVM.SelectedTopics); cpn.TypeOfUser = string.Join("|", cpnVM.SelectedTypeOfUser); if (cpnVM.Country != null && cpnVM.Country != "") { cpn.Country = _context.LocationCountries.FirstOrDefault(m => m.country_code == cpnVM.Country).country_name; } if (cpnVM.State != null && cpnVM.State != "") { cpn.State = _context.LocationStates.FirstOrDefault(n => n.country_code == cpnVM.Country && n.state_code == cpnVM.State).state_name; } cpn.City = cpnVM.City; _context.Add(cpn); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cpnVM)); }