Ejemplo n.º 1
0
        public GroupItem Edit(long installationID, int groupID, GroupClientData clientData)
        {
            Try.Argument(clientData, nameof(clientData));

            using (var transaction = Context.Data.Database.BeginTransaction())
            {
                var groups    = Context.Data.GetGroups(installationID);
                var powerBars = Context.Data.GetPowerBars(installationID, true);

                var editedGroup = groups.FirstOrDefault(x => x.GroupID == groupID);
                Try.NotNull(editedGroup, $"Cant find group with ID: {groupID};");

                SetGroupProperties(groups, powerBars, editedGroup, clientData);

                var editedHierarchy = new TopGroup(groups);
                editedHierarchy.CheckCycles();
                editedHierarchy.AddPowerBars(powerBars);

                var editedGroupItem = editedHierarchy.GetGroupById(editedGroup.GroupID);
                Try.NotNull(editedGroupItem, $"Cant find group with ID: {editedGroup.GroupID} in hierarchy;", false);

                editedHierarchy.UpdateStatuses();

                Context.Data.SaveChanges();
                transaction.Commit();

                Context.Events.GroupChange(installationID, editedGroupItem.GroupID, EventActionType.Edit);

                return(editedGroupItem);
            }
        }
Ejemplo n.º 2
0
        public GroupItem Create(long installationID, GroupClientData clientData)
        {
            Try.Argument(clientData, nameof(clientData));

            using (var transaction = Context.Data.Database.BeginTransaction())
            {
                var groups    = Context.Data.GetGroups(installationID);
                var powerBars = Context.Data.GetPowerBars(installationID, true);

                var installatioin = Context.Data.Installations.Find(installationID);
                var newGroup      = new Group(installatioin);

                SetGroupProperties(groups, powerBars, newGroup, clientData);

                Context.Data.Groups.Add(newGroup);
                groups.Add(newGroup);
                var newGroupId = newGroup.GroupID;

                var hierarchy = new TopGroup(groups);
                hierarchy.CheckCycles();
                hierarchy.AddPowerBars(powerBars);

                var newGroupItem = hierarchy.GetGroupById(newGroupId);
                Try.NotNull(newGroupItem, "Cant find new group in hierarchy;", false);

                hierarchy.UpdateStatuses();

                Context.Data.SaveChanges();
                transaction.Commit();

                Context.Events.GroupChange(installationID, newGroupItem.GroupID, EventActionType.Create);

                return(newGroupItem);
            }
        }
Ejemplo n.º 3
0
        public TopGroup Get(long installationID)
        {
            var topGroup = new TopGroup(Context.Data.GetGroups(installationID));

            topGroup.AddPowerBars(Context.Data.GetPowerBars(installationID, true));
            topGroup.UpdateStatuses();
            return(topGroup);
        }