Пример #1
0
        public int GetLoginPageTag(ActionExecutingContext context)
        {
            int            result = 0;
            string         IP     = context.HttpContext.Request.UserHostAddress;
            LoginPageTrail tmpLPT = db.LoginPageTrails.FirstOrDefault(r => r.ClientIP.CompareTo(IP) == 0);

            if (tmpLPT != null)
            {
                if (tmpLPT.ErrorCount > LOGINLOCK)
                {
                    result = -2;
                    DateTime tmpDT = DateTime.Parse(tmpLPT.LogDate);
                    tmpDT = tmpDT.AddSeconds(LOCKTIME);
                    TimeSpan tmpTS = tmpDT - DateTime.Now;
                    if (tmpTS.TotalSeconds < 0)
                    {
                        tmpLPT.ErrorCount = 0;
                        db.SaveChanges();
                        result      = 0;
                        waitSeconds = 0;
                    }
                    else
                    {
                        waitSeconds = (int)tmpTS.TotalSeconds;
                    }
                }
                else if (tmpLPT.ErrorCount > CHECKCODESHOW)
                {
                    result = -1;
                }
            }
            return(result);
        }
Пример #2
0
        public void WriteTrail(HttpRequest request)
        {
            ClientTrail tmpCT = new ClientTrail();

            tmpCT.URL = request.Url.ToString();
            if (request.RequestContext.RouteData.Route != null)
            {
                object tmpObj = request.RequestContext.RouteData.Route.GetRouteData(request.RequestContext.HttpContext).Values["controller"];
                tmpCT.ControllerName = tmpObj != null?tmpObj.ToString() : "";

                tmpObj           = request.RequestContext.RouteData.Route.GetRouteData(request.RequestContext.HttpContext).Values["action"];
                tmpCT.ActionName = tmpObj != null?tmpObj.ToString() : "";
            }
            else
            {
                tmpCT.ControllerName = "";
                tmpCT.ActionName     = "";
            }
            tmpCT.ClientIP = request.UserHostAddress;
            tmpCT.LogDate  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            if (request.RequestContext.HttpContext.User.Identity.IsAuthenticated)
            {
                MyUser tmpUser = request.RequestContext.HttpContext.User as MyUser;
                if (tmpUser != null)
                {
                    tmpCT.UID = tmpUser.UID;
                }
            }
            db.ClientTrails.Add(tmpCT);
            db.SaveChanges();
        }
Пример #3
0
        private async void izbrisiFilm(object parametar)
        {
            int kolekcijaID = OdabraniFilm.KolekcijaId;

            if (OdabraniFilm != null)
            {
                using (var db = new FilmDbContext())
                {
                    db.Filmovi.Remove(db.Filmovi.Where(x => x.FilmId == OdabraniFilm.FilmId).FirstOrDefault());
                    db.SaveChanges();
                }

                using (var db = new FilmDbContext())
                {
                    MojiFilmoviIzKolekcije.Clear();
                    foreach (Film k in db.Filmovi)
                    {
                        if (k.KolekcijaId == kolekcijaID)
                        {
                            MojiFilmoviIzKolekcije.Add(k);
                        }
                    }
                }
            }
            else
            {
                var dialog = new MessageDialog("Niste odabrali film.");
                await dialog.ShowAsync();
            }
        }
Пример #4
0
        private async void dodajFilm(object parametar)
        {
            if (OdabraniFilm != null && OdabranaKolekcija != null)
            {
                using (var db = new FilmDbContext())
                {
                    int max = -1;
                    foreach (Film k in db.Filmovi)
                    {
                        if (k.FilmId > max)
                        {
                            max = k.FilmId;
                        }
                    }
                    max++;

                    Film novi = new Film(max);
                    novi             = OdabraniFilm;
                    novi.FilmId      = max;
                    novi.KolekcijaId = OdabranaKolekcija.KolekcijaId;
                    novi.KorisnikId  = Korisnik.KorisnikId;

                    db.Filmovi.Add(novi);
                    db.SaveChanges();
                }

                var dialog = new MessageDialog("Film uspjesno sacuvan");
                await dialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog("Oznacite film ili kolekciju.");
                await dialog.ShowAsync();
            }
        }
Пример #5
0
 private void NewActor()
 {
     using (var db = new FilmDbContext(_connectionName))
     {
         var actor = _view.GetNewActor();
         db.Actors.Add(actor);
         db.SaveChanges();
     }
 }
