Exemple #1
0
        public async Task <IHttpActionResult> PostLiveShow(LiveShow liveShow)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LiveShows.Add(liveShow);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LiveShowExists(liveShow.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = liveShow.id }, liveShow));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Artist,Venue,ShowDate,EnteredBy")] LiveShow liveShow)
        {
            if (id != liveShow.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(liveShow);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LiveShowExists(liveShow.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(liveShow));
        }
Exemple #3
0
        public async Task <IHttpActionResult> PutLiveShow(Guid id, LiveShow liveShow)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != liveShow.id)
            {
                return(BadRequest());
            }

            db.Entry(liveShow).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LiveShowExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult Create()
        {
            var venues = GetVenues();
            var model  = new LiveShow {
                Venues = venues
            };

            return(View(model));
        }
        public async Task <IActionResult> Create([Bind("Id,Artist,Venue,ShowDate,EnteredBy")] LiveShow liveShow)
        {
            if (ModelState.IsValid)
            {
                _context.Add(liveShow);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(liveShow));
        }
Exemple #6
0
        public async Task <IHttpActionResult> GetLiveShow(Guid id)
        {
            LiveShow liveShow = await db.LiveShows.FindAsync(id);

            if (liveShow == null)
            {
                return(NotFound());
            }

            return(Ok(liveShow));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Artist,Venue,ShowDate")] LiveShow liveShow)
        {
            var currentUser = User.Identity.Name;

            liveShow.EnteredBy = currentUser;
            if (id != liveShow.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var existingShow = await _context.LiveShows.FindAsync(id);

                    existingShow.Artist    = liveShow.Artist;
                    existingShow.Venue     = liveShow.Venue;
                    existingShow.ShowDate  = liveShow.ShowDate;
                    existingShow.EnteredBy = currentUser;

                    if (existingShow.EnteredBy != User.Identity.Name)
                    {
                        return(Unauthorized());
                    }

                    var show = _context.LiveShows.FirstOrDefault(x => x.Artist == existingShow.Artist && x.ShowDate == liveShow.ShowDate);

                    if (show != null)
                    {
                        return(ValidationProblem());
                    }

                    _context.Update(existingShow);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LiveShowExists(liveShow.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(liveShow));
        }
Exemple #8
0
        public async Task <IHttpActionResult> DeleteLiveShow(Guid id)
        {
            LiveShow liveShow = await db.LiveShows.FindAsync(id);

            if (liveShow == null)
            {
                return(NotFound());
            }

            db.LiveShows.Remove(liveShow);
            await db.SaveChangesAsync();

            return(Ok(liveShow));
        }
Exemple #9
0
        public async Task <IActionResult> Create([Bind("Id,Artist,Venue,ShowDate")] LiveShow liveShow)
        {
            liveShow.EnteredBy = User.Identity.Name;
            if (ModelState.IsValid)
            {
                var existing = await _context.LiveShows.FirstOrDefaultAsync(f => f.ShowDate.Date == liveShow.ShowDate.Date && f.Artist == liveShow.Artist);

                if (existing != null)
                {
                    return(Content("Unable to create a liveshow for the same artist on the same dates.."));
                }
                _context.Add(liveShow);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(liveShow));
        }
        public async Task <IActionResult> Create([Bind("Id,Artist,Venue,ShowDate")] LiveShow liveShow)
        {
            liveShow.EnteredBy = User.Identity.Name;
            if (ModelState.IsValid)
            {
                var show = _context.LiveShows.FirstOrDefault(x => x.Artist == liveShow.Artist && x.ShowDate == liveShow.ShowDate);

                if (show != null)
                {
                    return(ValidationProblem());
                }

                _context.Add(liveShow);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(liveShow));
        }
Exemple #11
0
        public async Task <IActionResult> Create([Bind("Id,Artist,Venue,ShowDate")] LiveShow liveShow)
        {
            liveShow.EnteredBy = User.Identity.Name;
            if (ModelState.IsValid)
            {
                int count = _context.LiveShows.Where(l => l.Artist == liveShow.Artist && l.ShowDate.Year == liveShow.ShowDate.Year && l.ShowDate.Month == liveShow.ShowDate.Month && l.ShowDate.Day == liveShow.ShowDate.Day).Count();

                if (count == 0)
                {
                    _context.Add(liveShow);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError("", "Same artist cannot have more than one event on the same date");
                }
            }
            return(View(liveShow));
        }