public ActionResult Create(string eventName) { var url = EntityNameHelper.CreateUrl(eventName, true); var existing = DataRepository.GetEvent(url, loadExtended: false); if (eventName.IsNullOrWhiteSpace()) { ModelState.AddModelError("NoName", "No event name was entered"); } // no event exists, create a new one else if (existing == null) { DataRepository.CreateEvent(new EventModel { Name = eventName, UrlName = url }, loggedUserGuid); return(RedirectToRoute("myevents", new { action = "edit", eventName = url })); } else { ModelState.AddModelError("EventExists", "This event already exists"); } var events = DataRepository.GetEventsByUser(loggedUserGuid); return(View("list", events)); }
public ActionResult EditPost(BandModel m, IEnumerable <string> genres, Guid bandId) { var model = DataRepository.GetBand(bandId); if (ModelState.IsValid) { var oldUrl = model.UrlName; var newUrl = EntityNameHelper.CreateUrl(m.Name); m.UrlName = newUrl; m.BandId = model.BandId; var selectedGenres = genres.Where(g => g != "false").Select(g => new Guid(g)); DataRepository.UpdateBand(m); DataRepository.UpdateBandGenres(m.BandId, selectedGenres); DataRepository.AddFeedItem("{0} has updated their band profile.", 2, model.BandId); // notification Notifications.SendBandNotifications(NotificationType.NotifyBandProfileUpdate, model.BandId, new BandMessageData { Band = model.Name, Link = model.UrlName }); } return(JsonValidationResult(ModelState)); }
public ActionResult CreateBand(string bandName) { if (!String.IsNullOrWhiteSpace(bandName)) { var band = DataRepository.GetBand(bandName, false); if (band == null) { var bandUrl = EntityNameHelper.CreateUrl(bandName); var guid = Guid.NewGuid(); BandModel newBand = new BandModel() { BandId = guid, UrlName = bandUrl, Name = bandName, Date = DateTime.Now }; DataRepository.CreateBand(newBand, loggedUserGuid); DataRepository.AddFeedItem("{0} has created their band profile!", 2, guid); return(RedirectToRoute("MyBands", new { action = "edit", bandUrl = bandUrl })); } else { ModelState.AddModelError("BandExists", "This band already exists."); return(View("Join")); } } return(RedirectToRoute("join")); }
public ActionResult EditPost(EditEventModel m, string eventName, string letter) { var model = CreateModel(eventName, letter); if (ModelState.IsValid) { var oldUrl = model.Event.UrlName; var newUrl = EntityNameHelper.CreateUrl(m.Event.Name); var eventModel = m.Event; eventModel.EventId = model.Event.EventId; //eventModel.UrlName = newUrl; DataRepository.UpdateEvent(eventModel); if (model.Event.Date >= DateTime.Now && model.Event.Bands.Any()) { // for each band on the event model.Event.Bands.ToList().ForEach(b => { DataRepository.AddFeedItem("Event page for {0} has been updated.", 3, b.Band.BandId, eventId: model.Event.EventId); }); } // send notification, adding the list of bands for the event Notifications.SendEventNotifications(NotificationType.NotifyEventUpdated, model.Event.EventId, new EventMessageData { Event = m.Event.Name, Link = model.Event.UrlName, Bands = model.Event.Bands.Select(b => b.Band.Name).ToString("<br />") }); //if (oldUrl != newUrl) //{ // return JsonValidationResult(ModelState, Url.RouteUrl("myevents", new { action = "edit", eventName = newUrl })); //} } return(JsonValidationResult(ModelState)); }
public ActionResult GalleryPost(string galleryName, GalleryModel m) { var model = DataRepository.GetGallery(galleryName); if (ModelState.IsValid) { var oldUrl = model.UrlName; var newUrl = EntityNameHelper.CreateUrl(m.Name); model.UrlName = newUrl; model.Description = m.Description; model.Name = m.Name; model.BandId = m.BandId; newUrl = DataRepository.UpdateGallery(model); if (oldUrl != newUrl) { return(Json(new { success = true, redirect = Url.RouteUrl("myimages", new { action = "gallery", galleryName = newUrl }) })); } } return(Json(new { success = true })); }
public ActionResult SignUpPost(SignUpModel m) { // check city/state if (!m.City.IsNullOrWhiteSpace() && m.State.Name.IsNullOrWhiteSpace()) { ModelState.AddModelError("CityNoState", "If entering a city, please select your state."); } if (ModelState.IsValid) { using (var ctx = new OpenGroovesEntities()) { m.Email = m.Email.Trim(); bool hasBand = !m.BandName.IsNullOrWhiteSpace(); MembershipCreateStatus status; var username = EntityNameHelper.CreateUrl(m.Email); // check for email if (Membership.FindUsersByEmail(m.Email).Count > 0 || Membership.FindUsersByName(username).Count > 0) { ModelState.AddModelError("EmailExists", "This email address is already registered"); } // check for band name if (hasBand && ctx.Bands.Any(b => b.Name == m.BandName.Trim())) { ModelState.AddModelError("BandExists", String.Format("The band, \"{0}\", has already registered. But don't worry, you can leave this field blank and request to join this band later.", m.BandName)); ModelState.AddModelError("BandExistsHelp", "If this is in error, please contact [email protected]."); m.BandName = String.Empty; } // if we're here, we're good to go! if (ModelState.IsValid) { var user = Membership.CreateUser(username, "thisisafakepassword", m.Email, null, null, false, out status); // if membership create is good if (status == MembershipCreateStatus.Success) { var guid = (Guid)user.ProviderUserKey; var existingUser = ctx.Users.SingleOrDefault(u => u.Email == m.Email); existingUser.RealName = m.RealName; existingUser.Email = m.Email; existingUser.SetupRequired = true; var relation = new UsersBand { RelationId = Guid.NewGuid(), RelationTypeId = 1, Date = DateTime.Now }; if (!m.City.IsNullOrWhiteSpace() && !m.State.Name.IsNullOrWhiteSpace()) { existingUser.City = m.City; existingUser.State = m.State.Name; } var address = LocationHelper.CityStateOrZip(m.City, m.State.Name); var location = ObjectFactory.GetInstance <ILocationService>(); var loc = location.GetLocation(address); if (loc != null) { existingUser.Latitude = loc.Coordinate.Latitude; existingUser.Longitude = loc.Coordinate.Longitude; existingUser.State = loc.State; existingUser.City = loc.City; } if (hasBand) { var band = new Band { BandId = Guid.NewGuid(), Name = m.BandName, City = m.City, Searchable = EntityNameHelper.StripUselessWords(m.BandName), State = m.State.Name, UrlName = Core.Helpers.EntityNameHelper.CreateUrl(m.BandName), Date = DateTime.Now }; if (loc != null) { band.Latitude = loc.Coordinate.Latitude; band.Longitude = loc.Coordinate.Longitude; band.City = loc.City; band.State = loc.State; } relation.Band = band; existingUser.UsersBands.Add(relation); } ctx.SaveChanges(); NotifyNewSignup(m); return(View("ThankYou", m)); } else if (status == MembershipCreateStatus.DuplicateEmail) { ModelState.AddModelError("DupEmail", "This email address already exists."); } else { ModelState.AddModelError("OtherError", "Your account could not be created."); } } } } return(View(m)); }