public ResponseData UpdateDeviceType(DeviceTypeViewModel dtvm)
        {
            ResponseData rd = new ResponseData();
            //验证用户权限,只有管理员才能处理
            UserService us   = new UserService();
            bool        bRet = us.IsAdmin(dtvm.Account, dtvm.Token);

            if (!bRet)
            {
                rd.Success = false;
                rd.Message = "用户没有权限修改设备类型信息";
            }
            DeviceTypeModel dtm = _dtr.Find(dtvm.Id);

            dtm.ParentId       = dtvm.ParentId;
            dtm.Description    = dtvm.Description;
            dtm.DeviceTypeName = dtvm.DeviceTypeName;
            try
            {
                _dtr.Save(dtm);
                rd.Success = true;
                rd.Message = "修改设备类型信息成功";
            }
            catch (Exception)
            {
                rd.Success = false;
                rd.Message = "修改设备类型信息失败";
            }
            return(rd);
        }
        public ResponseData DeleteDeviceType(DeviceTypeViewModel dtvm)
        {
            ResponseData rd = new ResponseData();
            //验证用户权限,只有管理员才能处理
            UserService us   = new UserService();
            bool        bRet = us.IsAdmin(dtvm.Account, dtvm.Token);

            if (!bRet)
            {
                rd.Success = false;
                rd.Message = "用户没有权限删除设备类型信息";
            }
            DeviceTypeModel dtm = _dtr.Find(dtvm.Id);

            try
            {
                _dtr.Remove(dtm);
                rd.Success = true;
                rd.Message = "删除设备类型信息成功";
            }
            catch (Exception)
            {
                rd.Success = false;
                rd.Message = "删除设备类型信息失败";
            }
            return(rd);
        }
Exemple #3
0
        public IActionResult PostDeviceType([FromBody] DeviceTypeViewModel vmdl)
        {
            try
            {
                var dt = _bl.CreateDeviceType();

                vmdl.ApplyChanges(dt, _bl);
                _bl.SaveChanges();
                _log.LogInformation("DeviceType '{0}' created by '{1}'", vmdl.Name, User.Identity.Name);

                vmdl.Refresh(dt);
                return(Ok(vmdl));
            }
            catch (SecurityException)
            {
                _log.LogWarning("Security: '{0}' tried to create DeviceType '{1}'", _bl.GetCurrentUid(), vmdl.Name);
                return(Unauthorized());
            }

            catch (Exception ex)
            {
                _log.LogError("Exception: '{0}'", ex);
                return(StatusCode(500));
            }
        }
        public ActionResult Add(DeviceTypeViewModel deviceType)
        {
            if (Session["UserData"] is Admin)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (deviceType.DeviceTypeId == Guid.Empty)
                        {
                            deviceType.DeviceTypeId = Guid.NewGuid();
                            var device = Mapper.Map <DeviceTypeViewModel, DeviceType>(deviceType);
                            //     deal.parent = Guid.Parse(Request.Form["CustomerId"]);
                            devicetypeService.CreateDeviceType(device);
                            devicetypeService.SaveDeviceType();
                        }
                        else
                        {
                            var device = devicetypeService.GetDeviceType(deviceType.DeviceTypeId);
                            Mapper.Map <DeviceTypeViewModel, DeviceType>(deviceType, device);
                            devicetypeService.UpdateDeviceType(device);
                            devicetypeService.SaveDeviceType();
                        }

                        return(Json(new { Result = "Success" }));
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            return(PartialView("_Add", deviceType));
        }
Exemple #5
0
        public ActionResult Index(int?page)
        {
            int currentpage = (int)(page.HasValue ? page - 1 : 0);
            DeviceTypeViewModel devicetype = new DeviceTypeViewModel();

            devicetype.DeviceTypes = _deviceBaseService.DeviceTypeRepository.GetDeviceTypes().ToPagedList(currentpage, 20);
            if (devicetype.DeviceTypes == null)
            {
                return(HttpNotFound());
            }
            return(View("Index", devicetype));
        }
