Beispiel #1
0
        public async Task <IActionResult> PutEventDetail(int id, EventDetail eventDetail)
        {
            if (id != eventDetail.EventId)
            {
                return(BadRequest());
            }

            _context.Entry(eventDetail).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <IActionResult> PutUserDetail(int id, UserDetail userDetail)
        {
            if (id != userDetail.UserId)
            {
                return(BadRequest());
            }

            userDetail.Email = userDetail.Email.ToLower().Trim();
            if (!string.IsNullOrEmpty(userDetail.Password))
            {
                userDetail.Password = PasswordEncryptor.Encrypt(userDetail.Password);
            }

            _context.Entry(userDetail).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <ActionResult> AddEvent(int userId, int eventId)
        {
            try
            {
                var user = await _context.UserDetails.FirstOrDefaultAsync(u => u.UserId == userId);

                if (user == null)
                {
                    BadRequest("User not found");
                }

                var eventDetail = await _context.EventDetails.FirstOrDefaultAsync(u => u.EventId == eventId);

                if (eventDetail == null)
                {
                    BadRequest("Event not found");
                }

                if (await _context.UserEventDetails.AnyAsync(e => e.UserId == userId && e.EventId == eventId))
                {
                    BadRequest();
                }

                _context.UserEventDetails.Add(new UserEventDetail {
                    EventId = eventId, UserId = userId
                });
                await _context.SaveChangesAsync();
            }

            catch (Exception ex)
            {
                BadRequest(ex.Message);
            }

            return(Ok());
        }