コード例 #1
0
ファイル: SpreadsheetController.cs プロジェクト: Zowal/Oasis
        public ActionResult SpreadsheetPartial(long tableId)
        {
            ViewBag.TableId = tableId;
            ViewBag.LastSyncDateTime = DateTime.Now;

            var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id;

            if (IsUserAdmin(userId, tableId))
            {
                ViewBag.Admin = true;
            }
            else if (UserHelper.UserIsRedactor(userId, tableId))
            {
                var redactor = redactorRepository.Find(u => u.UserId_Id == userId && u.TableId == tableId);
                ViewBag.Admin = redactor.IsReadOnly;
                redactor.LastAccesDate = DateTime.Now;
                redactorRepository.Commit();
            }
            else
            {
                ViewBag.Admin = false;
            }

            string path = null;
            var dateTime = DateTime.Now;
            var backups = backupsRepository.FindAll(w => w.SpreadsheetID_Id == tableId).OrderBy(b => b.DateOfCreate).ToList();
            var backup = backups.Count > 0 ? backups.Last() : null;
            var CurrentTable = spreadsheetRepository.Find(w => w.Id == tableId);

            if (backup != null && (backup.DateOfCreate.DayOfYear - CurrentTable.CreationDate.DayOfYear) != 0)
            {
                if(backups.Count == 7)
                {
                    backupsRepository.Delete(backups.First());
                }

                string tableName = Guid.NewGuid().ToString();

                path = Server.MapPath(PathConstants.EmptyPath);

                string guidName = Server.MapPath(PathConstants.XlsPath) + tableName;

                if (path != null && !System.IO.File.Exists(guidName))
                {
                    System.IO.File.Copy(CurrentTable.GuidName, guidName);
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(guidName);

                    Model.BackupsOfSpreadsheetsFile spreadsheet = new BackupsOfSpreadsheetsFile
                    {
                        SpreadsheetID_Id = tableId,
                        Size = fileInfo.Length,
                        DateOfCreate = dateTime,
                        GuidName = guidName
                    };

                    backupsRepository.Add(spreadsheet);
                    backupsRepository.Commit();
                }
            }
            else
            {
                string tableName = Guid.NewGuid().ToString();

                path = Server.MapPath(PathConstants.EmptyPath);

                string guidName = Server.MapPath(PathConstants.XlsPath) + tableName;

                if (path != null && !System.IO.File.Exists(guidName))
                {
                    System.IO.File.Copy(CurrentTable.GuidName, guidName);
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(guidName);

                    Model.BackupsOfSpreadsheetsFile spreadsheet = new BackupsOfSpreadsheetsFile
                    {
                        SpreadsheetID_Id = tableId,
                        Size = fileInfo.Length,
                        DateOfCreate = dateTime,
                        GuidName = guidName
                    };

                    backupsRepository.Add(spreadsheet);
                    backupsRepository.Commit();
                }
            }

            IWorkbook book = SpreadsheetExtension.GetCurrentDocument("spreadsheet");
            byte[] docBytes = book.SaveDocument(DocumentFormat.Xlsx);
            path = SpreadsheetHelper.GetSpreadsheetPathById(tableId);

            if (path != null)
            {
                CurrentTable.Size = docBytes.Length;
                CurrentTable.DateOfLastChange = dateTime;
                spreadsheetRepository.Commit();
                System.IO.File.WriteAllBytes(path, docBytes);
            }

            ViewBag.FilePath = path;

            return PartialView("SpreadsheetPartial");
        }
コード例 #2
0
 partial void DeleteBackupsOfSpreadsheetsFile(BackupsOfSpreadsheetsFile instance);
コード例 #3
0
 partial void InsertBackupsOfSpreadsheetsFile(BackupsOfSpreadsheetsFile instance);
コード例 #4
0
 partial void UpdateBackupsOfSpreadsheetsFile(BackupsOfSpreadsheetsFile instance);
コード例 #5
0
		private void detach_BackupsOfSpreadsheetsFiles(BackupsOfSpreadsheetsFile entity)
		{
			this.SendPropertyChanging();
			entity.TableModels = null;
		}