void ValidateRequest(ManualViewModel model)
 {
     if (String.IsNullOrEmpty(model.Title))
     {
         ModelState.AddModelError("title", "請填寫標題");
     }
 }
示例#2
0
        public ManuelView()
        {
            InitializeComponent();
            DataContext = new ManualViewModel();

            //{Binding VM_aileron}
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(
            SearchViewModel searchViewModel,
            ManualViewModel manualViewModel,
            SettingsViewModel settingsViewModel,
            ShowTrackerViewModel showTrackerViewModel)
        {
            this.Version = ApplicationDeployment.IsNetworkDeployed
                ? $"ver. {ApplicationDeployment.CurrentDeployment.CurrentVersion}"
                : "ver. DEBUG";

            this.SearchViewModel      = searchViewModel;
            this.ManualViewModel      = manualViewModel;
            this.SettingsViewModel    = settingsViewModel;
            this.ShowTrackerViewModel = showTrackerViewModel;

            this.Width  = Properties.Settings.Default.WindowWidth;
            this.Height = Properties.Settings.Default.WindowHeight;

            ListSearchCommand  = new RelayCommand(OpenListSearch);
            InputSearchCommand = new RelayCommand(OpenInputSearch);
            SettingsCommand    = new RelayCommand(OpenSettings);
            ShowTrackerCommand = new RelayCommand(OpenShowTracker);

            OpenListSearch(); //Default open window
        }
        public async Task <IActionResult> Manual(String title, String userCreator)
        {
            //TODO test
            var manual = await _context.Manuals.FirstOrDefaultAsync(manuals =>
                                                                    manuals.UserCreator == userCreator &&
                                                                    manuals.Title == title);

            if (manual != null)
            {
                var user = await _context.Users.FirstOrDefaultAsync(us =>
                                                                    us.UserName == userCreator);

                var manualViewModel = new ManualViewModel
                {
                    Title            = manual.Title,
                    Body             = manual.Body,
                    Creator          = manual.UserCreator,
                    ShortDescription = manual.ShortDescription,
                    AmountLike       = manual.AmountLike,
                    Rating           = manual.Rating,
                    Tags             = GetTagsManuals(manual.Tags),
                    ImageManual      = manual.ManualImage,
                    OtherManualsUser = user.GetUserManuals()
                };

                return(View(manualViewModel));
            }
            return(NotFound(title));
        }
示例#5
0
        public ActionResult CreateNewManual(string ReturnUrl)
        {
            ManualViewModel model = new ManualViewModel();

            ViewBag.ReturnUrl = ReturnUrl;
            return(View(model));
        }
 public Manual()
 {
     InitializeComponent();
     vm = new ManualViewModel(new VirtualJoystickEventArgs());
     this.DataContext = vm;
     InitializeComponent();
 }
示例#7
0
        private void CalculateRating(ManualViewModel manual, string userId, bool liked)
        {
            Rating rating = ratingRepository.GetAll()
                            .FirstOrDefault(e => e.UserId == userId && e.ManualId == manual.Id);

            if (rating == null)
            {
                ratingRepository.Add(new Rating
                {
                    ManualId = manual.Id,
                    UserId   = userId,
                    Liked    = liked
                });
            }
            else if (rating.Liked != liked)
            {
                if (rating.Liked == null)
                {
                    rating.Liked = liked;
                }
                else
                {
                    rating.Liked = null;
                }
                ratingRepository.Update(rating);
            }
            ratingRepository.Save();
        }
示例#8
0
        public ActionResult Create([Bind] ManualViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Manual manual = new Manual
                {
                    Name     = vm.Name,
                    FileName = vm.File.FileName
                };

                FileData data = new FileData();
                using (Stream inputStream = vm.File.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    data.Data = memoryStream.ToArray();
                }

                manual.FileData = data;

                db.Manuals.Add(manual);
                db.SaveChanges();
                return(RedirectToAction("Index", "Manuals"));
            }

            return(View(vm));
        }
示例#9
0
 public ManualView()
 {
     InitializeComponent();
     DataContext = new ManualViewModel();
     Debug.WriteLine($"Actual width: {SystemParameters.PrimaryScreenWidth}");
     Debug.WriteLine($"Actual height: {SystemParameters.PrimaryScreenHeight}");
 }
示例#10
0
 public ManualView()
 {
     InitializeComponent();
     vm = new ManualViewModel();
     this.DataContext     = vm;
     joystick.DataContext = vm;
 }
示例#11
0
        public ActionResult AddComment(string content, string userId, int manualId)
        {
            Comment toAdd = new Comment()
            {
                AuthorId  = userId,
                Content   = mark.Transform(content),
                ManualId  = manualId,
                VoteCount = 0,
            };
            Manual manual = context.Manuals.Find(manualId);

            manual.LastUpdate = DateTime.Today;
            context.Comments.Add(toAdd);
            context.SaveChanges();
            ManualViewModel model = new ManualViewModel()
            {
                Manual   = manual,
                User     = context.ApplicationUsers.Find(userId),
                Steps    = context.Steps.Where(s => s.ManualId == manualId).ToList(),
                Tags     = ManualHelper.GetAllManualTags(manualId, context),
                Comments = context.Comments.Where(c => c.ManualId == manualId).ToList(),
                Context  = context
            };

            return(View("Manual", model));
        }
