Exemple #1
0
        public void SaveItemSize(ItemSize size)
        {
            using (var context = new ScrumFactoryEntities(this.connectionString)) {
                ItemSize oldSize = GetItemSize(size.ItemSizeUId);

                if (oldSize == null)
                {
                    context.ItemSizes.AddObject(size);
                }
                else
                {
                    context.AttachTo("ItemSizes", oldSize);
                    context.ApplyCurrentValues <ItemSize>("ItemSizes", size);

                    if (oldSize.SizeIdealHours == null)
                    {
                        oldSize.SizeIdealHours = new List <SizeIdealHour>();
                    }

                    if (size.SizeIdealHours == null)
                    {
                        oldSize.SizeIdealHours = new List <SizeIdealHour>();
                    }

                    var deletedHours  = oldSize.SizeIdealHours.Where(o => !size.SizeIdealHours.Any(s => s.IdealHourUId == o.IdealHourUId));
                    var updatedHours  = size.SizeIdealHours.Where(s => oldSize.SizeIdealHours.Any(o => o.IdealHourUId == s.IdealHourUId));
                    var insertedHours = size.SizeIdealHours.Where(s => !oldSize.SizeIdealHours.Any(o => o.IdealHourUId == s.IdealHourUId));

                    foreach (SizeIdealHour h in deletedHours)
                    {
                        context.SizeIdealHours.DeleteObject(h);
                    }

                    foreach (SizeIdealHour h in updatedHours)
                    {
                        context.ApplyCurrentValues <SizeIdealHour>("SizeIdealHours", h);
                    }

                    foreach (SizeIdealHour h in insertedHours)
                    {
                        context.SizeIdealHours.AddObject(h);
                    }
                }

                context.SaveChanges();
            }
        }
Exemple #2
0
        public void DeleteItemSize(string itemSizeUId)
        {
            using (var context = new ScrumFactoryEntities(this.connectionString)) {
                ItemSize size = context.ItemSizes.Include("SizeIdealHours").SingleOrDefault(z => z.ItemSizeUId == itemSizeUId);
                if (size == null)
                {
                    return;
                }
                //if (size.SizeIdealHours != null) {
                //    foreach (SizeIdealHour h in size.SizeIdealHours)
                //        context.SizeIdealHours.DeleteObject(h);
                //}
                context.ItemSizes.DeleteObject(size);

                context.SaveChanges();
            }
        }
Exemple #3
0
        public void UpdateItemSizeOccurrenceContraint(string itemSizeUId, ItemOccurrenceContraints constraint)
        {
            // gets the item and set the constraint
            ItemSize newSize = GetItemSize(itemSizeUId);

            if (newSize == null)
            {
                return;
            }

            // now seacrh for the olditem with the same constraint and clean it
            using (var context = new ScrumFactoryEntities(this.connectionString)) {
                ItemSize oldSize = context.ItemSizes.SingleOrDefault(z => z.OccurrenceConstraint == (int)constraint);
                if (oldSize != null)
                {
                    oldSize.OccurrenceConstraint = (int)ItemOccurrenceContraints.DEVELOPMENT_OCC;
                }

                context.AttachTo("ItemSizes", newSize);
                newSize.OccurrenceConstraint = (int)constraint;

                context.SaveChanges();
            }
        }