Пример #6
0
        private void NewFilm()
        {
            var newFilm = _view.GetNewFilmInfo();

            using (var db = new FilmDbContext(_connectionName))
            {
                db.Films.Add(newFilm);
                db.SaveChanges();
                _view.WriteFilmList(db.Films.ToList());
            }
        }
Пример #7
0
        public ActionResult SearchResource(string searchText, int pageIndex)
        {
            if (pageIndex <= 1)
            {
                try
                {
                    SearchLog tmpLog = new SearchLog();
                    tmpLog.IPAddress   = Request.UserHostAddress;
                    tmpLog.LogDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    tmpLog.SearchStr   = searchText;
                    db.SearchLogs.Add(tmpLog);
                    db.SaveChanges();
                }
                catch
                {
                }
            }

            SearchResult result = new SearchResult();

            result.PageIndex = pageIndex;

            string htmlStr = HtmlReader.OpenSync(string.Format(SEARCHHTMLFORMAT, searchText, pageIndex));

            if (!string.IsNullOrEmpty(htmlStr))
            {
                HtmlAnalyser analyser             = new HtmlAnalyser(htmlStr);
                HtmlAnalyser.MagnetResult[] tmpMC = analyser.GetResult();
                result.Items = new List <ResourceItem>();
                foreach (HtmlAnalyser.MagnetResult item in tmpMC)
                {
                    ResourceItem resourceItem = new ResourceItem();
                    resourceItem.ResourceName = item.Description;
                    resourceItem.MagnetLink   = item.MargnetLink;
                    resourceItem.Date         = item.Date;
                    resourceItem.Size         = item.Size;
                    resourceItem.SeedLink     = item.SeedLink;
                    resourceItem.DetailUrl    = HOMEPAGEURL + item.DetailLink;
                    result.Items.Add(resourceItem);
                }
                result.PageCount = analyser.GetPageCount();
            }

            if (Request.IsAjaxRequest())
            {
                string jsonStr = PubFunction.BuildResult(result);
                return(Content(jsonStr));
            }
            else
            {
                return(View(result));
            }
        }
Пример #8
0
        private void NewFilmRating()
        {
            using (var db = new FilmDbContext(_connectionName))
            {
                var films      = db.Films.ToList();
                var filmChoice = _view.GetFilmChoice(films);
                var filmRating = _view.GetNewFilmRating();
                filmRating.Film = filmChoice;

                db.FilmRatings.Add(filmRating);
                db.SaveChanges();
            }
        }
Пример #9
0
        private void AddActorToFilm()
        {
            using (var db = new FilmDbContext(_connectionName))
            {
                var actor = _view.GetActorChoice(db.Actors.ToList());

                var film = _view.GetFilmChoice(db.Films.ToList());

                film.Actors.Add(actor);

                db.SaveChanges();
            }
        }
Пример #10
0
        private void UpdateFilm()
        {
            using (var db = new FilmDbContext(_connectionName))
            {
                var films       = db.Films.ToList();
                var filmChoice  = _view.GetFilmChoice(films);
                var newFilmInfo = _view.GetNewFilmInfo();
                filmChoice.Name        = newFilmInfo.Name;
                filmChoice.Description = newFilmInfo.Description;
                filmChoice.Genre       = newFilmInfo.Genre;

                db.SaveChanges();
            }
        }
Пример #11
0
        public bool AddRev(AddReview request)
        {
            if (request.SeeReview != null && request.MovieId > 0)
            {
                //var movie = db.Movies.Where(a => a.MovieId == request.MovieId).FirstOrDefault();

                Reviews review = new Reviews();
                review.Review  = request.SeeReview;
                review.MovieId = request.MovieId;
                db.Review.Add(review);
                db.SaveChanges();
                return(true);
            }
            return(false);
        }