示例#12
0
        public IActionResult LikeComment(string userId, int commentId, string path)
        {
            Comment comment = context.Comments.Find(commentId);

            if (context.Votes.Where(c => c.CommentId == commentId && c.UserId == userId).ToList().Count == 0)
            {
                comment.VoteCount++;
                Vote vote = new Vote()
                {
                    CommentId = commentId,
                    UserId    = userId,
                };
                context.Votes.Add(vote);
            }
            Manual manual = context.Manuals.Find(comment.ManualId);

            context.SaveChanges();
            ManualViewModel model = new ManualViewModel()
            {
                Manual   = manual,
                User     = context.ApplicationUsers.Find(userId),
                Steps    = context.Steps.Where(s => s.ManualId == manual.ManualId).ToList(),
                Tags     = ManualHelper.GetAllManualTags(manual.ManualId, context),
                Comments = context.Comments.Where(c => c.ManualId == manual.ManualId).ToList(),
                Context  = context
            };

            return(View("Manual", model));
        }
示例#13
0
        private ManualViewModel manual_vm;      // view model instance of manual

        /**
         *  the constructor creates presentation of Manual Control based on the xaml code
         *  and initialized his properties
         **/
        public ManualControl()
        {
            InitializeComponent();
            manual_vm = new ManualViewModel();
            /* changes the data context to view model */
            DataContext = manual_vm;
        }
 public ManualPilot()
 {
     InitializeComponent();
     this.vm          = new ManualViewModel();
     this.DataContext = vm;
     // Registering the Joystick_Move method to the Moved event in the Joystick.
     this.Joystick.Moved += this.vm.Joystick_Move;
 }
示例#15
0
        public Manual()
        {
            InitializeComponent();
            Commands c = Commands.Instance;

            vm          = new ManualViewModel();
            DataContext = vm;
        }
示例#16
0
        public ActionResult ChangeRating(ManualViewModel manual, bool liked)
        {
            string currentUserId = User.Identity.GetUserId();

            CalculateRating(manual, currentUserId, liked);
            int rating = GetRating(manual.Id);

            return(Json(new { newRating = rating }));
        }
示例#17
0
 /// <summary>
 /// Displays the Search View.
 /// </summary>
 private void OpenInputSearch()
 {
     IsListSearchSelected   = false;
     IsManualSearchSelected = true;
     IsSettingsSelected     = false;
     IsShowTrackerSelected  = false;
     SelectedViewModel      = ManualViewModel;
     ManualViewModel.OnPresented();
 }
示例#18
0
 public Joystick()
 {
     InitializeComponent();
     vm = ManualViewModel.Instance;
     Knob.MouseLeftButtonDown += Knob_MouseLeftButtonDown;
     Knob.MouseLeftButtonUp   += Knob_MouseLeftButtonUp;
     Knob.MouseMove           += Knob_MouseMove;
     Moved     += vm.WhenMoved;
     centerKnob = Knob.Resources["CenterKnob"] as Storyboard;
 }
示例#19
0
        public ActionResult DeleteManual(ManualViewModel manual)
        {
            if (User.IsInRole("Admin") || manual.UserId == User.Identity.GetUserId())
            {
                manualRepository.Delete(manual.Id);
                manualRepository.Save();
            }

            return(null);
        }
示例#20
0
        public Joystick()
        {
            InitializeComponent();
            vm = new ManualViewModel();
            this.DataContext          = vm;
            Knob.MouseLeftButtonDown += Knob_MouseLeftButtonDown;
            Knob.MouseLeftButtonUp   += Knob_MouseLeftButtonUp;
            Knob.MouseMove           += Knob_MouseMove;

            centerKnob = Knob.Resources["CenterKnob"] as Storyboard;
        }
示例#21
0
        public async Task <ActionResult> RegManual(ManualViewModel manualViewModel, IEnumerable <HttpPostedFileBase> files)
        {
            ViewBag.LeftMenu = Global.Cs;

            var scForm =
                Mapper.Map <ScForm>(manualViewModel);

            scForm.Status = "N";
            scForm.RegDt  = DateTime.Now;
            scForm.RegId  = Session[Global.LoginID].ToString();


            //첨부파일
            if (files != null)
            {
                var fileHelper = new FileHelper();
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        var savedFileName = fileHelper.GetUploadFileName(file);

                        var subDirectoryPath = Path.Combine(FileType.Manual.ToString(), DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString());

                        var savedFilePath = Path.Combine(subDirectoryPath, savedFileName);

                        var scFileInfo = new ScFileInfo {
                            FileNm = Path.GetFileName(file.FileName), FilePath = savedFilePath, Status = "N", RegId = Session[Global.LoginID].ToString(), RegDt = DateTime.Now
                        };

                        var scFormFile = new ScFormFile {
                            ScFileInfo = scFileInfo
                        };
                        scForm.ScFormFiles.Add(scFormFile);

                        await fileHelper.UploadFile(file, subDirectoryPath, savedFileName);
                    }
                }
            }

            //저장
            int result = await _scFormService.AddScFormAsync(scForm);

            if (result != -1)
            {
                return(RedirectToAction("Manual", "Cs"));
            }
            else
            {
                ModelState.AddModelError("", "메뉴얼 등록 실패.");
                return(View(manualViewModel));
            }
        }
