Exemple #1
0
        public static void SendEmail(AryaTask job, bool includeLogUrl, string customStatus, string projectName, string emailAddress, string portalLocation)
        {
            var subject = String.Format("{0}: {1}", job.JobType.Spacify(), job.Description);
            //var to = aryaDb.CurrentUser.EmailAddress;
            var to          = emailAddress;
            var messageBody = String.Format(@"
    Project Name: {0}
    Description: {1}
    Status: {2}", projectName, job.Description, customStatus ?? WorkerBase.GetFriendlyWorkerState((WorkerState)Enum.Parse(typeof(WorkerState), job.Status)));

            if (includeLogUrl)
            {
                messageBody += String.Format("{0}{0}Log file can be viewed here: {1}/Log.aspx?ID={2}", Environment.NewLine,
                                             portalLocation, job.ID);
            }

            EmailSender.SendEmail(to, messageBody, subject);
        }
Exemple #2
0
        private void BindGridView(bool clearAllFilters = false)
        {
            using (var aryaDc = new AryaDbDataContext())
            {
                var currUser = (from u in aryaDc.Users where u.EmailAddress == Email select u).FirstOrDefault();
                if (currUser == null)
                {
                    FormsAuthentication.RedirectToLoginPage();
                    return;
                }

                using (var taskDc = new AryaServicesDbDataContext())
                {
                    var tasks = Enumerable.Empty <AryaTask>().AsQueryable();
                    if (currUser.IsAdmin)
                    {
                        tasks = taskDc.AryaTasks;
                    }
                    else
                    {
                        //Import Admin Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ImportAdminGroup,
                                                 new[] { typeof(ImportWorker).Name }, false));
                        //Import User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ImportUserGroup,
                                                 new[] { typeof(ImportWorker).Name }, true));

                        var exportJobTypes = ExportWorkerBase.GetExports().Select(e => e.GetType().Name).ToList();
                        //Export Admin Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ExportAdminGroup,
                                                 exportJobTypes.Union(typeof(CustomExportWorker).Name), false));
                        //Standard Export User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.StandardExportUserGroup,
                                                 exportJobTypes, true));
                        //Custom Export User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.CustomExportUserGroup,
                                                 new[] { typeof(CustomExportWorker).Name }, true));
                    }

                    if (!clearAllFilters)
                    {
                        Guid selectedProject, selectedUser;
                        if (Guid.TryParse(DdlProjects.SelectedValue, out selectedProject))
                        {
                            tasks = tasks.Where(task => task.ProjectID == selectedProject);
                        }

                        if (Guid.TryParse(DdlSubmittedBy.SelectedValue, out selectedUser))
                        {
                            tasks = tasks.Where(task => task.SubmittedBy == selectedUser);
                        }

                        var selectedJobType = DdlJobType.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(selectedJobType) && selectedJobType != "ALL")
                        {
                            tasks = tasks.Where(task => task.JobType == DdlJobType.SelectedValue);
                        }

                        var selectedStatus = DdlStatus.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(selectedStatus) && selectedStatus != "ALL")
                        {
                            tasks = tasks.Where(task => task.Status == DdlStatus.SelectedValue);
                        }
                    }
                    var allTasks = tasks.OrderByDescending(task => task.SubmittedOn).Take(100).ToList();

                    var distinctUserProjects =
                        allTasks.Select(t => t.SubmittedBy + "|" + t.ProjectID).Distinct().ToList();
                    var userProjects = (from up in aryaDc.UserProjects
                                        //from task in tasks.ToList()
                                        //where task.SubmittedBy == up.UserID && task.ProjectID == up.ProjectID
                                        where distinctUserProjects.Contains(up.UserID + "|" + up.ProjectID)
                                        select new { up.User, up.Project }).ToList();

                    var visibleTasks = from task in allTasks
                                       from up in userProjects
                                       where up.Project.ID == task.ProjectID && up.User.ID == task.SubmittedBy
                                       let project                                                           = up.Project
                                                                            let user                         = up.User
                                                                                                   let state =
                        WorkerBase.GetFriendlyWorkerState(
                            (WorkerState)Enum.Parse(typeof(WorkerState), task.Status))
                        orderby task.SubmittedOn descending
                        select
                        new
                    {
                        task.ID,
                        task.ProjectID,
                        ProjectName = project.DisplayName,
                        Type        = task.DisplayJobType,
                        task.JobType,
                        task.Description,
                        task.Status,
                        FriendlyStatus = state,
                        user.FullName,
                        task.SubmittedBy,
                        task.SubmittedOn
                    };

                    if (sortExpression != string.Empty)
                    {
                        visibleTasks = LinqExtensions.ApplyOrder(visibleTasks, sortExpression,
                                                                 sortOrder == "asc" ? "OrderBy" : "OrderByDescending");
                    }

                    var visibleTaskList = visibleTasks.Distinct().ToList();
                    GvStatus.DataSource = visibleTaskList;
                    GvStatus.DataBind();

                    if (visibleTaskList.Count == 0)
                    {
                        return;
                    }

                    if (!Page.IsPostBack)
                    {
                        var projects =
                            userProjects.Select(
                                up =>
                                new DropDownListItem
                        {
                            Text  = up.Project.DisplayName,
                            Value = up.Project.ID.ToString()
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["projects"] = projects;

                        var users =
                            userProjects.Select(
                                up => new DropDownListItem {
                            Text = up.User.FullName, Value = up.User.ID.ToString()
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["users"] = users;

                        var jobTypes =
                            allTasks.Select(
                                task => new DropDownListItem {
                            Text = task.DisplayJobType, Value = task.JobType
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["jobTypes"] = jobTypes;

                        var statuses =
                            allTasks.Select(task => new DropDownListItem {
                            Text = task.Status, Value = task.Status
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["statuses"] = statuses;
                    }

                    var prjs            = Session["projects"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visibleProjects =
                        prjs.Where(prj => visibleTaskList.Any(task => task.ProjectID.ToString() == prj.Value)).ToList();
                    visibleProjects.Insert(visibleProjects.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visibleProjects.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visibleProjects.AddRange(prjs.Where(prj => !visibleProjects.Contains(prj)));
                    DdlProjects.DataSource = visibleProjects;
                    DdlProjects.DataBind();

                    var usrs         = Session["users"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visibleusers =
                        usrs.Where(usr => visibleTaskList.Any(task => task.SubmittedBy.ToString() == usr.Value))
                        .ToList();
                    visibleusers.Insert(visibleusers.Count > 1 ? 0 : 1,
                                        new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visibleusers.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visibleusers.AddRange(usrs.Where(usr => !visibleusers.Contains(usr)));
                    DdlSubmittedBy.DataSource = visibleusers;
                    DdlSubmittedBy.DataBind();

                    var jbts            = Session["jobTypes"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visiblejobTypes =
                        jbts.Where(jbt => visibleTaskList.Any(task => task.JobType == jbt.Value)).ToList();
                    visiblejobTypes.Insert(visiblejobTypes.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visiblejobTypes.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visiblejobTypes.AddRange(jbts.Where(jbt => !visiblejobTypes.Contains(jbt)));
                    DdlJobType.DataSource = visiblejobTypes;
                    DdlJobType.DataBind();

                    var stus            = Session["statuses"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visiblestatuses =
                        stus.Where(stu => visibleTaskList.Any(task => task.Status == stu.Value)).ToList();
                    visiblestatuses.Insert(visiblestatuses.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visiblestatuses.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visiblestatuses.AddRange(stus.Where(stu => !visiblestatuses.Contains(stu)));
                    DdlStatus.DataSource = visiblestatuses;
                    DdlStatus.DataBind();
                }
            }
        }