Exemplo n.º 1
0
        public static void Update(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.ID == task.ID);

                if (target != null)
                {
                    target.Title           = task.Title;
                    target.Start           = task.Start;
                    target.End             = task.End;
                    target.PercentComplete = task.PercentComplete;
                    target.OrderID         = task.OrderID;
                    target.ParentID        = task.ParentID;
                    target.Summary         = task.Summary;
                    target.Expanded        = task.Expanded;
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();

                    db.GanttTasks.Attach(entity);
                    db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                    db.SaveChanges();
                }
            }
        }
        public static void Insert(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var first = All().OrderByDescending(e => e.ID).FirstOrDefault();

                var id = 0;

                if (first != null)
                {
                    id = first.ID;
                }

                task.ID = id + 1;

                All().Insert(0, task);
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();

                    db.GanttTasks.AddObject(entity);

                    db.SaveChanges();

                    task.ID = entity.ID;
                }
            }
        }
        public static void Insert(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var first = All().OrderByDescending(e => e.ID).FirstOrDefault();

                var id = 0;

                if (first != null)
                {
                    id = first.ID;
                }

                task.ID = id + 1;

                All().Insert(0, task);
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();

                    db.GanttTasks.AddObject(entity);

                    db.SaveChanges();

                    task.ID = entity.ID;
                }
            }
        }
Exemplo n.º 4
0
        public static void Delete(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var target = One(p => p.ID == task.ID);
                if (target != null)
                {
                    All().Remove(target);
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();
                    db.GanttTasks.Attach(entity);

                    db.GanttTasks.DeleteObject(entity);

                    db.SaveChanges();
                }
            }
        }
        public static void Update(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.ID == task.ID);

                if (target != null)
                {
                    target.Title = task.Title;
                    target.Start = task.Start;
                    target.End = task.End;
                    target.PercentComplete = task.PercentComplete;
                    target.OrderID = task.OrderID;
                    target.ParentID = task.ParentID;
                    target.Summary = task.Summary;
                    target.Expanded = task.Expanded;
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();

                    db.GanttTasks.Attach(entity);
                    db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                    db.SaveChanges();
                }
            }
        }
        public static void Delete(GanttTaskModel task)
        {
            if (!UpdateDatabase)
            {
                var target = One(p => p.ID == task.ID);
                if (target != null)
                {
                    All().Remove(target);
                }
            }
            else
            {
                using (var db = new SampleEntities())
                {
                    var entity = task.ToEntity();
                    db.GanttTasks.Attach(entity);

                    db.GanttTasks.DeleteObject(entity);

                    db.SaveChanges();
                }
            }
        }