public JsonResult GetRooms() { Entities db = new Entities(); var model = new List<object>() { }; foreach (Auditorium auditorium in db.Auditorium) { Dictionary<string, bool> equipment = new Dictionary<string, bool>(); foreach (AdditionalEquipment addEq in db.AdditionalEquipment) { equipment.Add(addEq.AdditionalEquipmentName, false); } foreach (AdditionalEquipment ae in auditorium.AdditionalEquipment) { if (equipment.ContainsKey(ae.AdditionalEquipmentName)) { equipment[ae.AdditionalEquipmentName] = true; } } model.Add(new { number = auditorium.AuditoriumName, places = auditorium.Capacity, wifi = equipment["Wifi"], projector = equipment[ "Проектор"], monitor = equipment["Монитор"], microphone = equipment["Микрофон"] }); } return Json(model, JsonRequestBehavior.AllowGet); }
public ActionResult Add(LoginModel userInfo) { if (ModelState.IsValid) { using (Entities db = new Entities()) { IQueryable<User> users = db.User .Where(user => user.Email.Equals(userInfo.Email)); if (users.AsEnumerable().Count() == 0) { ModelState.AddModelError("", "Данные введены не верно"); ViewBag.Close = false; return PartialView("Create", userInfo); } else { foreach (User curuser in users) { Security crypto = new Security(); bool isVerify = crypto.VerifyMd5Hash(MD5.Create(), userInfo.Password, curuser.Password); if (isVerify) { Session["IsAuthenticated"] = "true"; Session["UserSurname"] = curuser.Surname; Session["UserFirstName"] = curuser.FirstName; string rol = curuser.Role1.RoleName; Session["UserRole"] = rol; Session["UserEmail"] = curuser.Email; } else { ModelState.AddModelError("", "Данные введены не верно"); ViewBag.Close = false; return PartialView("Create", userInfo); } } ViewBag.Close = true; return PartialView("Create", userInfo); } } } return PartialView("Create", userInfo); }
public ActionResult Add(RegistrationModel userInfo) { Entities db = new Entities(); IQueryable<User> existUser = db.User.Where(user => user.Email.Equals(userInfo.Email)); if (ModelState.IsValid && existUser.Count() == 0) { User user = new User(); user.FirstName = userInfo.FirstName; user.Surname = userInfo.Surname; user.Email = userInfo.Email; using (MD5 md5Hash = MD5.Create()) { Security crypto = new Security(); user.Password = crypto.GetMd5Hash(md5Hash, userInfo.Password); } user.Role1 = db.Role.Where(role => role.RoleName.Equals("Client")).First(); db.User.Add(user); db.SaveChanges(); Session["IsAuthenticated"] = "true"; Session["UserSurname"] = user.Surname; Session["UserFirstName"] = user.FirstName; string rol = user.Role1.RoleName; Session["UserRole"] = rol; Session["UserEmail"] = user.Email; ViewBag.Close = true; return PartialView("Create", userInfo); } ViewBag.Close = false; return PartialView("Create", userInfo); }
public void AddNewRoom(NewRoomModel room) { Entities db = new Entities(); if (ModelState.IsValid && room.Capacity != 0) { Auditorium auditorium = new Auditorium(); auditorium.AuditoriumName = room.Name; auditorium.Capacity = room.Capacity; db.Auditorium.Add(auditorium); db.SaveChanges(); int auditoriumId = db.Auditorium.Where(aud => aud.AuditoriumName.Equals(room.Name)).First().AuditoriumId; if (room.Wifi) { int wifi = db.AdditionalEquipment.Where(addeq => addeq.AdditionalEquipmentName.Equals("Wifi")).First().AdditionalEquipmentId; db.InsertAudEq(auditoriumId, wifi); } if (room.Monitor) { int monitor = db.AdditionalEquipment.Where(addeq => addeq.AdditionalEquipmentName.Equals("Монитор")).First().AdditionalEquipmentId; db.InsertAudEq(auditoriumId, monitor); } if (room.Projector) { int projector = db.AdditionalEquipment.Where(addeq => addeq.AdditionalEquipmentName.Equals("Проектор")).First().AdditionalEquipmentId; db.InsertAudEq(auditoriumId, projector); } if (room.Microphone) { int microphone = db.AdditionalEquipment.Where(addeq => addeq.AdditionalEquipmentName.Equals("Микрофон")).First().AdditionalEquipmentId; db.InsertAudEq(auditoriumId, microphone); } db.SaveChanges(); } }
public void Initialization(Entities context) { var roles = new List<Role> { new Role { RoleId =1, RoleName= "admin"}, new Role { RoleId =2, RoleName= "Client"} }; roles.ForEach(r => context.Role.Add(r)); context.SaveChanges(); var users = new List<User> { new User { Role = 1, Email = "*****@*****.**", Surname = "Левицкий", FirstName = "Иван", Password = "******" }, new User { Role = 2, Email = "*****@*****.**", Surname = "Рахуба", FirstName = "Олександр", Password = "******" } }; users.ForEach(u => context.User.Add(u)); context.SaveChanges(); var additionalEquipments = new List<AdditionalEquipment> { new AdditionalEquipment {AdditionalEquipmentName = "Wifi"}, new AdditionalEquipment {AdditionalEquipmentName = "Projector"}, new AdditionalEquipment {AdditionalEquipmentName = "Monitor"}, new AdditionalEquipment {AdditionalEquipmentName = "Microphone"} }; additionalEquipments.ForEach(adde => context.AdditionalEquipment.Add(adde)); context.SaveChanges(); var auditoriums = new List<Auditorium> { new Auditorium {AuditoriumName = "301", Capacity = 35}, new Auditorium {AuditoriumName = "302", Capacity = 25 }, new Auditorium {AuditoriumName = "303", Capacity = 45 }, new Auditorium {AuditoriumName = "304", Capacity = 55 }, new Auditorium {AuditoriumName = "305", Capacity = 65 }, new Auditorium {AuditoriumName = "306", Capacity = 15 }, new Auditorium {AuditoriumName = "307", Capacity = 85 }, new Auditorium {AuditoriumName = "308", Capacity = 30 }, new Auditorium {AuditoriumName = "309", Capacity = 40 }, new Auditorium {AuditoriumName = "310", Capacity = 53 }, new Auditorium {AuditoriumName = "311", Capacity = 25 }, new Auditorium {AuditoriumName = "312", Capacity = 100 }, new Auditorium {AuditoriumName = "313", Capacity = 32 }, new Auditorium {AuditoriumName = "314", Capacity = 65 }, new Auditorium {AuditoriumName = "315", Capacity = 19 } }; auditoriums.ForEach(a => context.Auditorium.Add(a)); context.SaveChanges(); var reservation = new List<Reservation> { new Reservation {TargetAuditorium = context.Auditorium.Where(a => a.AuditoriumName.Equals("301")).First().AuditoriumId, CreatedBy = context.User.Where(u => u.Email.Equals("*****@*****.**")).First().UserId, Purpose = "Бизнес-митинг", Type = true, StartDate = new DateTime(2015, 09 ,09 ,09, 0, 0), FinishDate = new DateTime(2015, 09, 09, 10, 0, 0) }, new Reservation {TargetAuditorium = context.Auditorium.Where(a => a.AuditoriumName.Equals("303")).First().AuditoriumId, CreatedBy = context.User.Where(u => u.Email.Equals("*****@*****.**")).First().UserId, Purpose = "Семинар", Type = true, StartDate = new DateTime(2015, 09 ,09 ,11, 0, 0), FinishDate = new DateTime(2015, 09, 09, 12, 0, 0) }, new Reservation {TargetAuditorium = context.Auditorium.Where(a => a.AuditoriumName.Equals("306")).First().AuditoriumId, CreatedBy = context.User.Where(u => u.Email.Equals("*****@*****.**")).First().UserId, Purpose = "Лекция", Type = true, StartDate = new DateTime(2015, 09 ,09 ,14, 0, 0), FinishDate = new DateTime(2015, 09, 09, 15, 0, 0) } }; reservation.ForEach(r => context.Reservation.Add(r)); context.SaveChanges(); }
public ActionResult SavePassword(Password newpass) { Entities db = new Entities(); UserReservation userReservation = new UserReservation(); foreach (User user in db.User) { if (Session["UserEmail"].ToString() == user.Email) { if (newpass.password != null && newpass.confirm!=null) { user.Password = newpass.password; userReservation = new UserReservation(user); } } } db.SaveChanges(); return PartialView("ChangePlace",userReservation); }
public ActionResult Save(User modifyUser) { Entities db = new Entities(); UserReservation userReservation = new UserReservation(); foreach (User user in db.User) { if (Session["UserEmail"].ToString() == user.Email) { if (modifyUser.FirstName != null) { user.FirstName = modifyUser.FirstName; Session["UserFirstName"] = modifyUser.FirstName; } if (modifyUser.Surname != null) { user.Surname = modifyUser.Surname; Session["UserSurname"] = modifyUser.Surname; } if (modifyUser.Email != null) { user.Email = modifyUser.Email; Session["UserEmail"] = modifyUser.Email; } userReservation = new UserReservation(user); } } db.SaveChanges(); return PartialView("ChangePlace", userReservation); }
public List<List<TD>> GetDateReservation(DateTime date) { List<List<TD>> table = new List<List<TD>>(); db = new Entities(); for (int i = 9; i <= 21; i++) { List<TD> row = new List<TD>(); TD first = new TD(); first.ReservationId = -2; first.Purpose = i.ToString(); row.Add(first); int roomNumber = 0; foreach (Auditorium auditory in db.Auditorium) { Reservation reserv = GetAuditoriumReservation(auditory.AuditoriumId, new DateTime(date.Year, date.Month, date.Day, i, 0, 0)); TD td = new TD(); if (reserv == null) { td.ReservationId = -1; td.StartDate = new DateTime(date.Year, date.Month, date.Day, i, 0, 0); td.TargetAuditorium = auditory.AuditoriumId; } else { td = ConvertToTD(reserv); } td.Hour = i; td.Placement = "right"; if (roomNumber >= 8) { td.Placement = "left"; } if (i == 9) { td.Placement = "bottom"; } else if (i == 20 || i == 21) { td.Placement = "top"; } roomNumber++; row.Add(td); } table.Add(row); } return table; }
private Reservation GetAuditoriumReservation(int AuditoriumId, DateTime date) { Reservation reservation = null; db = new Entities(); foreach (Reservation reserv in db.Reservation) { if (reserv.TargetAuditorium == AuditoriumId && ( reserv.StartDate <= date && reserv.FinishDate > date)) { reservation = reserv; return reservation; } } return reservation; }
public ReservationManager(DateTime date) { db = new Entities(); Table = GetDateReservation(date); }