Ejemplo n.º 1
0
        private DevicesListViewModel DevicesToDevicesListViewModel(List <DeviceConfig> devices)
        {
            List <DeviceIndexViewModel> deviceIndexViewModels = new List <DeviceIndexViewModel>();

            devices.ForEach(device =>
            {
                var viewModel = new DeviceIndexViewModel()
                {
                    Id    = device.Id,
                    Title = device.Title,
                    RegistersListViewModel = RegistersToRegistersListViewModel(device.Registers.ToList())
                };

                deviceIndexViewModels.Add(viewModel);
            });

            return(new DevicesListViewModel()
            {
                DeviceIndexViewModels = deviceIndexViewModels
            });
        }
Ejemplo n.º 2
0
        // GET: Devices/Details/5
        public async Task <IActionResult> Details(long?id)
        {
            AppUser appUser = AuthExtender.GetLoggedInUser(this, _context);

            if (id == null)
            {
                return(NotFound());
            }

            Device device = await _context.Devices
                            .FirstOrDefaultAsync(m => m.Id == id);

            if (device == null)
            {
                return(NotFound());
            }

            await _context.Entry(device).Reference(p => p.Owner).LoadAsync();

            if (!device.Owner.Equals(appUser) & !_context.SickWardenRelations.Any(p => p.Warden.Equals(appUser) && p.Sick.Equals(device.Owner) && p.IsAccepted.Equals(true)))
            {
                return(NotFound());
            }

            DeviceIndexViewModel deviceViewModel = new DeviceIndexViewModel
            {
                Id                  = device.Id,
                Name                = device.Name,
                Comment             = device.Comment,
                Owner               = device.Owner.FullName,
                IsServiceObligatory = device.IsServiceObligatory.GetValueOrDefault(),
                LastPlaceLeft       = device.LastPlaceLeft,
                LastServiceDate     = device.LastServiceDate,
                LastUsedDate        = device.LastUsedDate
            };

            return(View(deviceViewModel));
        }