コード例 #1
0
        public async Task <ResponseModel> SaveAsync(DocumentViewModel model)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                var user = await userManager.FindByIdAsync(model.RequestBy);

                if (user != null)
                {
                    NewDocumentRequest document = new NewDocumentRequest()
                    {
                        DocumentTypeId          = model.DocumentTypeId,
                        Description             = model.Description,
                        ApprovalStatusId        = (int)Utility.ApprovalStatus.Awaiting_Admin_Review,
                        DocumentName            = model.DocumentName,
                        LastUpdated             = DateTime.Now,
                        RequestBy               = model.RequestBy,
                        RequestDate             = DateTime.Now,
                        IsFinalApprovalObtained = false
                    };
                    dbContext.NewDocumentRequest.Add(document);
                    await dbContext.SaveChangesAsync();

                    response.Code    = 200;
                    response.Message = "Document saved successfully, awaiting admin review";
                }
                else
                {
                    response.Code    = 404;
                    response.Message = "User doesn't exist";
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Code    = 404;
                dbContext.NewDocumentRequest.Local.Clear();
                ErrorLog log = new ErrorLog();
                log.ErrorDate       = DateTime.Now;
                log.ErrorMessage    = ex.Message;
                log.ErrorSource     = ex.Source;
                log.ErrorStackTrace = ex.StackTrace;
                dbContext.ErrorLogs.Add(log);
                await dbContext.SaveChangesAsync();
            }
            return(response);
        }
コード例 #2
0
        public async Task <ResponseModel> DeleteAsync(long id)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                NewDocumentRequest document = await dbContext.NewDocumentRequest.FindAsync(id);

                if (document != null)
                {
                    dbContext.NewDocumentRequest.Remove(document);
                    await dbContext.SaveChangesAsync();

                    response.Message = "Record deleted successfully";
                    response.Code    = 200;
                }
                else
                {
                    response.Message = "Record not found";
                    response.Code    = 404;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Code    = 404;
                dbContext.NewDocumentRequest.Local.Clear();
                ErrorLog log = new ErrorLog();
                log.ErrorDate       = DateTime.Now;
                log.ErrorMessage    = ex.Message;
                log.ErrorSource     = ex.Source;
                log.ErrorStackTrace = ex.StackTrace;
                dbContext.ErrorLogs.Add(log);
                await dbContext.SaveChangesAsync();
            }
            return(response);
        }