Beispiel #1
0
 public IActionResult AddDocumentFile(DocumentFile df)
 {
     df.numberOf_document = 0;
     dbContext.documentFiles.Add(df);
     dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #2
0
        public DocumentInfo CreateDocument(CreateDocumentInput input, Stream stream)
        {
            var documentInfo = Mapper.Map <DocumentInfo>(input);

            StoreDocumentFile(documentInfo, stream);
            HandleTifFile(documentInfo.FileType, documentInfo.Path);

            documentInfo.Key            = Guid.NewGuid().ToString();
            documentInfo.CreateTime     = DateTime.Now;
            documentInfo.ModifyTime     = documentInfo.CreateTime;
            documentInfo.ModifyUserId   = documentInfo.CreateUserID;
            documentInfo.ModifyUserName = documentInfo.CreateUserName;
            documentInfo.CurrentVersion = 1;

            _context.DocumentInfos.Add(documentInfo);
            _context.SaveChanges();

            var             historyPath = StoreHistoryFile(stream, documentInfo.FileType);
            DocumentHistory fileHistory = new DocumentHistory
            {
                DocumentInfoId  = documentInfo.Id,
                Version         = 1,
                PreviousVersion = -1,
                Key             = documentInfo.Key,
                Path            = historyPath,
                UserId          = input.CreateUserID,
                UserName        = input.CreateUserName,
                CreateTime      = DateTime.Now
            };

            _context.DocumentHistories.Add(fileHistory);
            _context.SaveChanges();

            return(documentInfo);
        }
Beispiel #3
0
        public IActionResult AddUser(User u)
        {
            if (ModelState.IsValid)
            {
                dbContext.users.Add(u);
                dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Beispiel #4
0
        public IActionResult AddDocument(Document d) // yeni doc ekliyo
        {
            var user = dbContext.users.Where(x => x.user_id == d.User.user_id).FirstOrDefault();

            d.User = user;

            var docFile = dbContext.documentFiles.Where(x => x.document_file_id == d.DocumentFile.document_file_id).FirstOrDefault();

            docFile.numberOf_document++;
            d.DocumentFile = docFile;

            dbContext.documents.Add(d);

            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public bool RemoveFile(string id)
        {
            var ids = id.Split(',');

            foreach (var item in ids)
            {
                PersonalFile personalFile = _context.PersonalFiles.Find(int.Parse(item));

                if (personalFile != null)
                {
                    _context.PersonalFiles.Remove(personalFile);
                }
            }

            _context.SaveChanges();
            return(true);
        }
Beispiel #6
0
        public IActionResult RemoveDoc(int id)
        {
            var dd = dbContext.deletedDocuments.Find(id);

            dbContext.deletedDocuments.Remove(dd);
            dbContext.SaveChanges();
            TempData.Add("Alert", "Document was completely deleted");
            return(RedirectToAction("Index"));
        }
 public static void EnsureSeeded(this DocumentDbContext context)
 {
     if (!context.DocumentsTypes.Any())
     {
         var types = JsonConvert.DeserializeObject <List <DocumentType> >(File.ReadAllText("Seeds" + Path.DirectorySeparatorChar + "DocumentTypes.json"));
         context.AddRange(types);
         context.SaveChanges();
     }
 }
Beispiel #8
0
 public ActionResult AddComments(string doc, int id)
 {
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == id).First().Comments = doc;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #9
0
 public ActionResult CancelDocument(int docId)
 {
     //9 wycofana z obiegu
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == docId).First().Status = db.Status.Where(c => c.StatusId == 9).First();
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #10
0
 public ActionResult CancelPutToArchive(int docId)
 {
     //Powrot do status id=4
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == docId).First().Status       = db.Status.Where(c => c.StatusId == 4).First();
         db.Documents.Where(x => x.DocumentId == docId).First().DateOfDelete = null;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #11
0
 public ActionResult SayNo(int docId)
 {
     //3 status odrzucona w bazie danych
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == docId).First().Status           = db.Status.Where(c => c.StatusId == 3).First();
         db.Documents.Where(x => x.DocumentId == docId).First().DateOfAcceptance = DateTime.Today;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #12
0
 public ActionResult PutToArchive(int docId)
 {
     //5 archiwum
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == docId).First().Status       = db.Status.Where(c => c.StatusId == 5).First();
         db.Documents.Where(x => x.DocumentId == docId).First().DateOfDelete = DateTime.Today;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Delete(int UserId, int id)
 {
     //przypisanie osoby odpowiedzialnej za zaakceptowanie usuniecia
     //7 status oczekuje na akceptacje do usuniecia
     using (var db = new DocumentDbContext())
     {
         db.Documents.Where(x => x.DocumentId == id).First().DeleteUser = db.DeleteAuthor.Where(z => z.DeleteUserId == UserId).First();
         db.Documents.Where(x => x.DocumentId == id).First().StatusId = 7;
         db.SaveChanges();
     }
     return RedirectToAction("DeleteDocument");
 }
        public bool AddShareUser(AddShareUserInput input)
        {
            var fileUsersToRemove = _context.FileUsers.Where(a => a.FileId == input.FileId);

            _context.FileUsers.RemoveRange(fileUsersToRemove);

            foreach (var item in input.FileUserDtos)
            {
                var user = _context.Users.FirstOrDefault(a => a.UserID == item.UserId);
                if (user == null)
                {
                    user = new User
                    {
                        UserID       = item.UserId,
                        UserName     = item.UserName,
                        CreationTime = DateTime.Now
                    };

                    _context.Users.Add(user);
                }

                var fileUser = new FileUser
                {
                    FileId       = input.FileId,
                    UserId       = item.UserId,
                    Permission   = item.Permission,
                    CreationTime = DateTime.Now
                };

                _context.FileUsers.Add(fileUser);
            }

            _context.SaveChanges();

            return(true);
        }
        public bool SaveUser(UserDto userDto)
        {
            if (string.IsNullOrEmpty(userDto.UserID) || string.IsNullOrEmpty(userDto.UserName))
            {
                return(true);
            }

            var user = _context.Users.FirstOrDefault(a => a.UserID == userDto.UserID);

            if (user == null)
            {
                user = Mapper.Map <User>(userDto);
                user.CreationTime = DateTime.Now;
                _context.Users.Add(user);
                _context.SaveChanges();
            }

            return(true);
        }
Beispiel #16
0
        //private byte[] GetExcelFile()
        //{

        //}
        public ActionResult SayYes(int docId)
        {
            //2 status zatwierdzona w bazie danych
            using (var db = new DocumentDbContext())
            {
                var    DocExcel     = db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel;
                string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string pathDownload = Path.Combine(pathUser, "Downloads");
                string title        = "temp" + DateTime.Now;
                title = title.Replace("-", "");
                title = title.Replace(":", "");
                string title2     = "temp" + ".pdf";
                string EndPathPDF = Path.Combine(pathDownload, title2);
                string EndPath    = Path.Combine(pathDownload, title);

                //stworzenie tablicy wielkosci
                System.IO.File.WriteAllBytes(EndPath, DocExcel);
                MyApp         = new Microsoft.Office.Interop.Excel.Application();
                MyApp.Visible = false;
                MyBook        = MyApp.Workbooks.Open(EndPath);
                MyWorkSheet   = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.Sheets[1];
                var    acceptUser = db.Documents.Where(x => x.DocumentId == docId).First().AcceptedUserId;
                string user       = db.Users.Where(x => x.AcceptUser.AcceptedUserId == acceptUser).First().FirstName + " " +
                                    db.Users.Where(x => x.AcceptUser.AcceptedUserId == acceptUser).First().LastName;
                MyWorkSheet.Cells[5, 13] = user;
                MyApp.Save();
                MyBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, EndPathPDF);
                MyBook.Close();
                byte[] f1 = new byte[15728640];
                f1 = System.IO.File.ReadAllBytes(EndPath);
                byte[] fPDF = new byte[15728640];
                fPDF = System.IO.File.ReadAllBytes(EndPathPDF);

                db.Documents.Where(x => x.DocumentId == docId).First().DocumentFile      = fPDF;
                db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel = f1;
                db.Documents.Where(x => x.DocumentId == docId).First().Status            = db.Status.Where(c => c.StatusId == 2).First();
                db.Documents.Where(x => x.DocumentId == docId).First().DateOfAcceptance  = DateTime.Today;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #17
0
        public bool ExternalRefreshFile(ExternalRefreshFileInput input)
        {
            var documentInfo = _context.DocumentInfos.FirstOrDefault(a => a.ExternalID == input.ID);

            if (documentInfo == null)
            {
                return(false);
            }

            DocumentHistory documentHistory = _context.DocumentHistories.FirstOrDefault(a => a.DocumentInfoId == documentInfo.Id && a.Version == documentInfo.CurrentVersion);

            documentInfo.Key    = Guid.NewGuid().ToString();
            documentHistory.Key = documentInfo.Key;
            if (!string.IsNullOrEmpty(input.NewID))
            {
                documentInfo.ExternalID = input.NewID;
            }

            documentService.StoreDocumentFile(documentInfo, input.FilePath);
            _context.SaveChanges();

            return(true);
        }
Beispiel #18
0
 public Category AddCategory(Category category)
 {
     _context.Categories.Add(category);
     _context.SaveChanges();
     return(category);
 }
Beispiel #19
0
        public ActionResult RegisterDocument(Document doc, HttpPostedFileBase file, string Title, int LineId,
                                             int OperationId, int DocumentTypeId, int AcceptedUserId)
        {
            //stworzenie sciezki do zapisania pliku
            //index idLini-idOperarcji-idInstr
            string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string pathDownload = Path.Combine(pathUser, "Downloads");
            string title        = Title + DateTime.Now;

            title = title.Replace("-", "");
            title = title.Replace(":", "");
            string title2     = LineId.ToString() + ".pdf";
            string EndPath    = Path.Combine(pathDownload, title);
            string EndPathPDF = Path.Combine(pathDownload, title2);

            //stworzenie tablicy wielkosci
            doc.DocumentFile = new byte[file.InputStream.Length];
            file.InputStream.Read(doc.DocumentFile, 0, doc.DocumentFile.Length);
            System.IO.File.WriteAllBytes(EndPath, doc.DocumentFile);

            MyApp         = new Microsoft.Office.Interop.Excel.Application();
            MyApp.Visible = false;
            MyBook        = MyApp.Workbooks.Open(EndPath);
            MyWorkSheet   = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.Sheets[1];
            using (var db = new DocumentDbContext())
            {
                MyWorkSheet.Cells[3, 3]  = db.Lines.Where(x => x.LineId == LineId).First().LineName;
                MyWorkSheet.Cells[2, 5]  = Title;
                MyWorkSheet.Cells[2, 13] = 1;
                MyWorkSheet.Cells[4, 3]  = db.Operations.Where(x => x.OperationId == OperationId).First().OperationNumber.ToString();
                int      NewId;
                Document temp = db.Documents.FirstOrDefault();
                if (temp == null)
                {
                    doc.DocumentId = 1;;
                    NewId          = 1;
                }
                else
                {
                    NewId = db.Documents.Max(x => x.DocumentId);
                    NewId++;
                }
                doc.DocumentId = NewId;

                UserAccount tempAuthor;
                User        authorUser;

                var    user  = (string)Session["UserName"];
                string index = LineId.ToString() + "-" + OperationId.ToString() + "-" + DocumentTypeId.ToString()
                               + "-" + NewId;
                MyWorkSheet.Cells[5, 5] = db.DocumentTypes.Where(x => x.DocumentTypeId == DocumentTypeId).First().Description;
                MyWorkSheet.Cells[2, 3] = index;

                using (var db1 = new AccountDbContext())
                {
                    tempAuthor = db1.userAccount.Where(x => x.UserName == user).First();
                    authorUser = db.Users.Where(x => x.LastName == tempAuthor.LastName).First();
                    MyWorkSheet.Cells[4, 13] = authorUser.FirstName + " " + authorUser.LastName;
                }
                Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)MyWorkSheet.Cells[1, 17];
                MyWorkSheet.PageSetup.CenterFooter = "Dokument wygenerowany przez program DocumentManager";
                string cellValue = range.Value.ToString();
                MyApp.Save();
                MyBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, EndPathPDF);
                MyBook.Close();
                byte[] f1 = new byte[15728640];
                f1 = System.IO.File.ReadAllBytes(EndPath);
                byte[] fPDF = new byte[15728640];
                fPDF = System.IO.File.ReadAllBytes(EndPathPDF);
                if (cellValue != "INSTRDOC")
                {
                    return(RedirectToAction("ErrorTemplate"));
                }
                else
                {
                    //
                    doc.DocumentFileExcel = f1;
                    doc.DocumentFile      = fPDF;
                    doc.Status            = db.Status.Where(x => x.StatusId == 1).First();
                    doc.Version           = 1;
                    doc.Title             = Title;
                    doc.LineId            = LineId;
                    //nadanie indexu  IdLini-IdOperacji-IdTypuInstruckji-IdPierwszejInstrukcji
                    doc.Index          = index;
                    doc.DateOfAdding   = DateTime.Now;
                    doc.OperationId    = OperationId;
                    doc.DocumentTypeId = DocumentTypeId;
                    doc.AcceptedUserId = AcceptedUserId;
                    doc.AuthorUserId   = authorUser.UserId;
                    db.Documents.Add(doc);
                    db.SaveChanges();

                    if (System.IO.File.Exists(EndPathPDF))
                    {
                        System.IO.File.Delete(EndPathPDF);
                    }
                    if (System.IO.File.Exists(EndPath))
                    {
                        System.IO.File.Delete(EndPath);
                    }
                }
            }
            return(RedirectToAction("RegisterDocument"));
        }
Beispiel #20
0
        public ActionResult MakeActive(int docId)
        {
            //4 status wydana na linie
            using (var db = new DocumentDbContext())
            {
                var    DocExcel     = db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel;
                string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string pathDownload = Path.Combine(pathUser, "Downloads");
                string title        = "temp" + DateTime.Now;
                title = title.Replace("-", "");
                title = title.Replace(":", "");
                string title2     = "temp" + ".pdf";
                string EndPathPDF = Path.Combine(pathDownload, title2);
                string EndPath    = Path.Combine(pathDownload, title);

                int VersionCurrent  = db.Documents.Where(x => x.DocumentId == docId).First().Version;
                int VersionPrevious = VersionCurrent - 1;
                if (VersionCurrent > 1)
                {
                    string index = db.Documents.Where(x => x.DocumentId == docId).First().Index;

                    Models.DocumentData.Document DocumentToArchive = db.Documents.Where(x => x.Index == index).Where(x => x.Version == VersionPrevious).First();
                    DocumentToArchive.Status = db.Status.Where(x => x.StatusId == 5).First();
                    db.SaveChanges();
                }


                //stworzenie tablicy wielkosci
                System.IO.File.WriteAllBytes(EndPath, DocExcel);
                MyApp                    = new Microsoft.Office.Interop.Excel.Application();
                MyApp.Visible            = false;
                MyBook                   = MyApp.Workbooks.Open(EndPath);
                MyWorkSheet              = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.Sheets[1];
                MyWorkSheet.Cells[3, 13] = DateTime.Now.ToShortDateString();
                MyApp.Save();
                MyBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, EndPathPDF);
                MyBook.Close();
                byte[] f1 = new byte[15728640];
                f1 = System.IO.File.ReadAllBytes(EndPath);
                byte[] fPDF = new byte[15728640];
                fPDF = System.IO.File.ReadAllBytes(EndPathPDF);

//zamiana indeksu z 4 na 5 w poprzedniej wersji

                db.Documents.Where(x => x.DocumentId == docId).First().DocumentFile      = fPDF;
                db.Documents.Where(x => x.DocumentId == docId).First().DocumentFileExcel = f1;
                db.Documents.Where(x => x.DocumentId == docId).First().Status            = db.Status.Where(c => c.StatusId == 4).First();

                db.Documents.Where(x => x.DocumentId == docId).First().DateOfPublic = DateTime.Today;
                db.SaveChanges();
                if (System.IO.File.Exists(EndPathPDF))
                {
                    System.IO.File.Delete(EndPathPDF);
                }
                if (System.IO.File.Exists(EndPath))
                {
                    System.IO.File.Delete(EndPath);
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult ShowDoc(HttpPostedFileBase file, string Title,string Index, int AcceptedUserId)
        {
            Document oldDocument;
            Document newDocument;
            using (var db = new DocumentDbContext())
            {
                oldDocument = GetOldOne(db, Index);
                newDocument = GetNewOne(db, Index);
                //stworzenie sciezki do zapisania pliku
                string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string pathDownload = Path.Combine(pathUser, "Downloads");
                string title = Title + DateTime.Now;
                title = title.Replace("-", "");
                title = title.Replace(":", "");
                string title2 = "temp" + ".pdf";
                string EndPath = Path.Combine(pathDownload, title);
                string EndPathPDF = Path.Combine(pathDownload, title2);
                int currentVersion = oldDocument.Version+1;

                //stworzenie tablicy wielkosci 
                newDocument.DocumentFile = new byte[file.InputStream.Length];
                file.InputStream.Read(newDocument.DocumentFile, 0, newDocument.DocumentFile.Length);
                System.IO.File.WriteAllBytes(EndPath, newDocument.DocumentFile);

                MyApp = new Microsoft.Office.Interop.Excel.Application();
                MyApp.Visible = false;
                MyBook = MyApp.Workbooks.Open(EndPath);
                MyWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.Sheets[1];
                MyWorkSheet.Cells[2, 3] = oldDocument.Index;
                MyWorkSheet.Cells[3, 3] = db.Lines.Where(x => x.LineId ==oldDocument.LineId).First().LineName;
                MyWorkSheet.Cells[2, 5] = Title;
                MyWorkSheet.Cells[2, 13] = currentVersion;
                MyWorkSheet.Cells[4, 3] = db.Operations.Where(x => x.OperationId ==oldDocument.OperationId).First().OperationNumber.ToString();
                MyWorkSheet.Cells[5, 5] = db.DocumentTypes.Where(x => x.DocumentTypeId == oldDocument.DocumentTypeId).First().Description;

                UserAccount tempAuthor;
                    User authorUser;

                    var user = (string)Session["UserName"];

                    using (var db1 = new AccountDbContext())
                    {
                        tempAuthor = db1.userAccount.Where(x => x.UserName == user).First();
                        authorUser = db.Users.Where(x => x.LastName == tempAuthor.LastName).First();
                        MyWorkSheet.Cells[4, 13] = authorUser.FirstName + " " + authorUser.LastName;
                    }
                    MyApp.Save();
                    MyBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, EndPathPDF);
                    MyBook.Close();
                    byte[] f1 = new byte[15728640];
                    f1 = System.IO.File.ReadAllBytes(EndPath);

                    byte[] fPDF = new byte[15728640];
                    fPDF = System.IO.File.ReadAllBytes(EndPathPDF);
                    newDocument.DocumentFileExcel = f1;
                    newDocument.DocumentFile = fPDF;
                    newDocument.Status = db.Status.Where(x => x.StatusId == 1).First();
                    newDocument.Version = currentVersion;
                    newDocument.Title = Title;
                    newDocument.LineId =oldDocument.LineId;
                    newDocument.DateOfAdding = DateTime.Now;
                    newDocument.OperationId = oldDocument.OperationId;
                    newDocument.DocumentTypeId = oldDocument.DocumentTypeId;
                    newDocument.AuthorUserId = authorUser.UserId;
                    newDocument.AcceptedUserId = AcceptedUserId;
                    db.Documents.Add(newDocument);
                    db.SaveChanges();
                if (System.IO.File.Exists(EndPath))
                {
                    System.IO.File.Delete(EndPath);
                }
                if (System.IO.File.Exists(EndPathPDF))
                {
                    System.IO.File.Delete(EndPathPDF);
                }

            }
            
            return RedirectToAction("ShowMessage");
        }
Beispiel #22
0
 public Document AddDocument(Document document)
 {
     _context.Documents.Add(document);
     _context.SaveChanges();
     return(document);
 }