public HttpResponseMessage GetPlant(int id) { PlantManagerViewModel plant = new PlantManagerViewModel(); plant = _plantService.GetPlant(id); return(Request.CreateResponse(HttpStatusCode.OK, plant, MediaTypeHeaderValue.Parse("application/json"))); }
public PlantManagerViewModel GetPlants(ContextModel context) { var plantManager = new PlantManagerViewModel(); string usernameCustomer = null; if (context.User.Role != enRole.Administrator && context.User.Role != enRole.Demo) { usernameCustomer = context.User.Username; } var plantsModel = _plantManagerService.GetPlants(usernameCustomer); if (context.User.Role == enRole.Demo) { plantsModel = _plantManagerService.FilterPlantsByRole(enRole.Demo, plantsModel); } plantManager.Plants = plantsModel.Where(p => !string.IsNullOrWhiteSpace(p.CustomerName)).Select(s => new PlantViewModel { Id = s.Id, Name = s.Name, Address = s.Address, MachineSerials = s.Machines.Where(m => m.ExpirationDate == null || m.ExpirationDate > DateTime.UtcNow).Select(u => $"({u.Serial})-{u.MachineName}").ToList(), CustomerName = s.CustomerName, Machines = s.Machines.Where(m => m.ExpirationDate == null || m.ExpirationDate > DateTime.UtcNow).Select(n => new UserMachineViewModel { Id = n.Id, Serial = n.Serial }).ToList() }).ToList(); plantManager.Customers = _userManagerService.GetCustomerNames(); return(plantManager); }
public PlantManagerViewModel GetPlantByMachine(int id) { var result = new PlantManagerViewModel(); var plantModel = _plantManagerService.GetPlantByMachine(id); if (plantModel == null) { return(result); } var plant = new PlantViewModel { Id = plantModel.Id, Name = plantModel.Name, Address = plantModel.Address, CustomerName = plantModel.CustomerName, MachineSerials = plantModel.Machines.Select(u => u.Serial).ToList(), Machines = plantModel.Machines.Select(n => new UserMachineViewModel { Id = n.Id, Serial = n.Serial }).ToList() }; result.Plant = plant; result.Machines = _userManagerViewService.GetMachinesByCustomer(plantModel.CustomerName, false); return(result); }
public HttpResponseMessage GetPlantByMachine(int idMachine) { ContextModel context = _contextService.GetContext(); PlantManagerViewModel plant = new PlantManagerViewModel(); plant = _plantService.GetPlantByMachine(idMachine); return(Request.CreateResponse(HttpStatusCode.OK, plant, MediaTypeHeaderValue.Parse("application/json"))); }
public PlantManagerViewModel GetPlantsByCustomer(string idCustomer) { var plantManager = new PlantManagerViewModel(); var plantsModel = _plantManagerService.GetPlants(idCustomer); plantManager.Plants = plantsModel.Select(s => new PlantViewModel { Id = s.Id, Name = s.Name, Address = s.Address, MachineSerials = s.Machines.Select(u => u.Serial).ToList(), CustomerName = s.CustomerName, Machines = s.Machines.Select(n => new UserMachineViewModel { Id = n.Id, Serial = n.Serial }).ToList() }).ToList(); return(plantManager); }
public PlantManagerViewModel GetPlant(int id) { var result = new PlantManagerViewModel(); var plantModel = _plantManagerService.GetPlant(id); var plant = new PlantViewModel { Id = plantModel.Id, Name = plantModel.Name, Address = plantModel.Address, CustomerName = plantModel.CustomerName, MachineSerials = plantModel.Machines.Select(u => u.Serial).ToList(), Machines = plantModel.Machines.Where(n => n.ExpirationDate == null || n.ExpirationDate > DateTime.UtcNow).Select(n => new UserMachineViewModel { Id = n.Id, Serial = n.Serial }).ToList() }; result.Plant = plant; result.Machines = _userManagerViewService.GetMachinesByCustomer(plantModel.CustomerName, false); return(result); }