Пример #12
0
        private async void izbrisiKolekciju(object parametar)
        {
            if (OdabranaKolekcija != null)// && OdabranaKolekcija.Naziv!="")
            {
                using (var db = new FilmDbContext())
                {
                    for (int i = 0; i < MojiFilmoviIzKolekcije.Count; i++)
                    {
                        db.Filmovi.Remove(db.Filmovi.Where(x => x.KolekcijaId == OdabranaKolekcija.KolekcijaId).FirstOrDefault());
                    }
                    db.SaveChanges();
                }
                MojiFilmoviIzKolekcije.Clear();

                using (var db = new KolekcijaDbContext())
                {
                    db.Kolekcije.Remove(db.Kolekcije.Where(x => x.KorisnikId == korisnik.KorisnikId && x.KolekcijaId == OdabranaKolekcija.KolekcijaId).FirstOrDefault());

                    db.SaveChanges();

                    MojeKolekcije.Clear();


                    foreach (Kolekcija k in db.Kolekcije)
                    {
                        if (k.KorisnikId == korisnik.KorisnikId)
                        {
                            MojeKolekcije.Add(k);
                        }
                    }
                }


                var dialog1 = new MessageDialog("Kolekcija uspješno obrisana.");
                await dialog1.ShowAsync();
            }
            else
            {
                var dialog1 = new MessageDialog("Niste oznacili kolekciju.");
                await dialog1.ShowAsync();
            }
        }
Пример #13
0
        public ActionResult Register(string userName, string email, string psw, string checkCode)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(psw) || string.IsNullOrEmpty(checkCode) || string.IsNullOrEmpty(Session["Validate_code"].ToString()))
            {
                if (Request.IsAjaxRequest())
                {
                    string jsonStr = PubFunction.BuildResult("err", null, false, -4);
                    return(Content(jsonStr));
                }
                else
                {
                    return(RedirectToAction("Register", "Home"));
                }
            }
            User user = null;

            if (checkCode != (Session["Validate_code"].ToString()))
            {
                ViewBag.LoginFail = -1;
                return(Content(PubFunction.BuildResult(null, null, false, -1, "验证码错误")));
            }
            else
            {
                user = db.Users.FirstOrDefault(r => (r.UserName == userName || r.Email == email));
                if (user != null)
                {
                    //用户已存在
                    bool UNExists = user.UserName == userName;
                    return(Content(PubFunction.BuildResult(null, null, false, UNExists ? -2 : -3, UNExists ? "用户名已被注册" : "邮箱已被注册")));
                }
                else
                {
                    //创建用户
                    user = new User()
                    {
                        UserName   = userName,
                        LoginID    = userName,
                        LoginPSW   = psw,
                        Email      = email,
                        Sex        = false,
                        Permission = "",
                        Gift       = 100 //100积分
                    };
                    user = db.Users.Add(user);
                    //关联角色
                    Role role = db.Roles.First(r => r.RID == (int)Role.RoleTypeID.RT_CLIENT);
                    if (role.Users == null)
                    {
                        role.Users = new List <User>();
                    }
                    role.Users.Add(user);
                    db.SaveChanges();
                    //设置cookie
                    StringBuilder tmpRPStr  = new StringBuilder("," + user.Permission + ",");
                    StringBuilder tmpRIDStr = new StringBuilder(",");
                    StringBuilder tmpRNStr  = new StringBuilder(",");
                    foreach (Role tmpRole in user.Roles)
                    {
                        tmpRIDStr.Append(tmpRole.RID + ",");
                        tmpRNStr.Append(tmpRole.RoleName + ",");
                        tmpRPStr.Append(tmpRole.Permission + ",");
                    }
                    string tmpStr = string.Format("<USERID>{0}</USERID><USERNAME>{1}</USERNAME><RIDARR>{2}</RIDARR><RNARR>{3}</RNARR><PERMISSION>{4}</PERMISSION>", user.UID, user.UserName, tmpRIDStr.ToString(), tmpRNStr.ToString(), tmpRPStr.ToString());

                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                        1,
                        user.UserName,
                        DateTime.Now,
                        DateTime.Now.AddMinutes(30),
                        true,
                        tmpStr);
                    string     encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    HttpCookie authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    Response.Cookies.Add(authCookie);

                    authCookie = new HttpCookie("UserInfo");
                    authCookie.Values.Add("UID", user.UID.ToString());
                    authCookie.Values.Add("UserName", user.UserName);
                    authCookie.Values.Add("RID", tmpRIDStr.ToString());
                    authCookie.Values.Add("Permission", tmpRPStr.ToString());
                    Response.Cookies.Add(authCookie);
                }
            }
            if (Request.IsAjaxRequest())
            {
                string jsonStr = PubFunction.BuildResult(user);
                return(Content(jsonStr));
            }
            else
            {
                return(View(user));
            }
        }
Пример #14
0
 public void Commit()
 {
     _databaseContext.SaveChanges();
 }