Ejemplo n.º 1
0
        public async Task<ActionResult> Index()
        {
            var ipAddress = Request.UserHostAddress;
            var macAddress = NativeMethods.GetMacAddress(ipAddress);
            var deviceService = new DeviceService();
            var device = await deviceService.Get(ipAddress, macAddress);

            if (device != null && device.IsLocalized)
            {
                return RedirectToAction("Index", "Dashboard");
            }

            var roomService = new RoomService();
            var rooms = await roomService.Get();

            Session["Rooms"] = rooms;

            var model = new LocalizationViewModel
            {
                IpAddress = ipAddress,
                MacAddress = macAddress,
                Departments = rooms.Select(x => x.Department).DistinctBy(x => x.Name)
            };

            return View(model);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Index(LocalizationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var rooms = Session["Rooms"] as IList<Room>;
                if (rooms == null)
                {
                    rooms = new List<Room>();
                }

                model.Departments = rooms.Select(x => x.Department).DistinctBy(x => x.Name);

                return View(model);
            }

            var device = new Device
            {
                Name = model.DeviceName,
                IpAddress = model.IpAddress,
                MacAddress = model.MacAddress ?? "fake",
                Location = new Location
                {
                    Name = model.SelectedLocationName
                },
                Room = new Room
                {
                    Name = model.SelectedRoomName,
                    Department = new Department
                    {
                        Name = model.SelectedDepartmentName
                    }
                }
            };

            var localizationService = new LocalizationService();
            var response = await localizationService.Localize(device);
            Session["localization_response"] = response;

            return RedirectToAction("Index", "Dashboard");
        }