Beispiel #1
0
        public ActionResult Refresh(string id)
        {
            if (!CelebManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            RefreshCelebViewModel refresh = new RefreshCelebViewModel();

            tbl_Celebrity tblceleb = _db.tbl_Celebrity.SingleOrDefault(s => s.celeb_Id == id);

            refresh.Old = new ManageCelebViewModel(tblceleb);

            JObject json = HtmlDecoder.GetJson("https://api.douban.com/v2/movie/celebrity/" + tblceleb.celeb_DoubanID);
            JToken  msg;

            if (json.TryGetValue("msg", out msg))
            {
                refresh.New    = new ManageCelebViewModel();
                refresh.New.Id = refresh.Old.Id;
            }
            else
            {
                tblceleb       = CelebManager.JsonToCeleb(json, Server.MapPath("~/Content/Celeb/"));
                refresh.New    = new ManageCelebViewModel(tblceleb);
                refresh.New.Id = refresh.Old.Id;
            }
            TempData["NewCeleb"] = refresh.New;

            return(View(refresh));
        }
Beispiel #2
0
 public ActionResult Create(CreateCelebViewModel celeb)
 {
     if (!ModelState.IsValid)
     {
         return(View(celeb));
     }
     foreach (var item in celeb.DoubanID.Split('\n'))
     {
         if (item.Trim().Length == 0)
         {
             continue;
         }
         JObject json = HtmlDecoder.GetJson("https://api.douban.com/v2/movie/celebrity/" + item);
         JToken  msg;
         if (json.TryGetValue("msg", out msg))
         {
             ModelState.AddModelError("", string.Format("{0} {1} {2}", "添加编号为", item, "的影人 失败"));
         }
         else
         {
             ModelState.AddModelError("", string.Format("{0}{1}{2}", "添加编号为", item, "的影人 成功"));
             CelebManager.CreateJson(json, Server.MapPath("~/Content/Celeb/"), AccountManager.GetId(User.Identity.Name));
         }
     }
     return(View());
 }
Beispiel #3
0
        public ActionResult Refresh(string id)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            RefreshMovieViewModel refresh = new RefreshMovieViewModel();

            tbl_Movie tblmovie = _db.tbl_Movie.SingleOrDefault(s => s.movie_Id == id);

            refresh.Old = new ManageMovieViewModel(tblmovie);

            JObject json = HtmlDecoder.GetJson("https://api.douban.com/v2/movie/subject/" + tblmovie.movie_DoubanID);
            JToken  msg;

            if (json.TryGetValue("msg", out msg))
            {
                refresh.New    = new ManageMovieViewModel();
                refresh.New.Id = refresh.Old.Id;
            }
            else
            {
                tblmovie       = MovieManager.JsonToMovie(json, Server.MapPath("~/Content/Movie/"));
                refresh.New    = new ManageMovieViewModel(tblmovie);
                refresh.New.Id = refresh.Old.Id;
            }
            TempData["New"] = refresh.New;

            return(View(refresh));
        }
Beispiel #4
0
 public ActionResult Create(CreateMovieViewModel movie)
 {
     if (!ModelState.IsValid)
     {
         return(View(movie));
     }
     foreach (var item in movie.DoubanID.Split('\n'))
     {
         if (item.Trim().Length == 0)
         {
             continue;
         }
         JObject json = HtmlDecoder.GetJson("https://api.douban.com/v2/movie/subject/" + item.Replace("https://movie.douban.com/subject/", "").Replace("/", ""));
         JToken  msg;
         if (json.TryGetValue("msg", out msg))
         {
             ModelState.AddModelError("", string.Format("{0} {1} {2}", "添加编号为", item, "的电影 失败"));
         }
         else
         {
             ModelState.AddModelError("", string.Format("{0} {1} {2}", "添加编号为", item, "的电影 成功"));
             MovieManager.CreateJson(json, Server.MapPath("~/Content/Movie/"), AccountManager.GetId(CookieHepler.GetCookie("user")));
         }
     }
     return(View());
 }
Beispiel #5
0
        public void Case1()
        {
            var obj = new SampleClass1
            {
                Text1 = "Admin's Fats1 Ping"
            };

            HtmlDecoder.ReplaceStrings(obj);

            obj.Text1.Should().Be("Admin's Fats1 Ping");
        }
        public IHttpResponse RegisterPost(IHttpRequest request)
        {
            var userName        = request.FormData["username"].ToString().Trim();
            var password        = request.FormData["password"].ToString();
            var confirmPassword = request.FormData["confirmPassword"].ToString();
            var email           = HtmlDecoder.Decode(request.FormData["email"].ToString());


            if (string.IsNullOrWhiteSpace(userName) || userName.Length < 3)
            {
                return(this.BadRequestError("Username should be more than 2 characters"));
            }

            if (this.DbContext.Users.Any(x => x.Username == userName))
            {
                return(this.BadRequestError("This username already exists in the database!"));
            }

            if (string.IsNullOrWhiteSpace(password) || password.Length < 6)
            {
                return(this.BadRequestError("The password should be at least 6 characters!"));
            }

            if (password != confirmPassword)
            {
                return(this.BadRequestError("Password and Confirm password fields do not match!"));
            }

            //Hashing password
            string hashedPassword = this.passwordHasher.HashPassword(password);

            var user = new User
            {
                Username         = userName,
                Password         = hashedPassword,
                Email            = email,
                RegistrationDate = DateTime.UtcNow,
            };

            //Save data in the DB
            try
            {
                this.DbContext.Users.Add(user);
                this.DbContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(this.ServerError(e.Message));
            }

            //Redirect to home page
            return(new RedirectResult("/"));
        }
        public IHttpResponse SetNewPasswordPost(IHttpRequest request)
        {
            var email = HtmlDecoder.Decode(request.FormData["email"].ToString());

            if (!this.DbContext.Users.Any(x => x.Email == email))
            {
                return(this.View("InvalidEmail"));
            }

            return(new RedirectResult("/"));
            //TODO rendom password generator for generating temp password
            //TODO find a way to sent the temp password to the user email
        }
        public IHttpResponse EditUsersDetailsPost(IHttpRequest request)
        {
            if (!this.IsAuthenticated(request))
            {
                return(new RedirectResult("/users/login"));
            }

            var username = request.Session.GetParameter("username").ToString();
            var user     = this.DbContext.Users.FirstOrDefault(x => x.Username == username);

            this.ViewBag["username"] = user.Username;

            var updatedEmail = HtmlDecoder.Decode(request.FormData["email"].ToString());

            if (this.DbContext.Users.Any(x => x.Email == updatedEmail))
            {
                this.ViewBag["email"]  = user.Email;
                this.ViewBag["allert"] = ExistingEmailAllert;
                return(this.View("EditProfile"));
            }

            user.Email = updatedEmail;

            try
            {
                this.DbContext.Users.Update(user);
                this.DbContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(this.ServerError(e.Message));
            }

            this.ViewBag["email"]  = user.Email;
            this.ViewBag["allert"] = SuccessfullyUpdatedEmailAllert;
            return(this.View("EditProfile"));
        }
Beispiel #9
0
 protected override void             DecodeHtmlInStrings <T>(T obj) => HtmlDecoder.ReplaceStrings(obj);