public async Task <IActionResult> DeleteRecertCycle(int id)
        {
            try
            {
                if (id <= 0)
                {
                    return(StatusCode(400, "id is invalid"));
                }

                var RecertCycle = await _context.RecertCycleTable.FindAsync(id);

                if (RecertCycle == null)
                {
                    return(StatusCode(404));
                }

                _context.RecertCycleTable.Remove(RecertCycle);
                await _context.SaveChangesAsync();

                return(StatusCode(204));
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex.ToString());
                return(StatusCode(500));
            }
        }
Exemple #2
0
        public async Task <ActionResult <PrivDTO> > AddPriv(PrivPostDTO priv)
        {
            try
            {
                var privExists = await _context.PrivTable.FindAsync(priv.PrivId);

                if (privExists != null)
                {
                    return(StatusCode(409, "The PrivId already exists")); // Conflict
                }

                var serviceExists = await _context.ServiceTable.FindAsync(priv.ServiceId);

                if (serviceExists == null)
                {
                    return(StatusCode(400, "The ServiceId does not exist"));
                }

                _context.PrivTable.Add(
                    new PrivTable
                {
                    PrivId                  = priv.PrivId,
                    ServiceId               = priv.ServiceId,
                    PermissionGroup         = priv.PermissionGroup,
                    ServicePrivSummary      = priv.ServicePrivSummary,
                    CredentialStorageMethod = priv.CredentialStorageMethod
                }
                    );

                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetPriv), new { id = priv.PrivId }, priv));
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex.ToString());
                return(StatusCode(500));
            }
        }
Exemple #3
0
        public async Task <ActionResult <ServiceDTO> > AddService(ServicePostDTO service)
        {
            try
            {
                var serviceExists = await _context.ServiceTable.FindAsync(service.ServiceId);

                if (serviceExists != null)
                {
                    return(StatusCode(409, "The ServiceId already exists"));
                }

                var roleExists = await _context.RoleTable.FindAsync(service.ServiceOwner_RoleId);

                if (roleExists == null)
                {
                    return(StatusCode(400, "The ServiceOwner_RoleId does not exist"));
                }

                _context.ServiceTable.Add(
                    new ServiceTable
                {
                    ServiceId           = service.ServiceId,
                    ServiceName         = service.ServiceName,
                    ServiceDescription  = service.ServiceDescription,
                    ServiceOwner_RoleId = service.ServiceOwner_RoleId
                }
                    );

                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetService), new { id = service.ServiceId }, service));
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex.ToString());
                return(StatusCode(500));
            }
        }
Exemple #4
0
        public async Task <ActionResult <UserDTO> > AddUser(UserPostDTO user)
        {
            try
            {
                var userExists = await _context.UserTable.FindAsync(user.UserId);

                if (userExists != null)
                {
                    return(StatusCode(409, "The UserId already exists"));
                }

                var roleExists = await _context.RoleTable.FindAsync(user.RoleId);

                if (roleExists == null)
                {
                    return(StatusCode(400, "The RoleId does not exist"));
                }

                _context.UserTable.Add(
                    new UserTable
                {
                    UserId       = user.UserId,
                    UserFullName = user.UserFullName,
                    RoleId       = user.RoleId
                }
                    );

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex.ToString());
                return(StatusCode(500));
            }

            return(CreatedAtAction(nameof(GetUser), new { id = user.UserId }, user));
        }