public IHttpActionResult CreateAttendance(int id)
        {
            var gig = _gigRepository.Get(id);

            if (gig == null)
            {
                return(BadRequest());
            }
            var attendance = new Attendance()
            {
                Artist = _userRepository.GetUserCurrent(User.Identity.GetUserId()),
                Gig    = gig
            };

            _attendanceRepository.Add(attendance);
            _unitOfWork.Complete();
            return(Ok(attendance.Id));
        }
Exemple #2
0
        public IHttpActionResult DeleteGig(int id)
        {
            var gig = _gigRepository.Get(id);

            if (gig == null)
            {
                return(BadRequest());
            }
            var attendances = _attendanceRepository.GetAllWithArtistGigCurrent(gig.Id);

            if (attendances.Count() != 0)
            {
                var userCurrent  = _userRepository.GetUserCurrent(User.Identity.GetUserId());
                var notification = new Notification()
                {
                    Date        = DateTime.Today,
                    Information = "A " + userCurrent.ArtisticName + "'s concert was removed",
                    GigDate     = gig.Date.ToString(),
                    Delivered   = false,
                    Gig         = 0
                };
                _notificationRepository.Add(notification);
                _unitOfWork.Complete();
                foreach (var attendance in attendances)
                {
                    _inboxRepository.Add(new Inbox()
                    {
                        User         = attendance.Artist,
                        Notification = notification
                    });
                    _attendanceRepository.Remove(attendance);
                }
                notification.Delivered = true;
            }
            _gigRepository.Remove(gig);
            var notifications = _notificationRepository.GetNotificationsGig(gig.Id);

            foreach (var notification in notifications)
            {
                notification.Gig = 0;
            }
            _unitOfWork.Complete();
            return(Ok());
        }