Exemple #6
0
 public ViewModelLocator()
 {
     //Простое решение — проверять, не бежим ли мы в дизайнере.
     if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         return;
     }
     homeViewModel         = new HomeViewModel();
     deviceTypeViewModel   = new DeviceTypeViewModel(App.deviceTypeDataService, App.deviceGadgetDataService);
     deviceModelViewModel  = new DeviceModelViewModel(App.deviceModelRepository, App.deviceTypeDataService);
     deviceGadgetViewModel = new DeviceGadgetViewModel(App.deviceGadgetDataService);
     locationViewModel     = new LocationViewModel(App.locationRepository);
     sPSIViewModel         = new SPSIViewModel(App.SPSIRepository);
 }
        // GET : DeviceType/Add
        public ActionResult Add(string deviceId)
        {
            DeviceTypeViewModel deviceVM = new DeviceTypeViewModel();

            if (string.IsNullOrWhiteSpace(deviceId))
            {
                deviceVM.DeviceTypeId = Guid.Empty;
            }
            else
            {
                var        dealerGuid = Guid.Parse(deviceId);
                DeviceType deviceType = devicetypeService.GetDeviceType(dealerGuid);
                deviceVM = Mapper.Map <DeviceType, DeviceTypeViewModel>(deviceType);
            }
            return(PartialView("_Add", deviceVM));
        }
        public DeviceTypeListReponseViewModel GetDeviceTypeList(string token)
        {
            DeviceTypeListReponseViewModel dtlrvm = new DeviceTypeListReponseViewModel();
            List <DeviceTypeModel>         list   = _dtr.FindAll(token);

            foreach (var item in list)
            {
                DeviceTypeViewModel dtvm = new DeviceTypeViewModel();
                dtvm.Id             = item.Id;
                dtvm.ParentId       = item.ParentId;
                dtvm.Token          = item.Token;
                dtvm.DeviceTypeName = item.DeviceTypeName;
                dtvm.Description    = item.Description;
                dtlrvm.List.Add(dtvm);
            }
            dtlrvm.Success = true;
            dtlrvm.Message = "获取设备类型列表成功";
            return(dtlrvm);
        }
        public static DeviceViewModel GetValidDeviceViewModel()
        {
            var p      = _bl.GetUsers("if15b032");
            var uvmdl  = new UserViewModel(p);
            var dt     = _bl.GetDeviceType("festplatte");
            var dtvmdl = new DeviceTypeViewModel(dt);
            var ds     = _bl.GetDeviceStatus(1);
            var dsvmdl = new DeviceStatusViewModel(ds);
            var vmdl   = new DeviceViewModel
            {
                CreateDate = DateTime.Now.ToShortDateString(),
                Marke      = "Test",
                IsActive   = true,
                Verwalter  = uvmdl,
                DeviceType = dtvmdl,
                Status     = dsvmdl,
                Name       = "Test Device,",
            };

            return(vmdl);
        }
Exemple #10
0
        public IActionResult PutDeviceType(string slug, [FromBody] DeviceTypeViewModel vmdl)
        {
            try
            {
                var dt = _bl.GetDeviceType(slug);
                _bl.UpdateDeviceType(dt);
                vmdl.ApplyChanges(dt, _bl);
                _bl.SaveChanges();

                _log.LogInformation("DeviceType '{0}' updated by '{1}'", vmdl.Name, User.Identity.Name);
                vmdl.Refresh(dt);
                return(Ok(vmdl));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (_bl.GetDeviceType(slug) == null)
                {
                    _log.LogWarning("Not Found: DeviceType '{0}' not found", slug);
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (SecurityException)
            {
                _log.LogWarning("Security: '{0}' tried to update DeviceType '{1}'", _bl.GetCurrentUid(), slug);
                return(Unauthorized());
            }

            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }
        }
Exemple #11
0
 public ResponseData UpdateDeviceType(DeviceTypeViewModel dtvm)
 {
     return(_dts.UpdateDeviceType(dtvm));
 }
Exemple #12
0
 public DeviceTypeViewModel AddDeviceType(DeviceTypeViewModel dtvm)
 {
     dtvm = _dts.DeviceTypeAdd(dtvm);
     return(dtvm);
 }
Exemple #13
0
        public DeviceTypeViewModel DeviceTypeAdd(DeviceTypeViewModel dtvm)
        {
            //验证用户权限(只有管理员能添加设备类型)
            #region 验证用户权限
            //首先验证用户是否有权限进行操作
            bool bRet = new UserService().IsAdmin(dtvm.Account, dtvm.Token);
            if (!bRet)
            {
                dtvm.Success = false;
                dtvm.Message = "用户没有添加设备类型的权限";
                return(dtvm);
            }

            /*
             * UserModel um = new UserRepository().Find(dtvm.Account);
             * //非管理员
             *
             * if (um.UserRole.Role.IsAdmin != 1)
             * {
             *  dtvm.Success = false;
             *  dtvm.Message = "用户没有添加设备类型的权限";
             *  return dtvm;
             * }*/

            #endregion
            //验证设备类型名称是否已经存在
            DeviceTypeModel dtm = _dtr.Find(dtvm.DeviceTypeName, dtvm.Token);
            if (dtm != null)
            {
                dtvm.Success = false;
                dtvm.Message = "已存在此设备类型";
                return(dtvm);
            }
            //添加设备类型
            dtm = new DeviceTypeModel();
            dtm.DeviceTypeName = dtvm.DeviceTypeName;
            dtm.Token          = dtvm.Token;
            dtm.Description    = dtvm.Description;
            if (dtvm.ParentId == 0)
            {
                dtm.ParentId = null;
            }
            else
            {
                dtm.ParentId = dtvm.ParentId;
            }
            try
            {
                _dtr.Add(dtm);
                dtvm.Id = dtm.Id;
            }
            catch (Exception ex)
            {
                dtvm.Success = false;
                dtvm.Message = "添加设备类型失败" + ex.Message;
                return(dtvm);
            }
            dtvm.Success = true;
            dtvm.Message = "添加设备类型成功";
            return(dtvm);
        }