public ActionResult Add(DeviceExtendedModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Device device = CreateDeviceFromDeviceModel(model);
             deviceRepository.AddObject(device);
             return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
             throw new Exception("Wystąpił błąd podczas dodawania urządzenia. Proszę o kontakt z administratorem. Error message: " + ex.Message);
         }
     }
     else
     {
         model.SectionList = peripheralDeviceController.DevicesListItem();
         if (Request.IsAjaxRequest())
         {
             return PartialView("Device/_DeviceAdd", model);
         }
         return View(model);
     }
 }
 public ActionResult Add()
 {
     DeviceExtendedModel model = new DeviceExtendedModel();
     model.SectionList = peripheralDeviceController.DevicesListItem();
     if (Request.IsAjaxRequest())
     {
         return PartialView("Device/_DeviceAdd", model);
     }
     return View(model);
 }
 void UpdateDevice(ref Device dev, DeviceExtendedModel model)
 {
     dev.comment = model.comment;
     dev.id_fixed_asset = model.id_fixed_asset;
     dev.ip_address = model.ip_address;
     dev.mac_address = model.mac_address;
     dev.model = model.modell;
     dev.producer = model.producer;
     dev.serial_number = model.serial_number;
 }
        DeviceExtendedModel CreateDeviceModelFromDevice(Device device)
        {
            DeviceExtendedModel model = new DeviceExtendedModel();
            model.comment = device.comment;
            model.id = device.id;
            model.id_fixed_asset = device.id_fixed_asset;
            model.ip_address = device.ip_address;
            model.mac_address = device.mac_address;
            model.modell = device.model;
            model.peripheral_device_id = device.id_peripheral_device;
            model.peripheral_device_name = device.PeripheralDevice.name;
            model.producer = device.producer;
            model.serial_number = device.serial_number;

            return model;
        }
        Device CreateDeviceFromDeviceModel(DeviceExtendedModel device)
        {
            Device model = new Device();
            model.comment = device.comment;
            model.id = device.id;
            model.id_fixed_asset = device.id_fixed_asset;
            model.ip_address = device.ip_address;
            model.mac_address = device.mac_address;
            int id_peripheral;
            int.TryParse(device.peripheral_device_name, out id_peripheral);
            model.id_peripheral_device = id_peripheral;
            model.producer = device.producer;
            model.serial_number = device.serial_number;

            return model;
        }
 public ActionResult Edit(DeviceExtendedModel model)
 {
     //ModelState.Remove("id");
     if (ModelState.IsValid)
     {
         try
         {
             Device device = deviceRepository.Repository.FirstOrDefault(x => x.id == model.id);
             UpdateDevice(ref device, model);
             deviceRepository.EditObject(device);
             return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
             throw new Exception("Nie udało się edytować urządzenia. Proszę skontaktować się z administratorem. " + ex.InnerException);
         }
     }
     else
     {
         if (Request.IsAjaxRequest())
         {
             return PartialView("Device/_DeviceEdit", model);
         }
         return View(model);
     }
 }