Ejemplo n.º 1
0
        public async Task <ActionResult> RemoveCrewMemberAsync(RemoveCrewMemberVm crewMember)
        {
            await _crewService.RemoveCrewMemberAsync(crewMember);

            Log.Information("Crewmember {@crewMember} deleted from db", crewMember);
            return(Ok());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes crewmember from crew
        /// </summary>
        public async Task RemoveCrewMemberAsync(RemoveCrewMemberVm crewMember)
        {
            var user = await _dbContext.ApplicationUsers.FindAsync(crewMember.UserId);

            if (user == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"Fant ikke brukeren med id: {crewMember.UserId}");
            }

            var crewMemberExisting = await _dbContext.CrewUsers
                                     .Where(a => a.CrewId == crewMember.CrewId && a.ApplicationUserId == crewMember.UserId)
                                     .FirstOrDefaultAsync();

            if (crewMemberExisting == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, "Brukeren er ikke i arbeidslaget, og kan derfor ikke fjernes");
            }

            _dbContext.CrewUsers.Remove(crewMemberExisting);
            await _dbContext.SaveChangesAsync();
        }