예제 #1
0
        /// <summary>
        /// Removes a document from loadshop and document service
        /// </summary>
        /// <param name="loadDocumentId"></param>
        /// <returns></returns>
        public async Task RemoveDocument(Guid loadDocumentId)
        {
            securityService.GuardAction(SecurityActions.Loadshop_Ui_Carrier_MyLoads_Documents_Remove);

            var loadDocument = await context.LoadDocuments.FirstOrDefaultAsync(x => x.LoadDocumentId == loadDocumentId);

            if (loadDocument == null)
            {
                throw new ValidationException("Document not found");
            }

            var load = await context.Loads.AsNoTracking().FirstOrDefaultAsync(x => x.LoadId == loadDocument.LoadId);

            if (load == null)
            {
                throw new ValidationException("Load not found");
            }

            try
            {
                // remove file from document API
                await documentApiClient.DeleteDocument(loadDocument.DocumentServiceDocHeaderId);

                // add the new entity and in order for the DB to generate the doc id, use that to pass to the document service
                context.LoadDocuments.Remove(loadDocument);
                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                // if any errors occured, we dont want to show the record in loadshop, so remove the attachment record and return error
                logger.LogError($"Error while removing document from Document Service: {e.Message}, removing db record from Loadshop", e);
            }
        }
예제 #2
0
        public async Task <IActionResult> Delete(DocumentsDeleteRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _documentApiClient.DeleteDocument(request.ID);

            if (result)
            {
                TempData["result"] = "Delete acccess";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Cannot delete document");
            return(View(request));
        }