Пример #1
0
        public void AddEmployee(String ADGUID, String Email, String FirstName, String LastName, String Username, String IsManager, String ManagerID, String EmpNum, int AuditUserID)
        {
            Employee emp = new Employee
            {
                ADGUID    = new Guid(ADGUID),
                Email     = Email,
                FirstName = FirstName,
                EmpNum    = EmpNum,
                LastName  = LastName,
                Username  = Username,
                IsManager = Convert.ToBoolean(IsManager)
            };

            if (!String.IsNullOrEmpty(ManagerID) && ManagerID != "0")
            {
                emp.ReportsTo = Convert.ToInt32(ManagerID);
            }

            db.Employees.Add(emp);
            db.SaveChanges();

            Employees_Log log = new Employees_Log
            {
                ADGUID     = new Guid(ADGUID),
                Email      = Email,
                FirstName  = FirstName,
                EmpNum     = "",
                LastName   = LastName,
                Username   = Username,
                IsManager  = Convert.ToBoolean(IsManager),
                EmpID      = emp.EmpID,
                ChangeDate = DateTime.Now,
                ChangedBy  = AuditUserID,
                ChangeType = "Insert"
            };

            if (!String.IsNullOrEmpty(ManagerID) && ManagerID != "0")
            {
                log.ReportsTo = Convert.ToInt32(ManagerID);
            }

            db.Employees_Log.Add(log);
            db.SaveChanges();
        }
Пример #2
0
        public void WriteLogonCookie(User user)
        {
            FormsAuthenticationTicket tkt;
            string     cookiestr;
            HttpCookie ck;

            tkt       = new FormsAuthenticationTicket(1, user.Username, DateTime.Now, DateTime.Now.AddMinutes((int)FormsAuthentication.Timeout.TotalMinutes), true, user.Username);
            cookiestr = FormsAuthentication.Encrypt(tkt);
            ck        = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
            ck.Path   = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(ck);

            Login login = new Login {
                LoginDate = DateTime.Now, UserID = user.UserID
            };

            db.Logins.Add(login);
            db.SaveChanges();
        }
Пример #3
0
        public void WriteErrorToLog(String URL, Exception ex, String AdditionalMessage)
        {
            try
            {
                DataLayer.EPSEntities db = new DataLayer.EPSEntities();
                User CurrentUser         = (User)System.Web.HttpContext.Current.Session["CurrentUser"];

                string ErrorText = string.Format("{2}Error Message: {0}, Inner Exception Message: {1}, Trace Data: {3}", ex.Message, ex.InnerException == null ? "None." : ex.InnerException.Message, AdditionalMessage == "" ? "" : AdditionalMessage + " - ", ex.StackTrace);

                ErrorLog error = new ErrorLog {
                    ErrorMessage = URL + " - " + ErrorText, Username = CurrentUser == null ? "Not Logged In" : CurrentUser.Username, ErrorDate = DateTime.Now
                };

                db.ErrorLogs.Add(error);
                db.SaveChanges();
            }
            catch (Exception ex1)
            {
                string dummy = ex1.Message;
            }
        }
Пример #4
0
        public void RunWorkflow()
        {
            WorkflowResult finalResult     = new WorkflowResult();
            String         LastItemRun     = "";
            int            LastRunResultID = 0;

            try
            {
                RunWorkflow run = db.RunWorkflows.Where(r => r.RunID == RunID).FirstOrDefault();

                run.StartTime = DateTime.Now;
                db.SaveChanges();

                List <vwRunItem> items = db.vwRunItems.Where(i => i.RunID == RunID).OrderBy(i => i.RunOrder).ToList();
                RunPayload       pl    = run.RunPayloads.FirstOrDefault();

                foreach (vwRunItem item in items)
                {
                    DateTime    StartTime = DateTime.Now;
                    LibraryItem li        = db.LibraryItems.Where(l => l.ItemID == item.ItemID).FirstOrDefault();

                    if (!String.IsNullOrEmpty(item.HtmlAnswers))
                    {
                        pl = util.SetPayload(RunID, li.ItemID, item.HtmlAnswers);
                    }

                    LastItemRun = li.ItemName;

                    WorkflowItem wfi = db.WorkflowItems.Where(w => w.ItemID == item.ItemID).FirstOrDefault();

                    RunResult rr = new RunResult
                    {
                        ResultString = "",
                        RunID        = RunID,
                        ResultID     = 1,
                        TimeStarted  = DateTime.Now,
                        WFItemID     = wfi.WFItemID
                    };

                    db.RunResults.Add(rr);
                    db.SaveChanges();

                    LastRunResultID = rr.RunResultID;

                    Assembly assembly         = Assembly.LoadFrom(li.LibraryPath);
                    Type     type             = assembly.GetType("ItemToRun.RunWorkflowItem");
                    object   instanceOfMyType = Activator.CreateInstance(type);

                    var result = type.InvokeMember("RunItem",
                                                   BindingFlags.Default | BindingFlags.InvokeMethod,
                                                   null,
                                                   instanceOfMyType,
                                                   new Object[] { run.EmpID, pl == null ? new RunPayload() : pl });

                    IEnumerable <PropertyInfo> props = result.GetType().GetRuntimeProperties();

                    int      ResultID   = Convert.ToInt32(props.ElementAt(0).GetValue(result, null));
                    String   ResultText = props.ElementAt(1).GetValue(result, null).ToString();
                    DateTime TimeDone   = Convert.ToDateTime(props.ElementAt(2).GetValue(result, null));

                    RunResult rrDone = db.RunResults.Where(r => r.RunResultID == rr.RunResultID).FirstOrDefault();

                    rrDone.TimeCompleted = DateTime.Now;
                    rrDone.ResultID      = ResultID;
                    rrDone.ResultString  = ResultText;
                    db.SaveChanges();

                    finalResult = new WorkflowResult {
                        Success = true, ResultString = ""
                    };
                }
            }
            catch (Exception ex)
            {
                finalResult = new WorkflowResult {
                    Success = false, ResultString = String.Format("There was an error during the run in the {0} item.", LastItemRun), FullError = ex
                };

                RunResult rrError = db.RunResults.Where(r => r.RunResultID == LastRunResultID).FirstOrDefault();
                rrError.ResultID      = 4;
                rrError.ResultString  = String.Format("Error: {0}", ex.Message);
                rrError.TimeCompleted = DateTime.Now;
                db.SaveChanges();
            }
        }