Ejemplo n.º 1
0
        public IActionResult CreateByExistingDeviceId(DeviceEditViewModel model)
        {
            //Get Ticket Number again and check ModelState
            model.Ticket.TicketNumber = context.Tickets.GetLatestTicketNum() + 1;
            if (!ModelState.IsValid)
            {
                model.Customer = context.Customers.Find(model.CustomerId);
                return(View(model));
            }
            //get the device and create a new ticket from the device
            var device = context.Devices.Find(model.Id);
            TicketConfirmationModel tcModel = _ticketCreator.CreateTicket(new TicketCreatorInfo
            {
                DeviceId    = device.Id,
                CustomerId  = device.CustomerId,
                NeedsBackup = model.Ticket.NeedsBackup,
                Notes       = model.Log.Notes,
                UserName    = User.FindFirst(ClaimTypes.Name).Value.ToString()
            });

            return(RedirectToAction("Confirmation", "Ticket", new
            {
                ticketId = tcModel.ticketId,
                deviceId = tcModel.deviceId,
                customerId = tcModel.customerId,
                updateId = tcModel.updateId
            }));
        }
Ejemplo n.º 2
0
        public void DropdownForEdit()
        {
            DeviceEditViewModel context = new DeviceEditViewModel();

            context.ListOfOffices = dropDownManager.OfficeDropDown();
            ViewBag.Context       = context;
        }
Ejemplo n.º 3
0
        //Ticket/CreateByExistingDeviceId
        // create ticket for existing device (and thus existing customer)
        public IActionResult CreateByExistingDeviceId(int deviceId)
        {
            //get the device and check it
            var device = context.Devices.Find(deviceId);

            if (device == null)
            {
                return(View());
            }
            //If it exists create ViewModel and send it to the View
            DeviceEditViewModel model = new DeviceEditViewModel
            {
                Id              = device.Id,
                Make            = device.Make,
                ModelNumber     = device.ModelNumber,
                OperatingSystem = device.OperatingSystem,
                Password        = device.Password,
                Serviced        = device.Serviced,
                Ticket          = new Ticket(),
                Customer        = context.Customers.Find(device.CustomerId),
                CustomerId      = device.CustomerId
            };

            //Get the current Ticket Number
            model.Ticket.TicketNumber = context.Tickets.GetLatestTicketNum() + 1;
            return(View(model));
        }
Ejemplo n.º 4
0
        public IActionResult Edit(string deviceId)
        {
            if (deviceId == null)
            {
                return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.DeviceNotFound }));
            }

            Device device = _deviceRepo.Get(deviceId);

            if (device == null)
            {
                return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.DeviceNotFound }));
            }

            if (!device.User.UserId.Equals(GetCurrentUserAsync().Result.Id))
            {
                return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.NotAuthorized }));
            }

            var model = new DeviceEditViewModel
            {
                Id             = device.Id,
                Hostname       = device.Hostname,
                DeviceType     = device.DeviceType.Name,
                DeviceTypeList = _deviceRepo.GetDeviceTypesAll()
            };

            return(PartialView(model));
        }
Ejemplo n.º 5
0
        public PartialViewResult EditPartial(DeviceEditViewModel device)
        {
            ViewBag.DeviceIDUnit     = new SelectList(db.Units, "ID", "Name", device.IDUnit);
            ViewBag.DeviceIDStatus   = new SelectList(db.Status, "ID", "Name", device.IDStatus);
            ViewBag.DeviceIDCategory = new SelectList(db.Categories, "ID", "Name", device.IDCategory);

            return(PartialView(device));
        }
Ejemplo n.º 6
0
        private void SaveDeviceDetail(DeviceEditViewModel model, string guid)
        {
            foreach (var log in model.Logs)
            {
                Stream stream = log.OpenReadStream();
                using (StreamReader reader = new StreamReader(stream))
                {
                    string strxml = reader.ReadToEnd();

                    DeviceDetail deviceDetail = HelperXML.DESerializer <DeviceDetail>(strxml);
                    deviceDetail.DeviceGUID = guid;

                    _deviceRepository.AddDetail(deviceDetail);
                }
            }
        }
