Exemplo n.º 1
0
        public static void Seed()
        {
            TakeMyTimeDbContext context = new TakeMyTimeDbContext();

            bool hasProjectTypes = context.ProjectTypes != null && context.ProjectTypes.Any();

            if (!hasProjectTypes)
            {
                var projectTypes = ProjectTypeFactory.SeedProjectTypes();
                context.ProjectTypes.AddRange(projectTypes);
                context.SaveChanges();

                var projects = ProjectFactory.SeedProjects(projectTypes.ToArray());
                context.Projects.AddRange(projects);
                context.SaveChanges();
            }

            bool hasAssignments = context.Assignments != null && context.Assignments.Any();

            if (!hasAssignments)
            {
                var projects    = context.Projects.ToList();
                var assignments = AssignmentFactory.CreateAssignments(projects.ToArray());
                context.Assignments.AddRange(assignments);
                context.SaveChanges();
            }

            bool hasSubtasks = context.Subtasks != null && context.Subtasks.Any();

            if (!hasSubtasks)
            {
                var assignments = context.Assignments.ToList();
                var subtasks    = new List <Subtask>();
                foreach (var assignment in assignments)
                {
                    subtasks.AddRange(SubtaskFactory.Create(assignment));
                }

                context.Subtasks.AddRange(subtasks);
                context.SaveChanges();
            }

            bool hasEntries = context.Entries != null && context.Entries.Any();

            if (!hasEntries)
            {
                var subtasks = context.Subtasks
                               .Include(s => s.Assignment)
                               .Include(s => s.Assignment.Project)
                               .ToList();
                var entries = new List <Entry>();
                foreach (var subtask in subtasks)
                {
                    entries.AddRange(EntryFactory.Create(subtask));
                }

                context.Entries.AddRange(entries);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source.
		/// </summary>
		/// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"/> that contains the values to bind to the control.</param>
		/// <param name="dataBinding">true to indicate that the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/> is called during data binding; otherwise, false.</param>
		/// <returns>
		/// The number of items created by the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/>.
		/// </returns>
		protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
		{
			InitImages(this.CurrentContainer.Page);
			divContainer = new Panel();
			divInnerContainer = new Panel();
			divIcons = new Panel();
			divSubIcons = new Panel();

			divIcons.CssClass = "iconBlock";
			divSubIcons.CssClass = "subiconBlock";
			divContainer.CssClass = "itemcontainerBlock";
			divInnerContainer.CssClass = "innerContainerBlock";

			#region Create and init controls
			#region ddType/lblType/extType
			ddType = new DropDownList();
			ddType.ID = this.ID + "_ddType";
			List<string> typeItems = AssignmentFactory.GetAvailableActivities();
			ddType.Items.Add(new ListItem("New activity", "0"));

			foreach (String s in typeItems)
			{
				ddType.Items.Add(new ListItem(s, s));
			}

			ddType.AutoPostBack = true;
			ddType.SelectedIndexChanged += new EventHandler(ddType_SelectedIndexChanged);
			ddType.Style.Add(HtmlTextWriterStyle.Display, "none");

			lblType = new Label();
			lblType.Text = this.CurrentContainer.AddText;
			lblType.Visible = (this.CurrentActivity is CompositeActivity);
			lblType.ID = this.ID + "_lblType";
			lblType.CssClass = "createAssignmentLink";
			if (!String.IsNullOrEmpty(this.CurrentContainer.NewActivityScript))
			{
				//string parentActivity = string.Empty;
				//if (this.CurrentActivity.Parent != null)
				//    parentActivity = this.CurrentActivity.Parent.Name;
				//else
				//    parentActivity = this.CurrentActivity.Name;

				string _newActivityScript = this.CurrentContainer.NewActivityScript.Replace("_parentName_", this.CurrentActivity.Name);
				lblType.Attributes.Add("onclick", _newActivityScript);
			}

			//extType = new HiderExtender();
			//extType.ID = this.ID + "_extType";

			//extType.TargetControlID = ddType.ID;
			#endregion

			#region ddPrototype
			ddPrototype = new DropDownList();
			ddPrototype.Items.AddRange(this.Prototypes.ToArray());
			ddPrototype.DataBind(); 
			#endregion

			#region button Create
			btnCreate = new Button();
			btnCreate.Text = "Add";
			btnCreate.ID = this.ID + "_btnCreate";
			btnCreate.Click += new EventHandler(btnCreate_Click);
			#endregion

			#region button Delete
			btnDelete = new ImageButton();
			//btnDelete.Text = "Delete";
			btnDelete.OnClientClick = String.Format("return confirm('{0}');", this.CurrentContainer.DeleteText);
			btnDelete.ImageUrl = _imageDenyUrl;
			btnDelete.Click += new ImageClickEventHandler(btnDelete_Click);
			#endregion

			#region btnUp
			btnUp = new ImageButton();
			//btnUp.Text = "Up";
			btnUp.ImageUrl = _imageUpUrl;
			btnUp.Click += new ImageClickEventHandler(btnUp_Click);
			#endregion

			#region btnDown
			btnDown = new ImageButton();
			//btnDown.Text = "Down";
			btnDown.ImageUrl = _imageDownUrl;
			btnDown.Click += new ImageClickEventHandler(btnDown_Click);
			#endregion

			#region btnEdit
			btnEdit = new Button();
			btnEdit.Text = "Edit prototype";
			btnEdit.Click += new EventHandler(btnEdit_Click);
			#endregion 

			lblEditPrototype = new HtmlGenericControl("DIV");
			lblEditPrototype.Attributes.Add("class", "editPrototypeLabel");
			lblEditPrototype.InnerHtml = string.Format("<img src='{0}' border='0'/><span>{1}</span>", this.ResolveUrl(_imageEditUrl), this.CurrentContainer.EditText);
			if (!String.IsNullOrEmpty(this.CurrentContainer.EditActivityScript))
			{
				string _editActivityScript = this.CurrentContainer.EditActivityScript.Replace("_activityName_", this.CurrentActivity.Name);
				lblEditPrototype.Attributes.Add("onclick", _editActivityScript);
			}
			lblEditPrototype.Visible = (WorkflowActivityWrapper.GetActivityMaster(this.CurrentContainer.CurrentSchemaMaster, this.CurrentActivity, this.CurrentActivity.Name) != null);
			//if (this.CurrentContainer.CurrentSchemaMaster
//			lblEditPrototype.Attributes.Add("onclick", "");

			#endregion

			divContainer.ID = this.ID + "_divContainer";
			divContainer.Style.Add(HtmlTextWriterStyle.Display, "inline");
			Control c = AssignmentFactory.GetActivityPrimitive(this.CurrentActivity, this.CurrentContainer.CurrentSchemaMaster, this.CurrentContainer.Page);
			//extType.TestPerform(lblType.ClientID);
			#region Create inner control structure
			if (c != null)
			{
				divInnerContainer.Controls.Add(c);
				((MCDataBoundControl)c).DataItem = this.CurrentActivity;
				((MCDataBoundControl)c).DataBind();
			}

			divIcons.Controls.Add(btnDelete);
			divIcons.Controls.Add(btnUp);
			divIcons.Controls.Add(btnDown);

			divIcons.Controls.Add(ddType);
			divIcons.Controls.Add(lblType);
			//divIcons.Controls.Add(extType);

			//divIcons.Controls.Add(lblEditPrototype);

			btnCreate.Visible = false;
			divIcons.Controls.Add(btnCreate);

			divSubIcons.Controls.Add(ddPrototype);
			divSubIcons.Controls.Add(btnEdit);
			divIcons.Controls.Add(lblEditPrototype);

			divContainer.Controls.Add(divIcons);
			divContainer.Controls.Add(divSubIcons);
			divContainer.Controls.Add(divInnerContainer); 
			#endregion

			this.Controls.Add(divContainer);
			//this.Controls.Add(extType);

			return 1;
		}
Exemplo n.º 3
0
 public InitializationRule(string pattern, SourceTypeEnum source, params object[] parameters)
 {
     Pattern          = pattern;
     AssignmentAction = AssignmentFactory.Create(source);
     Parameters       = parameters;
 }
Exemplo n.º 4
0
 public RuleWithParameters(InitRule initRule)
 {
     Pattern          = initRule.Pattern;
     AssignmentAction = AssignmentFactory.Create(initRule.SourceType);
     Parameters       = initRule.Parameters;
 }