Exemplo n.º 1
0
        public ActionResult Create(Mail mail)
        {
            if (ModelState.IsValid)
            {
                db.Mails.Add(mail);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(mail);
        }
Exemplo n.º 2
0
        void Global_ExecuteTask(object sender, System.Timers.ElapsedEventArgs e)
        {
            TesheContext db = new TesheContext();
            string strweek = e.SignalTime.DayOfWeek.ToString();
            DateTime date = e.SignalTime.Date;

            int inthour = e.SignalTime.Hour;
            int intminute = e.SignalTime.Minute;
            //int intSecond = e.SignalTime.Second;
            //int isecond = 00;
            log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");
            List<Device> devicelist = db.Devices.ToList();
            List<UserInfo> userlist = db.UserInfoes.Where<UserInfo>(u => u.UserType.Name != "客户").ToList();

            foreach (var i in devicelist)
            {
                TimeSpan ts = i.CheckTime.AddDays(i.CheckCycle) - DateTime.Now;
                List<UserInfo> userDistrict = userlist.Where<UserInfo>(u => u.District == i.District && u.UserType.Name == "区(县)级管理员").ToList();
                List<UserInfo> userCity = userlist.Where<UserInfo>(u => u.City == i.City && u.UserType.Name == "市级管理员").ToList();
                List<UserInfo> userProvince = userlist.Where<UserInfo>(u => u.Province == i.Province && u.UserType.Name == "省级管理员").ToList();
                List<UserInfo> userSystem = userlist.Where<UserInfo>(u => u.UserType.Name == "系统管理员").ToList();
                if (ts.Days == 7 || ts.Days == 15)
                //if (true)
                {
                    foreach (var j in userDistrict)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userCity)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userProvince)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.City + i.District + i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                    foreach (var j in userSystem)
                    {
                        Mail mail = new Mail();
                        mail.Contents = i.Company + "的" + i.Name + "(" + i.Model + ")" + "设备需要在" + i.CheckTime.AddDays(i.CheckCycle) + "前检查";
                        mail.IsRead = 0;
                        mail.ReceivedUser = j;
                        db.Mails.Add(mail);
                        db.SaveChanges();
                    }
                }
            }
            //if (inthour == ihour && intminute == iminute)
            //{

            //}
        }
Exemplo n.º 3
0
 public ActionResult Edit(Mail mail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mail).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(mail);
 }