Exemple #1
0
        /// <summary>
        /// Create a new BacklogItem object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        /// <param name="projectId">Initial value of the ProjectId property.</param>
        /// <param name="description">Initial value of the Description property.</param>
        /// <param name="weight">Initial value of the Weight property.</param>
        /// <param name="spent">Initial value of the Spent property.</param>
        public static BacklogItem CreateBacklogItem(global::System.String id, global::System.String projectId, global::System.String description, global::System.Double weight, global::System.Double spent)
        {
            BacklogItem backlogItem = new BacklogItem();

            backlogItem.Id          = id;
            backlogItem.ProjectId   = projectId;
            backlogItem.Description = description;
            backlogItem.Weight      = weight;
            backlogItem.Spent       = spent;
            return(backlogItem);
        }
        private void SaveBacklogItem(ScrumFactoryEntities context, BacklogItem item, bool saveHours)
        {
            // dont want to add the item group again, so if the group is already at the database
                // remove it from the item
                BacklogItemGroup group = context.BacklogItemGroups.SingleOrDefault(g => g.GroupUId == item.GroupUId);
                if (group != null)
                    item.Group = null;

                BacklogItem oldItem = GetBacklogItem(context, item.BacklogItemUId);

                // if is a new item insert it
                if (oldItem == null) {
                    int? lastNumber = context.BacklogItems.Where(b => b.ProjectUId == item.ProjectUId).Max(b => (int?)b.BacklogItemNumber);
                    if (lastNumber == null)
                        lastNumber = 0;
                    item.BacklogItemNumber = (int)lastNumber + 1;
                    context.BacklogItems.AddObject(item);
                }
                else {

                    // updates the item
                    context.AttachTo("BacklogItems", oldItem);
                    context.ApplyCurrentValues<BacklogItem>("BacklogItems", item);

                    if (saveHours) {

                        // detect the changes
                        var insertedHours = item.PlannedHours;
                        if (oldItem.PlannedHours != null)
                            insertedHours = item.PlannedHours.Where(p => !oldItem.PlannedHours.Any(o => (o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId && o.PlanningNumber == p.PlanningNumber))).ToList();

                        // ATTENTION HERE: DID NOT INCLUDE THE o.PlanningNumber == p.PlanningNumber BECAUSE I DONT WANT TO DELETE OLD PLANNINGS
                        var deletedHours = new List<PlannedHour>();
                        if (oldItem.PlannedHours != null)
                            deletedHours = oldItem.PlannedHours.Where(o => !item.PlannedHours.Any(p => o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId)).ToList();

                        var updatedHours = new List<PlannedHour>();
                        if (oldItem.PlannedHours != null)
                            updatedHours = item.PlannedHours.Where(p => oldItem.PlannedHours.Any(o => o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId && o.PlanningNumber == p.PlanningNumber)).ToList();

                        // insert, update and delete
                        foreach (PlannedHour p in updatedHours)
                            context.ApplyCurrentValues<PlannedHour>("PlannedHours", p);
                        foreach (PlannedHour p in insertedHours)
                            context.AddObject("PlannedHours", p);
                        foreach (PlannedHour p in deletedHours)
                            context.DeleteObject(p);

                    }

                }
        }
 private void SaveBacklogItem(BacklogItem item, bool saveHours)
 {
     using (var context = new ScrumFactoryEntities(this.connectionString)) {
         SaveBacklogItem(context, item, saveHours);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Saves a backlog item, but ignores it hours.
 /// </summary>
 /// <param name="item">The item to be saved</param>
 public void SaveBacklogItemIgnoreHours(BacklogItem item)
 {
     // I dont want to use a transaction to get a safe next backlog item number
     // because the SERIALIZABLE isolaton level will lock the whole table.
     // Better than that, i would rather try to update severel times until i got a valid number.
     TryAgainSave(() => { SaveBacklogItem(item, false); });
 }
Exemple #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BacklogItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBacklogItems(BacklogItem backlogItem)
 {
     base.AddObject("BacklogItems", backlogItem);
 }
Exemple #6
0
        private void SaveBacklogItem(ScrumFactoryEntities context, BacklogItem item, bool saveHours)
        {
            // dont want to add the item group again, so if the group is already at the database
            // remove it from the item
            BacklogItemGroup group = context.BacklogItemGroups.SingleOrDefault(g => g.GroupUId == item.GroupUId);

            if (group != null)
            {
                item.Group = null;
            }

            BacklogItem oldItem = GetBacklogItem(context, item.BacklogItemUId);

            // if is a new item insert it
            if (oldItem == null)
            {
                int?lastNumber = context.BacklogItems.Where(b => b.ProjectUId == item.ProjectUId).Max(b => (int?)b.BacklogItemNumber);
                if (lastNumber == null)
                {
                    lastNumber = 0;
                }
                item.BacklogItemNumber = (int)lastNumber + 1;

                if (item.BusinessPriority == 0)
                {
                    int?lastPriority = context.BacklogItems.Where(b => b.ProjectUId == item.ProjectUId).Max(b => (int?)b.BusinessPriority);
                    if (lastPriority == null)
                    {
                        lastPriority = 1;
                    }
                    else
                    {
                        lastPriority = lastPriority + 10;
                    }
                    item.BusinessPriority = lastPriority.Value;
                }

                context.BacklogItems.AddObject(item);
            }
            else
            {
                // updates the item
                context.AttachTo("BacklogItems", oldItem);
                context.ApplyCurrentValues <BacklogItem>("BacklogItems", item);

                if (saveHours)
                {
                    // detect the changes
                    var insertedHours = item.PlannedHours;
                    if (oldItem.PlannedHours != null)
                    {
                        insertedHours = item.PlannedHours.Where(p => !oldItem.PlannedHours.Any(o => (o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId && o.PlanningNumber == p.PlanningNumber))).ToList();
                    }

                    // ATTENTION HERE: DID NOT INCLUDE THE o.PlanningNumber == p.PlanningNumber BECAUSE I DONT WANT TO DELETE OLD PLANNINGS
                    var deletedHours = new List <PlannedHour>();
                    if (oldItem.PlannedHours != null)
                    {
                        deletedHours = oldItem.PlannedHours.Where(o => !item.PlannedHours.Any(p => o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId)).ToList();
                    }

                    var updatedHours = new List <PlannedHour>();
                    if (oldItem.PlannedHours != null)
                    {
                        updatedHours = item.PlannedHours.Where(p => oldItem.PlannedHours.Any(o => o.BacklogItemUId == p.BacklogItemUId && o.RoleUId == p.RoleUId && o.PlanningNumber == p.PlanningNumber)).ToList();
                    }

                    // insert, update and delete
                    foreach (PlannedHour p in updatedHours)
                    {
                        context.ApplyCurrentValues <PlannedHour>("PlannedHours", p);
                    }
                    foreach (PlannedHour p in insertedHours)
                    {
                        context.AddObject("PlannedHours", p);
                    }
                    foreach (PlannedHour p in deletedHours)
                    {
                        context.DeleteObject(p);
                    }
                }
            }
        }
 /// <summary>
 /// Create a new BacklogItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="projectId">Initial value of the ProjectId property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="weight">Initial value of the Weight property.</param>
 /// <param name="spent">Initial value of the Spent property.</param>
 public static BacklogItem CreateBacklogItem(global::System.String id, global::System.String projectId, global::System.String description, global::System.Double weight, global::System.Double spent)
 {
     BacklogItem backlogItem = new BacklogItem();
     backlogItem.Id = id;
     backlogItem.ProjectId = projectId;
     backlogItem.Description = description;
     backlogItem.Weight = weight;
     backlogItem.Spent = spent;
     return backlogItem;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the BacklogItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBacklogItems(BacklogItem backlogItem)
 {
     base.AddObject("BacklogItems", backlogItem);
 }