public void SaveDescOfWork(string desctext, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflows wf = (from x in db.workflows
                            where x.wfNumber == wfNumber
                            select x).First();

            wf.descofwork = desctext;
            db.SaveChanges();
            LogWFEdits(User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1), wfNumber, "Description of work change");
            return;
        }
        public void SaveDeadlineDate(DateTime deadlineDate, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflows wf = (from x in db.workflows
                            where x.wfNumber == wfNumber
                            select x).First();

            wf.deadline = deadlineDate;
            db.SaveChanges();
            LogWFEdits(User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1), wfNumber, "Deadline date change");
            return;
        }
        public void SaveClientMatter(string ClientMatter, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflows wf = (from x in db.workflows
                            where x.wfNumber == wfNumber
                            select x).First();

            wf.clientmatters = ClientMatter;
            db.SaveChanges();
            LogWFEdits(User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1), wfNumber, "Client Matter change");
            return;
        }
 public void SaveFilesToWorkflow(int wfid)
 {
     //now that the workflow has been created we need to clean up the files that they uploaded and put the workflow ID on them
     using (var db = new DashDBContext())
     {
         foreach (var wffiles in db.workflowfiles.Where(x => x.wfsessionid.Equals(Session.SessionID.ToString())).ToList())
         {
             wffiles.wfID = wfid;
         }
         db.SaveChanges();
     }
     return;
 }
        public void SaveWFTSNewTimeStamp(DateTime newTSDate, Guid wfTSID, string reason)
        {
            DashDBContext db = new DashDBContext();

            workflowtimestamps wf = (from x in db.workflowtimestamps
                                     where x.wftsid == wfTSID
                                     select x).First();

            wf.stamp = newTSDate;
            db.SaveChanges();
            LogWFEdits(User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1), wf.wfNumber, wfTSID + " had the date changed because of " + reason);
            AddNewNote(wfTSID + " had the date changed because of " + reason, wf.wfNumber);
            return;
        }
        public void SaveAttorneyName(string attyID, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflows wf = (from x in db.workflows
                            where x.wfNumber == wfNumber
                            select x).First();

            wf.Requestor = attyID;
            db.SaveChanges();

            LogWFEdits(User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1), wfNumber, "Requesting attorney change");
            return;
        }
        public void SaveDocumentToDB(string filename, string uniquename)
        {
            DashDBContext db = new DashDBContext();

            workflowfiles wff = new workflowfiles
            {
                filename       = filename,
                wfsessionid    = Session.SessionID.ToString(),
                upload_dtim    = DateTime.Now,
                uniquefilename = uniquename
            };

            db.workflowfiles.Add(wff);

            db.SaveChanges();

            return;
        }
        public void AddNewNote(string newnotetext, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflownotes wfnote = new workflownotes
            {
                wfID          = wfNumber,
                wfnote        = newnotetext,
                author        = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1).ToString(),
                notetimestamp = DateTime.Now
            };

            db.workflownotes.Add(wfnote);

            db.SaveChanges();

            return;
        }
        public void ChangeWorkflowStatus(int newstatus, int wfNumber)
        {
            DashDBContext db = new DashDBContext();

            workflowtimestamps wfts = new workflowtimestamps
            {
                wfNumber         = wfNumber,
                workflowstatusID = newstatus,
                stamp            = DateTime.Now,
                participant      = User.Identity.Name.Substring(User.Identity.Name.LastIndexOf('\\') + 1).ToString()
            };

            db.workflowtimestamps.Add(wfts);

            db.SaveChanges();

            return;
        }
        private void LogWFEdits(string tkinit, int wfNumber, string changeevent)
        {
            DashDBContext db = new DashDBContext();

            Edit_Log el = new Edit_Log
            {
                wfNumber    = wfNumber,
                dtim        = DateTime.Now,
                tkinit      = tkinit,
                changeevent = changeevent
            };

            db.Edit_Log.Add(el);

            db.SaveChanges();

            return;
        }
        private void SaveTimeStamp(int wfNumber, int wfstatus, string participant)
        {
            DashDBContext db = new DashDBContext();

            workflowtimestamps t = new workflowtimestamps
            {
                wfNumber         = wfNumber,
                workflowstatusID = wfstatus,
                participant      = participant,
                stamp            = DateTime.Now
            };

            db.workflowtimestamps.Add(t);

            db.SaveChanges();

            return;
        }
        public ActionResult Create([Bind(Exclude = "wfNumber, startdate, enddate", Include = "wfTitle, Requestor, Submitter, createddate, clientmatters, descofwork, deadline")] workflows workflow)
        {
            DashDBContext db = new DashDBContext();

            if (ModelState.IsValid)
            {
                workflow.createddate = DateTime.Now;

                db.workflows.Add(workflow);

                try
                {
                    db.SaveChanges();

                    int wfid = workflow.wfNumber;

                    SaveTimeStamp(wfid, 1, Request.Form["Submitter"].ToString());

                    SaveFilesToWorkflow(wfid);
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return(View());
        }