// GET: Greeting
        // Index is default action if action is not specified in teh ulr /controller/action/id
        public ActionResult Index(string name)
        {
            //mvv controller will go look for name arg, it could look for in the query string

            // controller to build a model to contain the information to render (view model)
            var model = new GreetingViewModel();

            // directly look for the query string in the url, but can just pass in the name as an argument to the Index method
            //var name = HttpContext.Request.QueryString["name"];
            model.Name    = name ?? "no name";
            model.Message = ConfigurationManager.AppSettings["message"];

            return(View(model));
        }
        public ActionResult Index(string name)
        {
            var model = new GreetingViewModel();

            //access http context directly but this is not needed with asp.net mvc since
            // you can insterad pass it as parameter into the method and MVC framework
            // will do anything it can to populate that param.  It will look in QueryString
            // and find it there (among others).
            //var name = HttpContext.Request.QueryString["name"];
            // on Windows, this would use ConfigurationManager.AppSettings
            model.Message = ConfigurationSettings.AppSettings["message"];
            model.Name    = name ?? "No name";
            return(View(model));
        }
Beispiel #3
0
        // GET: Greeting
        public ActionResult Index(string name)
        {
            var model = new GreetingViewModel();

            //var nameQueryString = HttpContext.Request.QueryString["name"];
            //Generally when we work with MVC5 you do not need to access HttpContext property directly
            //You just add variable in action method as argument and MVC5 automatically find from QueryString
            model.Message = ConfigurationManager.AppSettings["message"];
            model.Name    = name ?? "Anonymous";// ?? is null collation operator
            //ASP.Net also apply some built-In protection to prevent script tag into queryString
            //Also RazorView also provide one more aditional security layer and display
            //Script string as plain text
            return(View(model));
        }
        public ActionResult Create(Greeting greeting, HttpPostedFileBase photo, HttpPostedFileBase video)
        {
            if (ModelState.IsValid)
            {
                if (!isValidContentType((photo.ContentType)))
                {
                    ViewBag.Error             = "Only JPG, JPEG, PNG & Gif files are allowed";
                    ViewBag.categoryDetailsID = new SelectList(db.Category_Details, "id", "name");
                    return(View("Create"));
                }
                if (video != null && !isValidContentTypeVideo((video.ContentType)))
                {
                    ViewBag.Error             = "Only MP4 and WEBM files are allowed";
                    ViewBag.categoryDetailsID = new SelectList(db.Category_Details, "id", "name");
                    return(View("Create"));
                }
                else
                {
                    string path = Server.MapPath("~/Content/uploadedgreeting/" + photo.FileName);
                    photo.SaveAs(path);

                    if (video != null)
                    {
                        string pathVid = Server.MapPath("~/Content/uploadedgreeting/video/" + video.FileName);
                        video.SaveAs(pathVid);
                    }

                    GreetingViewModel greetingViewModel = new GreetingViewModel();
                    greetingViewModel.greeting = new Greeting();

                    greetingViewModel.greeting.photo = photo.FileName;
                    if (video != null)
                    {
                        greetingViewModel.greeting.video = video.FileName;
                    }

                    greetingViewModel.greeting.categoryDetailsID = greeting.categoryDetailsID;



                    db.Greetings.Add(greetingViewModel.greeting);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.categoryDetailsID = new SelectList(db.Category_Details, "id", "name", greeting.categoryDetailsID);
            return(View(greeting));
        }
Beispiel #5
0
        public LaunchViewModel(
            ConfigService configService,
            ThemeService themeService,
            VersionService versionService,
            LibraryService libraryService,
            AssetService assetService,
            AccountService accountService,
            AuthService authService,
            AuthlibInjectorService authlibInjectorService,
            LaunchService launchService,

            IWindowManager windowManager,
            GreetingViewModel greetingVM,
            VersionsManagementViewModel versionsVM,
            LaunchStatusViewModel statusVM,
            AccountEditViewModel accountEditVM,
            DownloadStatusViewModel downloadVM,
            ErrorReportViewModel errorReportVM,
            ProfileSelectViewModel profileSelectVM)
        {
            _windowManager = windowManager;
            _config        = configService.Entries;

            _versionService         = versionService;
            _libraryService         = libraryService;
            _assetService           = assetService;
            _accountService         = accountService;
            _authService            = authService;
            _authlibInjectorService = authlibInjectorService;
            _launchService          = launchService;

            _statusVM         = statusVM;
            _accountEditVM    = accountEditVM;
            _profileSelectVM  = profileSelectVM;
            _downloadStatusVM = downloadVM;
            _errorReportVM    = errorReportVM;

            _launchService.ErrorReceived += errorMessage => _logger.Append(errorMessage);
            _launchService.Exited        += OnGameExited;

            _versionService.Loaded  += hasAny => HasVersion = hasAny;
            _versionService.Created += _ => HasVersion = true;

            _statusVM.Closed += (sender, e) => OnLaunchCompleted();

            ThemeService = themeService;
            GreetingVM   = greetingVM;
            VersionsVM   = versionsVM;
        }
Beispiel #6
0
        public AccountSettingsViewModel(
            AccountService accountService,
            IWindowManager windowManager,
            AccountEditViewModel accountEditVM,
            GreetingViewModel greetingVM)
        {
            _windowManager     = windowManager;
            _accountEditEditVM = accountEditVM;
            _greetingVM        = greetingVM;

            _accountService = accountService;
            Accounts        = new BindableCollection <Account>(_accountService.GetAll());
            SelectedAccount = _accountService.GetSelected();

            _accountService.Created += account => Accounts.Add(account);
        }
Beispiel #7
0
        public ActionResult Create(GreetingViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var greeting = Mapper.Map <Greeting>(viewModel);

                    _greetingService.Insert(greeting);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(viewModel));
                }
            }

            return(View(viewModel));
        }
        public ActionResult ModelBindingInSeparateModel(GreetingViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                if (model.Name.ToLowerInvariant().Contains("admin"))
                {
                    this.ModelState.AddModelError("Name", "You are not admin");
                    return(this.View(model));
                }

                var greeting    = this.greetingService.GetGreeting(model.Name);
                var resultModel = new GreetingResultViewModel
                {
                    Greeting = greeting
                };

                return(this.View("Result", resultModel));
            }

            return(this.View(model));
        }
Beispiel #9
0
        public ActionResult Edit(int id, GreetingViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var greeting = Mapper.Map <Greeting>(viewModel);

                    _greetingService.Update(greeting);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View(viewModel));
                }
            }
            else
            {
                return(View(viewModel));
            }
        }
 public GreetingView()
 {
     ViewModel = new GreetingViewModel();
 }
Beispiel #11
0
 public IActionResult Index(GreetingViewModel model)
 {
     return(View(model));
 }