예제 #1
0
        public ActionResult DeviceEdit(string deviceCode)
        {

            var merchant = ModelFacade.Platform.TenantModel.GetTenant(this.Passport.TenantCode);
            ViewData["OperateModel"] = merchant;
            ViewData["GpsType"] = ModelFacade.Merchant.CustomerManager.GetGpsTypeList();
            ViewData["AddDeviceFee"] = ConfigHelper.ReadInt("AddDeviceFee");
            if (string.IsNullOrEmpty(deviceCode))
            {

                var account = ModelFacade.Merchant.CustomerManager.GetTenantAccount(merchant.TenantCode);
                ViewData["Balance"] = account == null ? 0M : account.Balance;
                ViewData["Title"] = "添加设备";
                var device = new VMDevice();
                device.SourceID = 1;
                device.MerchantCode = merchant.TenantCode;
                device.MerchantName = merchant.TenantName;
                return View(device);
            }
            else
            {
                ViewData["Title"] = "修改设备";
                var device = ModelFacade.Platform.DeviceModel.GetVMDevice(deviceCode);
                return View(device);
            }


        }
예제 #2
0
        public ActionResult Edit(long id)
        {
            var loggedUser = this.ViewBag.User as User;

            var device = db.Devices.Where(m => m.Id == id).FirstOrDefault();

            if (device == null)
            {
                this.FlashError("Device not found");
                return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
            }

            if (!loggedUser.isAdmin && device.User.Id != loggedUser.Id)
            {
                this.FlashError("You can't edit this device");
                return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
            }

            VMDevice vm = new VMDevice();

            vm.Users          = db.Users.ToList();
            vm.Id             = device.Id;
            vm.SerialNumber   = device.SerialNumber;
            vm.SelectedUserId = device.User.Id;
            vm.Description    = device.Description;
            return(View(vm));
        }
예제 #3
0
        public ActionResult Create()
        {
            VMDevice vm = new VMDevice();

            vm.Users = db.Users.ToList();
            return(View(vm));
        }
예제 #4
0
        public ActionResult Edit(long id, VMDevice vm)
        {
            try
            {
                var loggedUser = this.ViewBag.User as User;

                var device = db.Devices.Where(m => m.Id == id).FirstOrDefault();
                if (device == null)
                {
                    this.FlashError("Device not found");
                    return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
                }

                if (!loggedUser.isAdmin && device.User.Id != loggedUser.Id)
                {
                    this.FlashError("You can't edit this device");
                    return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
                }

                if (String.IsNullOrWhiteSpace(vm.SerialNumber))
                {
                    throw new ValidationException("SerialNumber", "Invalid serial number");
                }

                var selectedUser = db.Users.Where(m => m.Id == vm.SelectedUserId).FirstOrDefault();
                if (selectedUser == null)
                {
                    throw new ValidationException("User", "User not found");
                }

                device.SerialNumber = vm.SerialNumber;
                device.User         = selectedUser;
                device.Description  = vm.Description;
                db.SaveChanges();
                this.FlashInfo("Device updated");
                return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Field, ex.Message);
            }

            vm.Users = db.Users.ToList();
            return(View(vm));
        }
예제 #5
0
        public ActionResult Create(VMDevice vm)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(vm.SerialNumber))
                {
                    throw new ValidationException("SerialNumber", "Invalid serial number");
                }

                if (db.Devices.Where(m => m.SerialNumber.Equals(vm.SerialNumber)).Count() > 0)
                {
                    throw new ValidationException("SerialNumber", "Serial number already taken");
                }

                var selectedUser = db.Users.Where(m => m.Id == vm.SelectedUserId).FirstOrDefault();
                if (selectedUser == null)
                {
                    throw new ValidationException("User", "User not found");
                }

                Device device = new Device();
                device.SerialNumber = vm.SerialNumber;
                device.User         = selectedUser;
                device.Description  = vm.Description;
                db.Devices.Add(device);
                db.SaveChanges();
                return(RedirectToAction("Index", new { area = "Admin", controller = "Device" }));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Field, ex.Message);
            }

            vm.Users = db.Users.ToList();
            return(View(vm));
        }
예제 #6
0
파일: vm.cs 프로젝트: Northcode/nvm2
 /// <summary>
 /// Loads a new device to the device list
 /// </summary>
 /// <param name='device'>
 /// Device to load.
 /// </param>
 public void LoadDevice(VMDevice device)
 {
     VMDevice[] ndevices = new VMDevice[devices.Length + 1];
     devices.CopyTo(ndevices,0);
     ndevices[ndevices.Length - 1] = device;
     devices = ndevices;
 }