/// <summary>
 /// Create a new ToDo object.
 /// </summary>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="dueDate">Initial value of the DueDate property.</param>
 public static ToDo CreateToDo(global::System.String name, global::System.Int32 id, global::System.String description, global::System.DateTime dueDate)
 {
     ToDo toDo = new ToDo();
     toDo.Name = name;
     toDo.id = id;
     toDo.Description = description;
     toDo.DueDate = dueDate;
     return toDo;
 }
示例#2
0
        public static int[] UpdatePage(List<ToDoView> itemsI, List<ToDoView> itemsM, List<int> toDelete)
        {
            if (itemsM == null && itemsI == null && toDelete == null) return new int[0];
            List<ToDo> inserted = new List<ToDo>();
            using (SiteDbEntities context = new SiteDbEntities())
            {
                bool aChange = false;
                if (itemsI != null)
                {
                    foreach (ToDoView item in itemsI)
                    {
                        ToDo curr = new ToDo() { Name = item.Name, Description = item.Description, DueDate = item.DueDate };
                        aChange = true;
                        context.ToDo.AddObject(curr);
                        inserted.Add(curr);
                    }
                }
                if (itemsM != null)
                {
                    foreach (ToDoView item in itemsM)
                    {
                        ToDo curr = new ToDo() { Name = item.Name, Description = item.Description, DueDate = item.DueDate, id = item.id.Value };
                        context.ToDo.Attach(curr);
                        context.ObjectStateManager.ChangeObjectState(curr, System.Data.EntityState.Modified);
                        aChange = true;
                    }
                }
                if (toDelete != null)
                {
                    foreach (int key in toDelete)
                    {
                        ToDo curr = new ToDo() { id = key };
                        context.ToDo.Attach(curr);
                        context.ObjectStateManager.ChangeObjectState(curr, System.Data.EntityState.Deleted);
                        aChange = true;
                    }
                }
                if (aChange)
                {
                    try
                    {
                        context.SaveChanges();

                    }
                    catch
                    {
                    }
                    return inserted.Select(m => m.id).ToArray();
                }
                else return new int[0];
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ToDo EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToToDo(ToDo toDo)
 {
     base.AddObject("ToDo", toDo);
 }