public ActionResult Edit(int id, CreateDeviceViewModel deviceVm) { try { _deviceService.Update(new Device() { RentPrice = deviceVm.TheDevice.RentPrice, Price = deviceVm.TheDevice.Price, Name = deviceVm.TheDevice.Name, Picture = deviceVm.TheDevice.Picture, Description = deviceVm.TheDevice.Description, Stock = deviceVm.TheDevice.Stock }, deviceVm.SelectedFrameworks, deviceVm.SelectedOSs); TempData["status"] = "success"; TempData["message"] = "Device updated"; } catch (Exception ex) { TempData["status"] = "error"; TempData["message"] = $"{ex.Message} / {ex.InnerException?.Message}"; } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> Create(CreateDeviceViewModel viewModel) { try { var registryManager = RM(viewModel.Location); var newDevice = new Device(viewModel.DeviceId) { Status = DeviceStatus.Enabled }; var device = await registryManager.AddDeviceAsync(newDevice); var twin = await registryManager.GetTwinAsync(device.Id); twin.Tags["DeviceType"] = viewModel.DeviceType; twin.Tags["Installation"] = viewModel.Installation; await registryManager.UpdateTwinAsync(device.Id, twin, twin.ETag); return(RedirectToAction(nameof(Index), new { location = viewModel.Location })); } catch (Exception ex) { return(View(viewModel)); } }
public IActionResult Post([FromBody] CreateDeviceViewModel deviceViewModel) { try { deviceViewModel.Name = deviceViewModel.Name.Trim(); if (_deviceRepository.List(d => d.Name.Equals(deviceViewModel.Name, StringComparison.OrdinalIgnoreCase)).Any()) { return(BadRequest("Duplicate device name!")); } var device = _mapper.Map <Device>(deviceViewModel); device.IsDeleted = false; device.IsBorrowed = false; device.CreatedOn = DateTime.Now; device.CreatedBy = User.Identity.Name; _deviceRepository.Add(device); string qrCodeFileName = $"P{device.Id}_{Guid.NewGuid().ToString().Replace("-", "")}.png"; string qrCodeContent = "{\"objectType\":\"" + AssetClassifications.DEVICE + "\",\"objectId\":" + device.Id + "}"; device.QrCodeImageUrl = QRCodeHelper.GenerateQrCodeImage(qrCodeFileName, qrCodeContent); device.QrCodeContent = qrCodeContent; _deviceRepository.Update(device); return(Ok()); } catch (Exception EX) { return(StatusCode(500, EX.Message)); } }
// GET: Devices/Create public async Task <ActionResult> Create(string location) { var viewModel = new CreateDeviceViewModel { Location = location }; return(View(viewModel)); }
public async Task <IActionResult> Create(CreateDeviceViewModel vm) { var dto = _deviceViewModelMapper.MapFrom(vm); var result = await _deviceService.Create(dto); if (result) { return(new JsonResult(true)); } return(new JsonResult(false)); }
public async Task <IActionResult> Create() { var devicetypes = await _deviceTypeService.GetAllAsync(); var vm = _deviceTypeViewModelMapper.MapFrom(devicetypes); var newvm = new CreateDeviceViewModel { DeviceTypes = vm }; return(View(newvm)); }
public ActionResult Edit(int id) { CreateDeviceViewModel vm = new CreateDeviceViewModel() { TheDevice = _deviceService.GetDevice(id), AllFrameworks = new SelectList(_frameworkService.GetAll(), "ID", "Name"), AllOSs = new SelectList(_osService.GetAll(), "ID", "Name") }; ViewBag.Title = "Edit " + vm.TheDevice.Name; return(View(vm)); }
public ActionResult Create(CreateDeviceViewModel deviceVm) { _deviceService.Insert(new Device() { RentPrice = deviceVm.TheDevice.RentPrice, Price = deviceVm.TheDevice.Price, Name = deviceVm.TheDevice.Name, Picture = deviceVm.TheDevice.Picture, Description = deviceVm.TheDevice.Description, Stock = deviceVm.TheDevice.Stock }, deviceVm.SelectedFrameworks, deviceVm.SelectedOSs); return(RedirectToAction(nameof(Index))); }
public IActionResult AddNewDevice() { var createDeviceViewModel = new CreateDeviceViewModel() { Manufacturers = _manufacturerRepository.GetManufacturers().ToList(), Types = _typeRepository.GetTypes().ToList(), OperatingSystems = _operatingSystemRepository.GetOperatingSystems().ToList(), OSversions = _osVersionRepository.GetOSversions().ToList(), RAMamounts = _ramAmountRepository.GetRAMamounts().ToList(), Processors = _processorRepository.GetProcessors().ToList(), Users = _userRepository.GetUsers().ToList() }; return(View(createDeviceViewModel)); }
public async Task <ActionResult> Create(CreateDeviceViewModel device, params Guid[] selectedGroups) { if (ModelState.IsValid) { selectedGroups = selectedGroups ?? new Guid[] { }; db.Devices.Add(new Device { Id = Guid.NewGuid(), DeviceName = device.DeviceName, IPAddress = device.IPAddress, IsOnline = false, DeviceGroups = await db.DeviceGroups.Where(c => selectedGroups.Contains(c.Id)).ToListAsync() }); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(device)); }