Ejemplo n.º 7
0
        public IActionResult Edit(DeviceEditViewModel model)
        {
            if (model.Id == null)
            {
                return(RedirectToAction("Index", new { dmessage = DeviceMessageId.DeviceNotFound }));
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.ValidationFailed }));
            }

            try
            {
                Device device = _deviceRepo.Get(model.Id);

                var authUserId = GetCurrentUserAsync().Result.Id;
                if (device.Hostname != model.Hostname)
                {
                    if (_deviceRepo.CheckHostnameExists(model.Hostname, authUserId))
                    {
                        return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.HostnameAlreadyExists }));
                    }
                }

                if (!device.User.UserId.Equals(authUserId))
                {
                    return(RedirectToAction(nameof(Index), new { dmessage = DeviceMessageId.NotAuthorized }));
                }

                device.Hostname   = model.Hostname;
                device.DeviceType = _deviceRepo.GetDeviceType(model.DeviceType);
                device.UpdatedOn  = DateTime.Now;

                _deviceRepo.Update(device);
                _logger.LogInformation("User updated one device.");
                return(RedirectToAction("Index", new { dmessage = DeviceMessageId.UpdateDeviceSuccess }));
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
                return(RedirectToAction("Index", new { dmessage = DeviceMessageId.UpdateDeviceFailed }));
            }
        }
        public bool ShowView(CellCultivation device)
        {
            vm = new DeviceEditViewModel <CellCultivation>(device);
            this.DataContext = vm;
            this.ShowDialog();

            Debug.WriteLine("edit end");

            if (vm.isSaved)
            {
                if (CurrentContext.Status == SysStatusEnum.Ready || CurrentContext.Status == SysStatusEnum.Completed)
                {
                    device.Name        = vm.Entity.Name;
                    device.UserName    = vm.Entity.UserName;
                    device.Cell        = vm.Entity.Cell;
                    device.Description = vm.Entity.Description;
                }
            }
            return(vm.isSaved);
        }
Ejemplo n.º 9
0
        public IActionResult Edit(DeviceEditViewModel model)
        {
            //检查提供的数据是否有效,如果没有通过验证,需要重新编辑设备信息
            //这样用户就可以更正并重新提交编辑表单
            if (ModelState.IsValid)
            {
                Device device = _deviceRepository.GetDevice(model.Id);

                device.Name         = model.Name;
                device.ClassName    = model.ClassName;
                device.City         = model.City;
                device.HealthStatus = model.HealthStatus;

                if (model.Photos?.Count > 0)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", model.ExistingPhotoPath);

                        System.IO.File.Delete(filePath);
                    }

                    device.PhotoPath = ProcessUploadedFile(model);
                }

                if (model.Logs?.Count > 0)
                {
                    device.LogPath = ProcessUploadedFileLogs(model);
                    SaveDeviceDetail(model, device.GUID);
                }

                Device updateDevice = _deviceRepository.Update(device);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 10
0
        public ViewResult Edit(int id)
        {
            Device device = _deviceRepository.GetDevice(id);

            if (device != null)
            {
                DeviceEditViewModel deviceEditViewModel = new DeviceEditViewModel
                {
                    Id                = device.Id,
                    GUID              = device.GUID,
                    Name              = device.Name,
                    ClassName         = device.ClassName,
                    City              = device.City,
                    ExistingPhotoPath = device.PhotoPath,
                    ExistingLogsPath  = device.LogPath,
                    HealthStatus      = device.HealthStatus,
                };

                return(View(deviceEditViewModel));
            }

            throw new Exception("查询不到这个设备信息");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 将日志保存到指定的路径中,并返回唯一的路径名
        /// </summary>
        /// <returns></returns>
        private string ProcessUploadedFileLogs(DeviceEditViewModel model)
        {
            string filePath = null;

            if (model.Logs.Count > 0)
            {
                //确定保存路径
                if (model.ExistingLogsPath != null)
                {
                    filePath = model.ExistingLogsPath;
                }
                else
                {
                    string str1 = Path.Combine(webHostEnvironment.WebRootPath, "logs");
                    string str2 = model.Name + "_" + Guid.NewGuid().ToString();

                    filePath = Path.Combine(str1, str2);

                    System.IO.Directory.CreateDirectory(filePath);
                }

                foreach (var log in model.Logs)
                {
                    string path = Path.Combine(filePath, Guid.NewGuid().ToString() + "_" + log.FileName);

                    //因为使用了非托管资源,所以需要手动进行释放
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        //使用IFormFile接口提供的CopyTo()方法见文件赋值到wwwroot/images文件夹
                        log.CopyTo(fileStream);
                    }
                }
            }

            return(filePath);
        }