示例#22
0
        public static Manual MapEntity(this ManualViewModel model, IMapper mapper, string currentUserId)
        {
            var entity = mapper.Map <ManualViewModel, Manual>(model);

            if (model.Id == 0)
            {
                entity.SetCreated(currentUserId);
            }
            entity.SetUpdated(currentUserId);

            entity.Content = entity.Content.ReplaceNewLine("");
            return(entity);
        }
示例#23
0
        public Joystick()
        {
            InitializeComponent();

            Knob.MouseLeftButtonDown += Knob_MouseLeftButtonDown;
            Knob.MouseLeftButtonUp   += Knob_MouseLeftButtonUp;
            Knob.MouseMove           += Knob_MouseMove;

            centerKnob  = Knob.Resources["CenterKnob"] as Storyboard;
            vm          = ManualViewModel.Instance;
            DataContext = vm;
            Moved      += vm.update;
            Released   += vm.reset;
        }
示例#24
0
        public ActionResult DeleteConfirmed(int id)
        {
            Manual manual = db.Manuals.Include("FileData").SingleOrDefault(x => x.Id == id);

            ManualViewModel vm = new ManualViewModel
            {
                Id   = manual.Id,
                Name = manual.Name
            };

            db.FileDatas.Remove(manual.FileData);
            db.Manuals.Remove(manual);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Store([FromBody] ManualViewModel model)
        {
            ValidateRequest(model);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.Order = model.Active ? 0 : -1;

            var manual = model.MapEntity(_mapper, CurrentUserId);

            manual = await _manualsService.CreateAsync(manual);

            return(Ok(manual.Id));
        }
示例#26
0
 public ActionResult Save(ManualViewModel model)
 {
     try
     {
         string pathFile     = @"~/App_Data/Manual.txt";
         var    fileContents = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(pathFile));
         System.IO.File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath(pathFile), model.ManualText);
         DisplaySuccessMessage("Successfully updated manual text!");
         return(RedirectToAction("Index", "Admin"));
     }
     catch (Exception e)
     {
         DisplayErrorMessage("Error ocurred, failed updating manual text!");
         return(RedirectToAction("Index"));
     }
 }
示例#27
0
 public ActionResult Index()
 {
     try
     {
         string          pathFile     = @"~/App_Data/Manual.txt";
         var             fileContents = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(pathFile));
         ManualViewModel mvm          = new ManualViewModel();
         mvm.ManualText = fileContents;
         return(View(mvm));
     }
     catch (Exception e)
     {
         DisplayErrorMessage("Error ocurred, failed loading current manual text, enter new and save!");
         return(View());
     }
 }
示例#28
0
        public async Task <IActionResult> Manual(int id)
        {
            var user = await _userManager.GetUserAsync(User);

            Manual          manual = context.Manuals.Find(id);
            ManualViewModel model  = new ManualViewModel
            {
                Manual   = manual,
                Steps    = context.Steps.Where(s => s.ManualId == manual.ManualId).ToList(),
                Comments = context.Comments.Where(c => c.ManualId == manual.ManualId).ToList(),
                User     = user,
                Context  = context,
                Tags     = ManualHelper.GetAllManualTags(id, context)
            };

            return(View(model));
        }
示例#29
0
 public ActionResult CreateNewManual(ManualViewModel model, string ReturnUrl = "/")
 {
     if (ModelState.IsValid)
     {
         var currentUserId = User.Identity.GetUserId();
         model.UserId    = currentUserId;
         model.DateAdded = DateTime.Now;
         if (model.TemplateId == 3)
         {
             model.VideoLink = model.VideoLink.Substring(model.VideoLink.IndexOf("v=") + 2, 11);
         }
         Manual manual = Mapper.Map <Manual>(model);
         manualRepository.Add(manual);
         manualRepository.Save();
         MedalsCheck();
         return(Json(new { result = "Redirect", url = ReturnUrl }));
     }
     return(View(model));
 }
示例#30
0
        // GET: Manuals/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Manual manual = db.Manuals.SingleOrDefault(x => x.Id == id);

            if (manual == null)
            {
                return(HttpNotFound());
            }

            ManualViewModel vm = new ManualViewModel
            {
                Id   = manual.Id,
                Name = manual.Name,
            };

            return(View(vm));
        }