Ejemplo n.º 1
0
        public JsonResult DeleteRoomInConstruction(ParemetersRoom paremetersRoom, ParemetersRange paremetersRange)
        {
            Room room = ApplicationContext.Rooms.AsNoTracking().FirstOrDefault(x => x.Id == paremetersRoom.RoomId);

            if (room != null && room.Id == paremetersRoom.RoomId)
            {
                ApplicationContext.Rooms.Remove(room);
                ApplicationContext.SaveChanges();
            }

            return(GetRoomsInConstruction(paremetersRoom, paremetersRange));
        }
Ejemplo n.º 2
0
        public JsonResult DeleteMachineInRoom(ParemetersMachine paremetersMachine, ParemetersRange paremetersRange)
        {
            Machine machine = ApplicationContext.Machines.FirstOrDefault(x => x.Id == paremetersMachine.MachineId);

            if (machine != null && machine.Id == paremetersMachine.MachineId)
            {
                ApplicationContext.Machines.Remove(machine);
                ApplicationContext.SaveChanges();
            }

            return(GetMachinesInRoom(paremetersMachine, paremetersRange));
        }
Ejemplo n.º 3
0
        public JsonResult GetMachinesInConstruction(int constructionId, ParemetersRange paremetersRange)
        {
            var            rooms    = ApplicationContext.Rooms.AsNoTracking().Where(x => x.ConstructionId == constructionId).Include(x => x.Machines).ToList();
            List <Machine> machines = new List <Machine>();

            foreach (var room in rooms)
            {
                machines = machines.Concat(room.Machines).ToList();
            }

            var machinesShort = machines.Skip(paremetersRange.Skip).Take(paremetersRange.Take).AsQueryable();

            return(Json(machinesShort));
        }
Ejemplo n.º 4
0
        public JsonResult EditMachineInRoom(ParemetersMachine paremetersMachine, ParemetersRange paremetersRange)
        {
            Machine machine = ApplicationContext.Machines.FirstOrDefault(x => x.Id == paremetersMachine.MachineId);

            if (machine != null && machine.Id == paremetersMachine.MachineId)
            {
                machine.Name       = paremetersMachine.Name;
                machine.CreateYear = paremetersMachine.CreateYear;
                ApplicationContext.Machines.Update(machine);
                ApplicationContext.SaveChanges();
            }

            return(GetMachinesInRoom(paremetersMachine, paremetersRange));
        }
Ejemplo n.º 5
0
        public JsonResult AddMachineInRoom(ParemetersMachine paremetersMachine, ParemetersRange paremetersRange)
        {
            Machine machine = new Machine
            {
                Name       = paremetersMachine.Name,
                CreateYear = paremetersMachine.CreateYear,
                RoomId     = paremetersMachine.RoomId
            };

            ApplicationContext.Machines.Add(machine);
            ApplicationContext.SaveChanges();

            return(GetMachinesInRoom(paremetersMachine, paremetersRange));
        }
Ejemplo n.º 6
0
        public JsonResult EditRoomInConstruction(ParemetersRoom paremetersRoom, ParemetersRange paremetersRange)
        {
            Room room = ApplicationContext.Rooms.AsNoTracking().FirstOrDefault(x => x.Id == paremetersRoom.RoomId);

            if (room != null && room.Id == paremetersRoom.RoomId)
            {
                room.Name  = paremetersRoom.Name;
                room.Floor = paremetersRoom.Floor;
                ApplicationContext.Rooms.Update(room);
                ApplicationContext.SaveChanges();
            }

            return(GetRoomsInConstruction(paremetersRoom, paremetersRange));
        }
Ejemplo n.º 7
0
        public JsonResult AddRoomInConstruction(ParemetersRoom paremetersRoom, ParemetersRange paremetersRange)
        {
            Room room = new Room
            {
                Name           = paremetersRoom.Name,
                Floor          = paremetersRoom.Floor,
                ConstructionId = paremetersRoom.ConstructionId
            };

            ApplicationContext.Rooms.Add(room);
            ApplicationContext.SaveChanges();

            return(GetRoomsInConstruction(paremetersRoom, paremetersRange));
        }
Ejemplo n.º 8
0
        //Rooms
        public JsonResult GetRoomsInConstruction(ParemetersRoom paremetersRoom, ParemetersRange paremetersRange)
        {
            var rooms = ApplicationContext.Rooms.AsNoTracking().Where(x => x.ConstructionId == paremetersRoom.ConstructionId).Include(x => x.Machines)
                        .Select(x => new
            {
                id             = x.Id,
                name           = x.Name,
                floor          = x.Floor,
                constructionId = x.ConstructionId,
                haveMachine    = x.Machines.Any()
            }).Skip(paremetersRange.Skip).Take(paremetersRange.Take);

            return(Json(rooms));
        }
Ejemplo n.º 9
0
        public JsonResult GetConstructions(ParemetersRange paremetersRange)
        {
            var constructions = ApplicationContext.Constructions.AsNoTracking().Include(x => x.Rooms)
                                .Select(x => new
            {
                id          = x.Id,
                name        = x.Name,
                address     = x.Address,
                haveMachine = x.Rooms
                              .SelectMany(y => y.Machines)
                              .Any()
            }).Skip(paremetersRange.Skip).Take(paremetersRange.Take);

            return(Json(constructions));
        }
Ejemplo n.º 10
0
        public JsonResult EditConstruction(ParemetersConstruction paremetersConstruction, ParemetersRange paremetersRange)
        {
            Construction construction = ApplicationContext.Constructions.FirstOrDefault(x => x.Id == paremetersConstruction.ConstructionId);

            if (construction != null && construction.Id == paremetersConstruction.ConstructionId)
            {
                construction.Name    = paremetersConstruction.Name;
                construction.Address = paremetersConstruction.Address;
                ApplicationContext.Constructions.Update(construction);
                ApplicationContext.SaveChanges();
            }

            return(GetConstructions(paremetersRange));
        }
Ejemplo n.º 11
0
        public JsonResult DeleteConstruction(ParemetersConstruction paremetersConstruction, ParemetersRange paremetersRange)
        {
            Construction construction = ApplicationContext.Constructions.FirstOrDefault(x => x.Id == paremetersConstruction.ConstructionId);

            if (construction != null && construction.Id == paremetersConstruction.ConstructionId)
            {
                ApplicationContext.Constructions.Remove(construction);
                ApplicationContext.SaveChanges();
            }

            return(GetConstructions(paremetersRange));
        }
Ejemplo n.º 12
0
        public JsonResult AddConstruction(ParemetersConstruction paremetersConstruction, ParemetersRange paremetersRange)
        {
            Construction construction = new Construction
            {
                Name    = paremetersConstruction.Name,
                Address = paremetersConstruction.Address
            };

            ApplicationContext.Constructions.Add(construction);
            ApplicationContext.SaveChanges();

            return(GetConstructions(paremetersRange));
        }
Ejemplo n.º 13
0
        public JsonResult GetMachinesInRoom(ParemetersMachine paremetersMachine, ParemetersRange paremetersRange)
        {
            var machines = ApplicationContext.Machines.AsNoTracking().Where(x => x.RoomId == paremetersMachine.RoomId).Skip(paremetersRange.Skip).Take(paremetersRange.Take);

            return(Json(machines));
        }