Пример #1
0
        /// <summary>
        /// Opens document for writing for current user if document is not locked and no one currently reads it.
        /// </summary>
        /// <param name="documentId">The document id.</param>
        /// <param name="loggedUserId">The logged user id.</param>
        /// <returns></returns>
        public bool TryOpenDocumentForWriting(int documentId, int loggedUserId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (DMSDataBaseEntities context = new DMSDataBaseEntities())
                {
                    tDocument document = context.tDocuments.Find(documentId);
                    if (document.IsLocked)
                    {
                        scope.Complete();
                        return(false);
                    }
                    int readers = context.tUserDocuments.Where(u => u.DocumentId == documentId && u.IsReading).Count();
                    if (readers > 0)
                    {
                        scope.Complete();
                        return(false);
                    }

                    tUserDocument ud = context.tUserDocuments.Where(u => u.DocumentId == documentId && u.UserId == loggedUserId).Single();
                    ud.IsWriting      = true;
                    document.IsLocked = true;
                    context.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds new document to system.
        /// </summary>
        /// <param name="documentDto">The document</param>
        /// <param name="ownerId">The owner id = logged user id.</param>
        /// <returns></returns>
        public DocumentDTO SaveNewDocument(DocumentDTO documentDto, int ownerId)
        {
            if (documentDto == null)
            {
                throw new ArgumentNullException("documentDto");
            }

            documentDto.CreatedAt  = DateTime.Now;
            documentDto.IsArchived = false;
            documentDto.IsLocked   = false;
            documentDto.IsValid    = true;

            tDocument result = Mapper.Map <tDocument>(documentDto);

            result.Version   = 1;
            result.Guid      = Guid.NewGuid();
            result.Extension = result.Extension.TrimStart('.');

            result.tKeywords = Mapper.Map <List <tKeyword> >(documentDto.Keywords.ToList());

            foreach (DocumentShareDTO share in documentDto.DocumentShares)
            {
                tUserDocument ud = new tUserDocument();
                ud.IsReading             = false;
                ud.IsWriting             = false;
                ud.UserId                = share.UserId;
                ud.DocumentId            = documentDto.Id;
                ud.DocumentAccessRightId = (int)share.AccessRight;

                result.tUserDocuments.Add(ud);
            }

            tUserDocument owner = new tUserDocument()
            {
                IsReading             = false,
                IsWriting             = false,
                DocumentAccessRightId = (int)DocumentAccessRightCodes.Owner,
                UserId = ownerId
            };

            using (DMSDataBaseEntities context = new DMSDataBaseEntities())
            {
                result = context.tDocuments.Add(result);
                context.SaveChanges();

                owner.DocumentId = result.Id;
                result.tUserDocuments.Add(owner);
                context.SaveChanges();
            }

            AddAdministratorsToDocument(result.Id, ownerId);
            documentDto.Id = result.Id;
            return(documentDto);
        }
Пример #3
0
 /// <summary>
 /// Toggles value of archived flag for specified document.
 /// </summary>
 /// <param name="documentDto">The document dto.</param>
 /// <returns>The modified document dto.</returns>
 public DocumentDTO ToggleArchivedFlag(DocumentDTO documentDto)
 {
     documentDto.IsArchived = !documentDto.IsArchived;
     using (DMSDataBaseEntities context = new DMSDataBaseEntities())
     {
         tDocument document = context.tDocuments.Find(documentDto.Id);
         Mapper.Map(documentDto, document);
         document.Version++;
         context.SaveChanges();
         return(documentDto);
     }
 }
Пример #4
0
        /// <summary>
        /// Sets IsValid property to false for document specified by id.
        /// </summary>
        /// <param name="id">The id of a user.</param>
        public void DeleteDocument(int id)
        {
            BeginTransaction();
            tDocument result = Context.tDocuments.Find(id);

            if (result == null)
            {
                return;
            }
            result.IsValid = false;
            Context.SaveChanges();
            EndTransaction();
        }
Пример #5
0
        /// <summary>
        /// Closes file without saving changes or creating new version.
        /// </summary>
        /// <param name="documentId">The document id.</param>
        /// <param name="userId">The user id.</param>
        public void CloseDocument(int documentId, int userId)
        {
            BeginTransaction();

            tUserDocument ud       = Context.tUserDocuments.Where(u => u.DocumentId == documentId && u.UserId == userId).Single();
            tDocument     document = Context.tDocuments.Find(documentId);

            document.IsLocked = false;
            ud.IsReading      = false;
            ud.IsWriting      = false;
            Context.SaveChanges();

            EndTransaction();
        }
Пример #6
0
        /// <summary>
        /// Updates document title, keywords and sharing with users.
        /// </summary>
        /// <param name="documentDto">The document dto.</param>
        /// <param name="loggedUserId">The logged user id.</param>
        public void UpdateDocumentData(DocumentDTO documentDto, long loggedUserId)
        {
            if (documentDto == null)
            {
                throw new ArgumentNullException("documentDto");
            }

            // operators, not owner, not logged user
            Expression <Func <tUserDocument, bool> > oldShareRestrictions = x => x.DocumentId == documentDto.Id &&
                                                                            x.DocumentAccessRightId != (int)DocumentAccessRightCodes.Owner && x.UserId != loggedUserId && x.tUser.AuthorizationRoleId == (int)AuthorizationRoleCodes.Operator;

            using (DMSDataBaseEntities context = new DMSDataBaseEntities())
            {
                tDocument document = context.tDocuments.Find(documentDto.Id);
                document.tKeywords.Clear();
                document.tKeywords = Mapper.Map <List <tKeyword> >(documentDto.Keywords.ToList());

                document.LastModifiedAt = DateTime.Now;
                document.Version++;
                document.Title = documentDto.Title;

                IEnumerable <tUserDocument> oldShared = context.tUserDocuments.Where(oldShareRestrictions);
                foreach (tUserDocument ud in oldShared)
                {
                    context.tUserDocuments.Remove(ud);
                }

                foreach (DocumentShareDTO share in documentDto.DocumentShares)
                {
                    tUserDocument ud = new tUserDocument();
                    ud.IsReading             = false;
                    ud.IsWriting             = false;
                    ud.UserId                = share.UserId;
                    ud.DocumentId            = documentDto.Id;
                    ud.DocumentAccessRightId = (int)share.AccessRight;

                    document.tUserDocuments.Add(ud);
                }

                context.SaveChanges();
            }
        }
Пример #7
0
        public void FinalSaveToDBtDocument(string SessionID, long ReferenceID, string UserID, string TargetObjectName, string HttpAppPath, string[] conn)
        {
            try
            {
                BISPL_CRMDBEntities ce = new BISPL_CRMDBEntities(svr.GetEntityConnection(conn));
                List <SP_GetDocumentList_Result> paraobjList = new List <SP_GetDocumentList_Result>();
                paraobjList = GetTempDataByObjectNameSessionID(SessionID, UserID, TargetObjectName, conn).Where(d => d.Active == "Y" && d.ID == null).ToList();

                foreach (var v in paraobjList)
                {
                    string    TempSaveAsPath;
                    tDocument objDocument = new tDocument();
                    objDocument.ObjectName   = TargetObjectName.ToString();
                    objDocument.ReferenceID  = Convert.ToInt64(ReferenceID);
                    objDocument.DocumentName = v.DocumentName;
                    objDocument.Sequence     = Convert.ToInt64(v.Sequence);
                    objDocument.Description  = v.Description;
                    // objDocument.DocumentDownloadPath = "../Document/Attach_Document/" + v.CompanyID.ToString() + "/";//v.DocumentPath;
                    objDocument.DocumentDownloadPath = "../Document/Attach_Document/" + ReferenceID.ToString() + "/" + v.DocumentName.ToString();
                    TempSaveAsPath = v.DocumentSavePath;
                    // objDocument.DocumentSavePath = HttpAppPath + "Document\\Attach_Document\\" + v.CompanyID.ToString() + "\\";
                    objDocument.DocumentSavePath = HttpAppPath + "Document\\Attach_Document\\" + ReferenceID.ToString() + "\\";
                    objDocument.Keywords         = v.Keywords;
                    objDocument.FileType         = v.FileType;
                    objDocument.AccessTo         = v.AccessTo;/*document type or extension*/
                    objDocument.ViewAccess       = v.ViewAccess_Value;
                    objDocument.DowloadAccess    = v.DowloadAccess_Value;
                    objDocument.DeleteAccess     = v.DeleteAccess_Value;
                    objDocument.Active           = v.Active;
                    objDocument.CreatedBy        = v.CreatedBy;
                    objDocument.CreationDate     = Convert.ToDateTime(v.CreationDate);
                    objDocument.CustomerHeadID   = Convert.ToInt64(v.CustomerHeadID);
                    objDocument.CompanyID        = Convert.ToInt64(v.CompanyID);
                    objDocument.DocumentType     = v.DocumentType;

                    ce.tDocuments.AddObject(objDocument);
                    ce.SaveChanges();
                    /* For File Move form Temp To Main*/
                    //if (!(Directory.Exists(HttpAppPath + "Document\\Attach_Document\\" + v.CompanyID.ToString())))
                    //{
                    //    Directory.CreateDirectory(HttpAppPath + "Document\\Attach_Document\\" + v.CompanyID.ToString());
                    //}

                    if (!(Directory.Exists(objDocument.DocumentSavePath)))
                    {
                        Directory.CreateDirectory(objDocument.DocumentSavePath);
                    }

                    // File.Move(TempSaveAsPath, objDocument.DocumentSavePath + objDocument.ID.ToString() + "." + v.FileType);
                    File.Move(TempSaveAsPath, objDocument.DocumentSavePath + objDocument.DocumentName.ToString() + "." + v.FileType);

                    tDocumentDetail objDocumentDtls = new tDocumentDetail();
                    objDocumentDtls.ObjectName  = TargetObjectName.ToString();
                    objDocumentDtls.ReferenceID = Convert.ToInt64(ReferenceID);
                    objDocumentDtls.DocumentID  = Convert.ToInt64(objDocument.ID);
                    ce.tDocumentDetails.AddObject(objDocumentDtls);
                    ce.SaveChanges();
                }

                paraobjList = GetTempDataByObjectNameSessionID(SessionID, UserID, TargetObjectName, conn).Where(d => d.Active == "Y" && d.ID != null).ToList();
                foreach (var v in paraobjList)
                {
                    if (ce.tDocumentDetails.Where(d => d.ObjectName == TargetObjectName && d.ReferenceID == ReferenceID && d.DocumentID == v.ID).Count() == 0)
                    {
                        tDocumentDetail objDocumentDtls = new tDocumentDetail();
                        objDocumentDtls.ObjectName  = TargetObjectName.ToString();
                        objDocumentDtls.ReferenceID = Convert.ToInt64(ReferenceID);
                        objDocumentDtls.DocumentID  = Convert.ToInt64(v.ID);
                        ce.tDocumentDetails.AddObject(objDocumentDtls);
                        ce.SaveChanges();
                    }
                }

                paraobjList = GetTempDataByObjectNameSessionID(SessionID, UserID, TargetObjectName, conn).Where(d => d.Active == "N" && d.ID != null).ToList();
                foreach (var v in paraobjList)
                {
                    tDocumentDetail docdetail = ce.tDocumentDetails.Where(d => d.ObjectName == TargetObjectName && d.ReferenceID == ReferenceID && d.DocumentID == v.ID).FirstOrDefault();
                    ce.tDocumentDetails.DeleteObject(docdetail);
                    ce.SaveChanges();
                }

                //ClearTempData(SessionID, UserID, TargetObjectName, conn);
            }
            catch (Exception ex) { }
        }