public async Task <IActionResult> GetAllBands() { var bands = _bandsRepository.GetAllEntities(); var model = bands.Select(b => BandViewModel.FromBand(b)); return(Ok(model)); }
public async Task <IActionResult> GetMostPopular() { var toprated = _bandsRepository.GetTopRated(); var model = toprated.Select(b => BandViewModel.FromBand(b)); return(Ok(model)); }
public async Task <IActionResult> GetBandById([FromRoute] int id) { var band = _bandsRepository.GetEntityById(id); var model = BandViewModel.FromBand(band); return(Ok(model)); }
private List <string> GetEmails(BandViewModel band) { List <string> bandList = new List <string>(); if (CheckForNullString(band.Email_2)) { bandList.Add(band.Email_2); } if (CheckForNullString(band.Email_3)) { bandList.Add(band.Email_3); } if (CheckForNullString(band.Email_4)) { bandList.Add(band.Email_4); } if (CheckForNullString(band.Email_5)) { bandList.Add(band.Email_5); } if (CheckForNullString(band.Email_6)) { bandList.Add(band.Email_6); } return(bandList); }
public ActionResult Details(int id) { var band = _context.Bands.SingleOrDefault(b => b.Id == id); var member = _context.Members.Where(b => b.BandId == id).ToList(); var schedules = _context.EventSchedules.Where(e => e.BandId == id).ToList(); List <int> eventIds = new List <int>(); foreach (var scheduleObj in schedules) { eventIds.Add(scheduleObj.EventId); } var events = _context.Events.Where(e => eventIds.Contains(e.Id)).ToList(); //var eve = _context.Events.SingleOrDefault(e => e.Id == id); //var schedule = _context.EventSchedules.Include(e => e.Event).Where(e => e.BandId == id).ToList(); var viewModel = new BandViewModel { Band = band, Members = member, Events = events, //EventSchedule=Schedule is not call beacause Eventschedule bata event liyesakyo n now events call }; return(View(viewModel)); }
public IActionResult Put(int id, [FromForm] BandViewModel model) { var existingBand = _bandRepository.Get(id); if (existingBand == null) { return(NotFound()); } existingBand.Name = model.Name; existingBand.DescriptionDe = model.DescriptionDe; existingBand.DescriptionFr = model.DescriptionFr; existingBand.Name = model.Name; existingBand.SpotifyPlaylist = model.SpotifyPlaylist; existingBand.YoutubeUrls = model.YoutubeUrls; existingBand.Order = model.Order ?? existingBand.Order; existingBand.Facebook = model.Facebook; existingBand.Instagram = model.Instagram; existingBand.PlayTime = model.PlayTime; existingBand.Stage = model.Stage; existingBand.PlayTimeForSorting = model.PlayTimeForSorting; existingBand.WebSiteUrl = model.WebSiteUrl; SafeBandImages(model, existingBand); _bandRepository.Update(existingBand); return(NoContent()); }
private void SafeBandImages(BandViewModel model, Band band) { if (model.ImageThumbnail != null) { string filename = band.Id + Path.GetExtension(model.ImageThumbnail.FileName); _fileUtility.SaveImage(model.ImageThumbnail.OpenReadStream(), "bands", "thumbnail", filename, new Size(_configuration.GetValue <int>("Images:ThumbnailSize:Bands:X"), _configuration.GetValue <int>("Images:ThumbnailSize:Bands:Y"))); band.ImageThumbnail = filename; } if (model.ImageLarge != null) { string filename = band.Id + Path.GetExtension(model.ImageLarge.FileName); _fileUtility.SaveImage(model.ImageLarge.OpenReadStream(), "bands", "images", filename, new Size(_configuration.GetValue <int>("Images:Bands:X"), _configuration.GetValue <int>("Images:Bands:Y"))); band.ImageLarge = filename; } if (model.ImageMobile != null) { string filename = band.Id + Path.GetExtension(model.ImageMobile.FileName); _fileUtility.SaveImage(model.ImageMobile.OpenReadStream(), "bands", "mobile", filename, new Size(_configuration.GetValue <int>("Images:MobileSize:Bands:X"), _configuration.GetValue <int>("Images:MobileSize:Bands:Y"))); band.ImageMobile = filename; } }
public async Task <BandViewModel> Get(int id) { Band band = await _bandRepository.GetByIdAsync(id); BandViewModel bandViewModel = band.Adapt <BandViewModel>(); return(bandViewModel); }
public IActionResult Index(BandViewModel model) { if (ModelState.IsValid) { return(RedirectToAction("BandNameReserved")); } return(View("Index", model)); }
private void EmailAllMembers(BandViewModel band) { List <string> bandEmails = GetEmails(band); for (int i = 0; i < bandEmails.Count; i++) { string receipient = bandEmails[i]; string subject = "Join BANDdrop group!"; string body = "Join group by entering : '" + band.Name + "' at band join page!"; APIUtility.SendSimpleMessage(receipient, subject, body); } }
public async Task ReturnsBandForValidId() { HttpResponseMessage response = await _client.GetAsync($"{BaseUrl}/1"); response.EnsureSuccessStatusCode(); string responseContent = await response.Content.ReadAsStringAsync(); BandViewModel band = JsonConvert.DeserializeObject <BandViewModel>(responseContent); Assert.Equal("Radiohead", band.Name); }
public VMLocator(INavigationService nav) { var builder = new ContainerBuilder(); builder.RegisterInstance(nav); builder.RegisterType <MainPageViewModel>().SingleInstance(); // Factory to retrieve band view model from a cache and thus associate Band model objects // with BandViewModel objects - sure there must be a way to do this in AutoFac but haven't // found it yet. builder.Register((c, p) => { var p1 = (TypedParameter)p.First(); Band parameter = (Band)p1.Value; BandViewModel outVal = null; if (_bandCache.TryGetValue(parameter, out outVal)) { return(outVal); } outVal = new BandViewModel(parameter, c.Resolve <ITelemetry>()); _bandCache[parameter] = outVal; return(outVal); }); builder.RegisterType <DetailPageViewModel>().InstancePerDependency(); // Ensure this gets created early on... builder.RegisterInstance(new SettingsViewModel()); builder.RegisterType <ShellViewModel>().InstancePerDependency(); builder.RegisterType <HeartRateViewModel>().InstancePerDependency(); builder.RegisterType <SkinTempViewModel>().InstancePerDependency(); builder.RegisterType <UVViewModel>().InstancePerDependency(); builder.RegisterType <DistanceViewModel>().InstancePerDependency(); #if DEBUGddd builder.RegisterType <FakeBandService>().As <IBandService>().SingleInstance(); builder.RegisterType <FakeBandInfo>().As <IBandInfo>().InstancePerDependency(); #else builder.RegisterType <MSBandService>( ).As <IBandService>().SingleInstance(); #endif //builder.RegisterType<EventHubsTelemetry>().As<ITelemetry>().SingleInstance(); builder.RegisterType <IotHubsTelemetry>().As <ITelemetry>().InstancePerDependency(); builder.RegisterType <Band>().InstancePerDependency(); builder.RegisterType <EventAggregator>().As <IEventAggregator>().SingleInstance(); _container = builder.Build(); }
public async Task ReturnsNoContentGivenValidData() { var band = new BandViewModel { Id = 1, Name = "A", ActiveFromYear = DateTime.Today.Year - 5, ActiveToYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PutAsJsonAsync($"{BaseUrl}/1", band); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); }
public async Task ReturnsBadRequestGivenIdMismatch() { var band = new BandViewModel { Id = 1, Name = "A", ActiveFromYear = DateTime.Today.Year - 5, ActiveToYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PutAsJsonAsync($"{BaseUrl}/2", band); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public IActionResult Band(int id) { var band = _db.GetBand(id); var bandViewModel = new BandViewModel { Genre = _mapper.Map <GenreDto>(band.Genre), Band = _mapper.Map <BandDto>(band), BandMembers = _mapper.Map <List <BandMemberDto> >(band.BandMembers), Albums = _mapper.Map <List <AlbumDto> >(band.Albums), }; return(View(bandViewModel)); }
public async Task ReturnsBadRequestGivenNoName() { var band = new BandViewModel { ActiveFromYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PostAsJsonAsync(BaseUrl, band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Contains("Name", responseContent); Assert.Contains("The Name field is required.", responseContent); }
public async Task <IActionResult> Post([FromBody] BandViewModel model) { var band = new Band { Name = model.Name, ActiveFromYear = model.ActiveFromYear, ActiveToYear = model.ActiveToYear }; await _bandRepository.AddAsync(band); BandViewModel bandViewModel = band.Adapt <BandViewModel>(); return(CreatedAtAction(nameof(Get), new { id = band.Id }, bandViewModel)); }
public async Task ReturnsBadRequestGivenNameOver100Chars() { var band = new BandViewModel { Name = "A".PadLeft(101), ActiveFromYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PostAsJsonAsync(BaseUrl, band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Contains("Name", responseContent); Assert.Contains("The field Name must be a string with a maximum length of 100.", responseContent); }
public async Task ReturnsBadRequestGivenActiveToYearLessThan1900() { var band = new BandViewModel { Name = "A", ActiveToYear = 1899 }; HttpResponseMessage response = await _client.PostAsJsonAsync(BaseUrl, band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Contains("ActiveToYear", responseContent); Assert.Contains($"The field ActiveToYear must be between 1900 and {DateTime.Today.Year}.", responseContent); }
public async Task ReturnsBadRequestGivenActiveFromYearGreaterThanActiveToYear() { var band = new BandViewModel { Name = "A", ActiveFromYear = DateTime.Today.Year, ActiveToYear = DateTime.Today.Year - 1 }; HttpResponseMessage response = await _client.PostAsJsonAsync(BaseUrl, band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Contains("Active from Year must be lower than or equal to Active to Year.", responseContent); }
public async Task <IActionResult> Put(int id, [FromBody] BandViewModel model) { if (id != model.Id) { return(BadRequest()); } Band band = await _bandRepository.GetByIdAsync(id); band.Name = model.Name; band.ActiveFromYear = model.ActiveFromYear; band.ActiveToYear = model.ActiveToYear; await _bandRepository.UpdateAsync(band); return(NoContent()); }
public async Task ReturnsNotFoundForInvalidId() { var band = new BandViewModel { Id = 0, Name = "A", ActiveFromYear = DateTime.Today.Year - 5, ActiveToYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PutAsJsonAsync($"{BaseUrl}/0", band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal("0", responseContent); }
public async Task ReturnsBadRequestGivenActiveFromYearGreaterThanCurrentYear() { var band = new BandViewModel { Id = 1, Name = "A", ActiveFromYear = DateTime.Today.Year + 1 }; HttpResponseMessage response = await _client.PutAsJsonAsync($"{BaseUrl}/1", band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Contains("ActiveFromYear", responseContent); Assert.Contains($"The field ActiveFromYear must be between 1900 and {DateTime.Today.Year}.", responseContent); }
public ActionResult Create([Bind(Include = "Name,Email_2,Email_3,Email_4,Email_5,Email_6,")] BandViewModel band) { if (ModelState.IsValid) { Band newBand = new Band(); newBand.BandName = band.Name; db.Bands.Add(newBand); db.SaveChanges(); EmailAllMembers(band); string userId = User.Identity.GetUserId(); var user = db.Musicians.FirstOrDefault(m => m.UserId == userId); user.BandName = band.Name; var userBand = db.Bands.Where(b => b.BandName == band.Name).First(); user.BandId = userBand.Id; user.Band = userBand; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(band)); }
//////////////////////////////////////////////////////////////////////////////////////// //DASHBOARD: HOME //////////////////////////////////////////////////////////////////////////////////////// public ActionResult Index(int?bandId) { //Common code for all actions in BandController CheckSubscription(); var bands = GetUserBands(); if (bands.Count <= 0) { return(RedirectToAction("Create")); } Band currentBand = bands[0]; if (bandId != null) { currentBand = bands.Where(b => b.BandId == bandId).FirstOrDefault(); } else { return(RedirectToAction("Index", "Band", new { bandId = currentBand.BandId })); } List <Band> otherBands; otherBands = bands.Where(b => b.BandId != bandId).ToList(); //End of common code var viewModel = new BandViewModel(); viewModel.OtherBands = otherBands; viewModel.CurrentBand = currentBand; if (TempData["infoMessage"] != null) { ViewBag.infoMessage = TempData["infoMessage"].ToString(); } if (TempData["dangerMessage"] != null) { ViewBag.dangerMessage = TempData["dangerMessage"].ToString(); } return(View(viewModel)); }
public IActionResult Post([FromForm] BandViewModel model) { Band band = new Band { DescriptionDe = model.DescriptionDe, DescriptionFr = model.DescriptionFr, Name = model.Name, SpotifyPlaylist = model.SpotifyPlaylist, Stage = model.Stage, YoutubeUrls = model.YoutubeUrls, Facebook = model.Facebook, Instagram = model.Instagram, PlayTime = model.PlayTime, WebSiteUrl = model.WebSiteUrl, PlayTimeForSorting = model.PlayTimeForSorting }; band.Order = _bandRepository.GetAll().Select(b => b.Order).DefaultIfEmpty(0).Max() + 1; _bandRepository.Add(band); SafeBandImages(model, band); _bandRepository.Update(band); return(CreatedAtRoute(GetBandRouteName, new { id = band.Id }, band)); }
public async Task ReturnsCreatedGivenValidData() { var band = new BandViewModel { Name = "A", ActiveFromYear = DateTime.Today.Year - 5, ActiveToYear = DateTime.Today.Year }; HttpResponseMessage response = await _client.PostAsJsonAsync(BaseUrl, band); string responseContent = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.Created, response.StatusCode); var bandCreated = JsonConvert.DeserializeObject <BandViewModel>(responseContent); Assert.Equal("A", bandCreated.Name); Assert.Equal(DateTime.Today.Year - 5, bandCreated.ActiveFromYear); Assert.Equal(DateTime.Today.Year, bandCreated.ActiveToYear); Assert.True(bandCreated.Id > 0); Assert.Contains($"{BaseUrl}/{bandCreated.Id}", response.Headers.Location.ToString(), StringComparison.InvariantCultureIgnoreCase); }
// GET: Bands/SelectBand/42 public ActionResult SelectBand(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var selectedBand = db.Bands.Find(id); if (selectedBand == null) { return(HttpNotFound()); } var members = selectedBand.People.ToList(); var viewModel = new BandViewModel { mBand = selectedBand, mMembers = members }; return(View("Band", viewModel)); }
//////////////////////////////////////////////////////////////////////////////////////// //DASHBOARD: HOME //////////////////////////////////////////////////////////////////////////////////////// public ActionResult Index(int?bandId) { //Common code for all actions in BandMemberController List <Band> bands = GetAllBands(); List <Band> myBands = GetUserBands(bands); List <Invitation> invitations = GetInvitations(); CheckInvitationStatus(myBands, invitations); Band currentBand = myBands[0]; if (bandId != null) { currentBand = bands.Where(b => b.BandId == bandId).FirstOrDefault(); } else { return(RedirectToAction("Index", "BandMember", new { bandId = currentBand.BandId })); } List <Band> otherBands = myBands.Where(b => b.BandId != bandId).ToList(); //end of common code //////////////////////////////////////////////////// var viewModel = new BandViewModel(); viewModel.OtherBands = otherBands; viewModel.Invitations = invitations; viewModel.CurrentBand = currentBand; if (TempData["infoMessage"] != null) { ViewBag.infoMessage = TempData["infoMessage"].ToString(); } if (TempData["dangerMessage"] != null) { ViewBag.dangerMessage = TempData["dangerMessage"].ToString(); } return(View(viewModel)); }
public IEnumerable <BandViewModel> SearchBand([FromQuery] string search, [FromQuery] bool?isActive) { return(_bandsRepository.SearchEntity(search, isActive).Select(b => BandViewModel.FromBand(b))); }