Esempio n. 1
0
        public async Task <IActionResult> GetAllBands()
        {
            var bands = _bandsRepository.GetAllEntities();
            var model = bands.Select(b => BandViewModel.FromBand(b));

            return(Ok(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetMostPopular()
        {
            var toprated = _bandsRepository.GetTopRated();
            var model    = toprated.Select(b => BandViewModel.FromBand(b));

            return(Ok(model));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetBandById([FromRoute] int id)
        {
            var band  = _bandsRepository.GetEntityById(id);
            var model = BandViewModel.FromBand(band);

            return(Ok(model));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        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;
            }
        }
Esempio n. 8
0
        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));
 }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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();
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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());
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        ////////////////////////////////////////////////////////////////////////////////////////
        //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));
        }
Esempio n. 26
0
        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));
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        // 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));
        }
Esempio n. 29
0
        ////////////////////////////////////////////////////////////////////////////////////////
        //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));
        }
Esempio n. 30
0
 public IEnumerable <BandViewModel> SearchBand([FromQuery] string search, [FromQuery] bool?isActive)
 {
     return(_bandsRepository.SearchEntity(search, isActive).Select(b => BandViewModel.FromBand(b)));
 }