public static void SetContent(object source, Timers.ElapsedEventArgs e) { List <string> emails = new List <string>(); DateTime tomorrow = DateTime.Today.AddDays(1); if (DateTime.Now.ToString("HH:mm:ss") == "20:00:00") { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { foreach (var r in from s in db.Reservations where s.Date == tomorrow && !s.Disable select s) { var user = (from u in db.AspNetUsers where u.Id == r.AspNetUserId select u).First(); emails.Add(user.Email); foreach (var email in r.BorrowerList.Split(';')) { emails.Add(email); } } } } emails = emails.Distinct().ToList(); foreach (var email in emails) { string subject = "會議系統提醒"; string body = string.Format("{0:yyyy-MM-dd} 有預約會議室,但不用到喔", tomorrow); System.Controllers.HomeController.SendEmail(email, "", subject, body); } }
public ActionResult Record(int?roomId, string Date, string SearchEmail) { string ASPNetUserID = User.Identity.GetUserId(); ViewBag.Date = Date; ViewBag.SearchEmail = SearchEmail; using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); List <System.Models.Reservations> reservations; ViewBag.Authority = user.Authority; if (user.Authority > 0) { reservations = (from s in db.Reservations where !s.Disable select s).ToList(); if (SearchEmail != null) { reservations = reservations.Where(x => x.BorrowerList.Split(';').Where(y => y.Contains(SearchEmail)).Any() || db.AspNetUsers.Where(w => w.Id == x.AspNetUserId).First().Email.Contains(SearchEmail)).ToList(); } } else { reservations = (from s in db.Reservations where s.AspNetUserId == ASPNetUserID && !s.Disable select s).ToList(); } if (Date != null && Date != "") { DateTime date = DateTime.ParseExact(Date, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); reservations = reservations.Where(x => x.Date == date).ToList(); } if (roomId != null) { reservations = reservations.Where(x => x.RoomId == roomId).ToList(); } return(View(reservations.Select(x => new RoomSystem.Models.ReservationModel(x)).ToList())); } }
public ActionResult Cancel(int id) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { System.Models.Reservations reservation = (from s in db.Reservations where s.Id == id select s).First(); reservation.Disable = true; db.SaveChanges(); } return(RedirectToAction("Record", "Home")); }
public ActionResult RoomCreate() { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } } return(View(new RoomSystem.Models.RoomModle())); }
public ActionResult UsersEdit(string id) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } System.Models.AspNetUsers editUser = (from s in db.AspNetUsers where s.Id == id select s).First(); return(View(new RoomSystem.Models.AspNetUserModel(editUser))); } }
public ActionResult RoomList() { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(PartialView()); } List <System.Models.Rooms> rooms = (from s in db.Rooms where s.Enable select s).ToList(); return(PartialView(rooms.Select(x => new RoomSystem.Models.RoomModle(x)).ToList())); } }
public ActionResult RoomSetting() { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } System.Models.ReservationCenters center = (from s in db.ReservationCenters select s).First(); return(View(new RoomSystem.Models.ReservationCenterModel(center))); } }
public ActionResult UsersSetting() { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } ViewBag.Authority = user.Authority; List <System.Models.AspNetUsers> users = (from s in db.AspNetUsers select s).ToList(); return(View(users.Select(x => new RoomSystem.Models.AspNetUserModel(x)).ToList())); } }
public ActionResult RoomDelete(int id) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } System.Models.Rooms room = (from s in db.Rooms where s.Id == id select s).First(); room.Enable = false; db.SaveChanges(); } return(RedirectToAction("RoomSetting", "Home")); }
public ActionResult RoomEdit(int id) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } System.Models.Rooms room = (from s in db.Rooms where s.Id == id select s).First(); if (room != null) { return(View(new RoomSystem.Models.RoomModle(room))); } } return(RedirectToAction("RoomSetting", "Home")); }
public ActionResult AuthorityLayout() { string ASPNetUserID = User.Identity.GetUserId(); ViewBag.Authority = 2; if (ASPNetUserID == null) { ViewBag.Authority = -1; } else { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).FirstOrDefault(); ViewBag.Authority = user.Id == ASPNetUserID ? user.Authority : -1; } } return(PartialView()); }
public ActionResult UsersEdit(int Authority, string Id) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } if (!(Authority >= 0 && Authority < user.Authority)) { return(UsersEdit(Id)); } System.Models.AspNetUsers saveUser = (from s in db.AspNetUsers where s.Id == Id select s).First(); saveUser.Authority = Authority; db.SaveChanges(); return(RedirectToAction("UsersSetting", "Home")); } }
public ActionResult RoomEdit(RoomSystem.Models.RoomModle r) { if (!(r.MinNumberOfUsers > 0 && r.MaxNumberOfUsers > r.MinNumberOfUsers)) { return(View(r)); } using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } System.Models.Rooms room = (from s in db.Rooms where s.Id == r.Id select s).First(); room.MinNumberOfUsers = r.MinNumberOfUsers; room.MaxNumberOfUsers = r.MaxNumberOfUsers; db.SaveChanges(); } return(RedirectToAction("RoomSetting", "Home")); }
//public RoomSystem.Models.AspNetUsers AspNetUsers { get; set; } //public RoomSystem.Models.Rooms Rooms { get; set; } public ReservationModel(System.Models.Reservations r) { Id = r.Id; BorrowerList = r.BorrowerList; Disable = r.Disable; AspNetUserId = r.AspNetUserId; RoomId = r.RoomId; SessionNo = r.SessionNo; Date = r.Date; //AspNetUsers = new RoomSystem.Models.AspNetUsers(r.AspNetUsers); //Rooms = new RoomSystem.Models.Rooms(r.Rooms); using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { System.Models.ReservationCenters center = (from s in db.ReservationCenters select s).First(); // Models.Rooms room = rooms.Where(x => x.Id == roomId).First(); if (center != null) { bool isWeekend = Date.DayOfWeek == DayOfWeek.Sunday || Date.DayOfWeek == DayOfWeek.Saturday; TimeSpan openTime = isWeekend ? center.WeekendOpenTime : center.WeekdaysOpenTime; TimeSpan closeTime = isWeekend ? center.WeekendCloseTime : center.WeekdaysCloseTime; TimeSpan startTime = openTime; TimeSpan interval = new TimeSpan(0, center.TimePerTimePeriod, 0); int i = SessionNo; while (i > 0) { startTime = startTime.Add(interval); i--; } TimeSpan endTime = startTime.Add(interval); endTime = endTime <= closeTime ? endTime : closeTime; StartTime = string.Format("{0:hh\\:mm}", startTime); EndTime = string.Format("{0:hh\\:mm}", endTime); Email = r.AspNetUsers.Email; } } }
public ActionResult RoomSetting(RoomSystem.Models.ReservationCenterModel reserveCenterModel) { using (System.Models.RoomSystemEntities db = new System.Models.RoomSystemEntities()) { string ASPNetUserID = User.Identity.GetUserId(); System.Models.AspNetUsers user = (from s in db.AspNetUsers where s.Id == ASPNetUserID select s).First(); if (user.Authority == 0) { return(View()); } bool hasReservation = (from s in db.Reservations where s.Date >= DateTime.Today && !s.Disable select s).Any(); System.Models.ReservationCenters center = (from s in db.ReservationCenters select s).First(); if (!hasReservation) { center.WeekdaysOpenTime = reserveCenterModel.WeekdaysOpenTime; center.WeekdaysCloseTime = reserveCenterModel.WeekdaysCloseTime; center.WeekendOpenTime = reserveCenterModel.WeekendOpenTime; center.WeekendCloseTime = reserveCenterModel.WeekendCloseTime; center.TimePerTimePeriod = reserveCenterModel.TimePerTimePeriod; db.SaveChanges(); } return(View(new RoomSystem.Models.ReservationCenterModel(center))); } }