コード例 #1
0
 public ActionResult Index(int?pg, int?ct)
 {
     if (Session["username"] == null)
     {
         return(RedirectToAction("Login"));
     }
     try
     {
         int page = 1, count = 3;
         if (pg != null && ct != null)
         {
             page  = (int)pg;
             count = (int)ct;
         }
         var db       = new TourWebDBEntities();
         var lstScene = new List <Scene>();
         var query    = (from item in db.Scene
                         orderby item.Sid
                         select new
         {
             Sid = item.Sid,
             Img = item.Img,
             Name = item.Name,
             Position = item.Position,
             Priority = item.Priority,
             Credit = item.Credit,
             Price = item.Price,
             PubTime = item.PubTime
         }).Skip(count * (page - 1)).Take(count).ToList();
         foreach (var item in query)
         {
             lstScene.Add(new Scene
             {
                 Sid      = item.Sid,
                 Img      = item.Img,
                 Name     = item.Name,
                 Position = item.Position,
                 Priority = item.Priority,
                 Credit   = item.Credit,
                 Price    = item.Price,
                 PubTime  = item.PubTime
             });
         }
         var jsonScene = new JObject(
             new JProperty("total", lstScene.Count),
             new JProperty("rows",
                           new JArray(from p in lstScene
                                      select new JObject(new JProperty("Sid", p.Sid), new JProperty("Img", p.Img), new JProperty("Name", p.Name),
                                                         new JProperty("Position", p.Position), new JProperty("Priority", p.Priority), new JProperty("Credit", p.Credit),
                                                         new JProperty("Price", p.Price), new JProperty("PubTime", p.PubTime)))));
         if (Math.Ceiling(jsonScene.Count / 3.0) > page)
         {
             return(RedirectToAction("Index"));
         }
         return(Content(jsonScene.ToString()));
     }
     catch (Exception ex) { return(Content("error")); }
 }
コード例 #2
0
 public ActionResult Register(string username, string password)
 {
     try
     {
         var db   = new TourWebDBEntities();
         var user = new User
         {
             UserName = username,
             Password = password,
             PubTime  = DateTime.Now
         };
         db.User.Add(user);
         db.SaveChanges();
         return(Content("success"));
     }
     catch (Exception ex)
     {
         return(Content("error"));
     }
 }
コード例 #3
0
 public ActionResult AdminLogin(string username, string password)
 {
     try
     {
         TourWebDBEntities db = new TourWebDBEntities();
         var set    = db.Set <Admin>();
         var result = from u in set.ToList()
                      where u.UserName == username && u.Password == password
                      select u;
         if (result.Count() != 0)
         {
             Session["adminuser"] = username;
             return(Content("success"));
         }
         else
         {
             return(Content("error"));
         }
     }
     catch (Exception ex)
     {
         return(Content("error"));
     }
 }