public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var client = await _context.CrmClients.Include(cl => cl.Documents).FirstOrDefaultAsync(cl => cl.ClientId == id);

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

                if (client.Documents != null)
                {
                    foreach (var doc in client.Documents)
                    {
                        _savedDocumentHandler.DeleteDocument(doc.Name);
                    }
                }
                _context.Remove(client);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                var debugEx = ex;
                return(BadRequest());
            }
        }
        public async Task <IActionResult> DeleteCandidate([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var candidate = await _context.Candidates.Include(c => c.Documents).FirstOrDefaultAsync(c => c.CandidateId == id);

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

            if (candidate.Documents != null)
            {
                foreach (var doc in candidate.Documents)
                {
                    _savedDocumentHandler.DeleteDocument(doc.Name);
                }
            }

            _context.Candidates.Remove(candidate);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteJob([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var job = await _context.Jobs.Include(j => j.Documents).FirstOrDefaultAsync(j => j.JobId == id);

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

            if (job.Documents != null)
            {
                foreach (var doc in job.Documents)
                {
                    _savedDocumentHandler.DeleteDocument(doc.Name);
                }
            }

            _context.Jobs.Remove(job);
            await _context.SaveChangesAsync();

            return(NoContent());
            //return Ok(job);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var document = await _context.Documents
                               .FirstOrDefaultAsync(d => d.FileRepresentationInDatabaseId == id);

                if (document == null)
                {
                    return(NotFound());
                }
                _savedDocumentHandler.DeleteDocument(document.Name);
                _context.Remove(document);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                var debugEx = ex;
                return(BadRequest());
            }
        }