Example #1
0
        public string CheckLogin(string userName, string password)
        {
            string passwordDes = EncryptAndDecrypte.EncryptString(password);
            //IPredicateGroup predGrp = null;
            //var pred1 = Predicates.Field<SysPerson>(p => p.Name, Operator.Eq, userName);
            //var pred2 = Predicates.Field<SysPerson>(p => p.Password, Operator.Eq, passwordDes);
            //predGrp = Predicates.Group(GroupOperator.And, pred1, pred2);
            //var person = Db.GetList<SysPerson>(predGrp).SingleOrDefault();

            using (SysEntities db = new SysEntities())
            {
                var person = db.SysPerson.Where(p => p.Name == userName && p.Password == password).FirstOrDefault();
                if (person != null)
                {
                    Account account = new Account()
                    {
                        Name = person.MyName,
                        PersonName = person.Name,
                        Id = person.Id
                    };
                    Session["account"] = account;
                    return "1";
                }
                else
                    return "0";
            }
        }
Example #2
0
 public Archive DetailById(int id)
 {
     using (SysEntities db = new SysEntities())
     {
         var result = db.Archive.Where(a => a.Id == id).FirstOrDefault();
         return result;
     }
 }
Example #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (SysEntities db = new SysEntities())
        {
            foreach (var item in db.SysPerson)
                Response.Write(item.Name);

        }
    }
Example #4
0
 public object CountStat()
 {
     using (SysEntities db = new SysEntities())
     {
         int archiveCount = db.Archive.Count();
         long? visitCount = db.Archive.Sum(a => a.VisitTotal);
         var obj = new { archiveCount = archiveCount, visitCount = visitCount };
         return obj;
     }
 }
Example #5
0
 public object GetCountListByCategory()
 {
     using (SysEntities db = new SysEntities())
     {
         var list = db.Category.Select(t => new
            {
                Id = t.Id,
                Name = t.Name,
                Count = db.Archive.Count(a => a.CategoryId == t.Id)
            }).ToList();
         var obj = new { rows = list };
         return obj;
     }
 }
Example #6
0
        public object GetCountListByMonth()
        {
            using (SysEntities db = new SysEntities())
            {
                var list = db.Archive.GroupBy(a => new
                {
                    Year = a.PublishDate.Value.Year,
                    Month = a.PublishDate.Value.Month
                })
                .ToList()
                .Select(g => new
                {
                    YyyyMm = g.Key.Year.ToString() + g.Key.Month.ToString().PadLeft(2, '0'),
                    YM = g.Key.Year.ToString() + "年" + g.Key.Month.ToString() + "月",
                    Count = g.Count()
                })
                .OrderByDescending(g => g.YM.Substring(0, 4))
                .ThenByDescending(g => g.YM.Substring(5, g.YM.Length - 6));

                var obj = new { rows = list };
                return obj;
            }
        }
Example #7
0
 private object GetPageData(int page, int rows, Expression<Func<Archive, bool>> predicate)
 {
     using (SysEntities db = new SysEntities())
     {
         int totalCount = 0;
         var list = db.Archive.GetPager(predicate, "PublishDate desc,Id desc", page, rows, out totalCount)
                 .ToList()
                 .Select(c => new
                 {
                     Id = c.Id,
                     Subject = c.Subject,
                     PublishDate = c.PublishDate,
                     Content = FormatStr(c.Content, 200),
                     VisitTotal = c.VisitTotal
                 });
         var obj = new { total = totalCount, rows = list };
         return obj;
     }
 }
Example #8
0
 public void UpdateVisitTotal(int id)
 {
     using (SysEntities db = new SysEntities())
     {
         var m = db.Archive.Where(a => a.Id == id).FirstOrDefault();
         m.VisitTotal = m.VisitTotal + 1;
         //db.Archive.Attach(m);
         db.ObjectStateManager.ChangeObjectState(m, System.Data.EntityState.Modified);
         db.SaveChanges();
     }
 }