示例#1
0
        public QPVersion VersionDetails(string versionId)
        {
            QPVersion ver = new QPVersion();

            try
            {
                ver = (from v in Context.QPVersions where v.VersionId == versionId select v).FirstOrDefault();
            }
            catch (Exception)
            {
                ver = null;
            }
            return(ver);
        }
示例#2
0
        public bool UpdateDocumentVersion(QPMasterPool doc)
        {
            QPVersion version = new QPVersion();
            string    versionId;
            bool      status = false;

            try
            {
                var oldDoc = (from d in Context.QPMasterPools where d.QPDocId == doc.QPDocId select d).FirstOrDefault <QPMasterPool>();
                var ver    = (from v in Context.QPVersions where v.DocId == oldDoc.QPDocId select v.VersionId).ToList();
                version.Comments     = oldDoc.Comments;
                version.CreationLog  = oldDoc.CreationLog;
                version.DocId        = oldDoc.QPDocId;
                version.Document     = oldDoc.Document;
                version.DocumentName = oldDoc.DocumentName;
                version.UpdationLog  = oldDoc.UpdationLog;
                //-------------------------------------
                if (ver.Count == 0)
                {
                    versionId         = Regex.Match(oldDoc.QPDocId, @"\d+").Value;
                    versionId        += ".1";
                    version.VersionId = versionId;
                }
                else
                {
                    int length = 0;
                    foreach (var item in ver)
                    {
                        if (item.Length > length)
                        {
                            length = item.Length;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    ver.RemoveAll(x => x.Length < length);
                    string   vers  = ver.Max();
                    string[] parts = vers.Split('.');
                    int      i1    = int.Parse(parts[0]);
                    int      i2    = int.Parse(parts[1]);
                    i2               += 1;
                    vers              = i1.ToString() + "." + i2.ToString();
                    versionId         = vers;
                    version.VersionId = versionId;
                }
                //----------------------------------------
                Context.QPVersions.Add(version);
                Context.SaveChanges();
                status = true;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            return(status);
        }