예제 #1
0
        public async Task Store(Contracts.Entities.User user)
        {
            // search und update User

            int id = user.UserID;

            var UserInDb = await Context.Users.
                           Where(m => m.UserID == id).
                           FirstOrDefaultAsync();

            if (UserInDb == default(Contracts.Entities.User))
            {
                // add new

                Uow.MarkNew(user);
            }
            else
            {
                // syn with existing

                Uow.SetValue(UserInDb, user);

                // search und update Usercommands (add and delete)
            }
        }
예제 #2
0
        public async Task Store(Contracts.Entities.Item item)
        {
            // search und update machine

            int id        = item.ItemID;
            var optValues = item.ItemProperties?.ToList() ?? new List <Contracts.Entities.ItemProperty>();

            var itemInDb = await Context.Items.
                           Where(m => m.ItemID == id).
                           Include(d => d.ItemProperties).
                           FirstOrDefaultAsync();

            if (itemInDb == default(Contracts.Entities.Item))
            {
                // add new
                Uow.MarkNew(item);
                foreach (var iv in optValues)
                {
                    Uow.MarkNew(iv);
                }
            }
            else
            {
                // syn with existing

                Uow.SetValue(itemInDb, item);

                // search und update machinecommands (add and delete)

                Sync <Contracts.Entities.ItemProperty>(
                    itemInDb.ItemProperties,
                    optValues,
                    (x, y) => x.ItemID > 0 && x.ItemID == y.ItemID && x.Name == y.Name);
            }
        }
예제 #3
0
        public async Task Store(Contracts.Entities.Machine machine)
        {
            // search und update machine

            int id = machine.MachineID;
            var machineCommands     = machine.MachineCommands?.ToList() ?? new List <Contracts.Entities.MachineCommand>();
            var machineInitCommands = machine.MachineInitCommands?.ToList() ?? new List <Contracts.Entities.MachineInitCommand>();

            var machineInDb = await Context.Machines.
                              Where(m => m.MachineID == id).
                              Include(d => d.MachineCommands).
                              Include(d => d.MachineInitCommands).
                              FirstOrDefaultAsync();

            if (machineInDb == default(Contracts.Entities.Machine))
            {
                // add new

                Uow.MarkNew(machine);
                foreach (var mc in machineCommands)
                {
                    Uow.MarkNew(mc);
                }
                foreach (var mic in machineInitCommands)
                {
                    Uow.MarkNew(mic);
                }
            }
            else
            {
                // syn with existing

                Uow.SetValue(machineInDb, machine);

                // search und update machinecommands (add and delete)

                Sync <Contracts.Entities.MachineCommand>(
                    machineInDb.MachineCommands,
                    machineCommands,
                    (x, y) => x.MachineCommandID > 0 && x.MachineCommandID == y.MachineCommandID);

                Sync <Contracts.Entities.MachineInitCommand>(
                    machineInDb.MachineInitCommands,
                    machineInitCommands,
                    (x, y) => x.MachineInitCommandID > 0 && x.MachineInitCommandID == y.MachineInitCommandID);
            }
        }
예제 #4
0
        public async Task Save(Contracts.Entities.Configuration configuration)
        {
            // search und update machine

            var cInDb = await Context.Configurations.Where(c => c.Group == configuration.Group && c.Name == configuration.Name).FirstOrDefaultAsync();

            if (cInDb == default(Contracts.Entities.Configuration))
            {
                // add new

                cInDb = configuration;
                Uow.MarkNew(cInDb);
            }
            else
            {
                // syn with existing
                Uow.SetValue(cInDb, configuration);
            }
        }