示例#1
0
        public async Task <IActionResult> SaveJournalImport([FromBody] SaveJournalImportRequest req)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                PortalUser user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

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

                JournalImportModel saveMe = req.JournalEntry.docfile;

                JournalImport dbEntry = null;

                // Make sure the driver exists.
                if (saveMe.JournalEntryID == null || saveMe.JournalEntryID == 0)
                {
                    throw new NullReferenceException("JournalEntryID is required.");
                }

                // Are we saving a new Journal or editing an old one?
                dbEntry = new JournalImport();
                repository.Insert(dbEntry);
                dbEntry.CreatedBy      = user.PortalUsername;
                dbEntry.DocTitle       = saveMe.DocTitle;
                dbEntry.ContentType    = saveMe.ContentType;
                dbEntry.CreatedDate    = DateTime.UtcNow;
                dbEntry.JournalEntryID = saveMe.JournalEntryID;
                dbEntry.FileName       = saveMe.FileName;

                Byte[] bytes = Convert.FromBase64String(saveMe.FileData64String);
                dbEntry.FileData = bytes;

                await repository.SaveChanges();

                JournalImportModel resp = new JournalImportModel();
                resp = LoadJournalImport(dbEntry);
                return(Ok(resp));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
示例#2
0
        /// <summary>
        /// Will convert a dbModel to its DTO pair.
        /// </summary>
        public static JournalImportModel LoadJournalImport(JournalImport dbModel)
        {
            JournalImportModel ret = new JournalImportModel
            {
                CreatedBy       = dbModel.CreatedBy,
                CreatedDate     = dbModel.CreatedDate,
                DocTitle        = dbModel.DocTitle,
                ContentType     = dbModel.ContentType,
                FileName        = dbModel.FileName,
                JournalEntryID  = dbModel.JournalEntryID,
                JournalImportId = dbModel.JournalImportId
            };

            return(ret);
        }