public async Task <IActionResult> Create([Bind("WarningNumber,StudentId,Date")] Warning warning) { string Id = HttpContext.Session.GetString("User"); string Aut = HttpContext.Session.GetString("Aut"); ViewBag.Aut = Aut; try { if (ModelState.IsValid) { _context.Add(warning); Message msg = new Message { From = "ועדת משמעת", Addressee = Id, MsgTime = DateTime.Now, Subject = "אזהרת משמעת", Content = "קיבלת מכתב אזהרה מועדת המשמעת בעקבות אורח שלא חתמת עליו ביומן המבקרים" + "במידה ואת/ה חושב/ת שהייתה טעות נא לפנות בהודעה לועדת המשמעת" + "במידה וזו אזהרה שלישית חל עלייך איסור לארח למשך שבוע החל מרגע זה." }; _context.Add(msg); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(warning)); }
public async Task <IActionResult> Create([Bind("Addressee,Subject,Content")] Message message) { string Id = HttpContext.Session.GetString("User"); string Aut = HttpContext.Session.GetString("Aut"); ViewBag.Aut = Aut; var u = await _context.Users.SingleOrDefaultAsync(m => m.StundetId.ToString().Equals(Id)); try { message.From = u.FullName; message.MsgTime = DateTime.Now; if (ModelState.IsValid) { _context.Add(message); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(message)); }
public async Task <IActionResult> Create([Bind("EnteryDate,VistorName,VisitorID,StudentFullName,ExitDate,ApartmentNum,Room,Signature")] VisitorsLog visitorsLog) { User u = await _context.Users.AsNoTracking().SingleOrDefaultAsync(m => m.ApartmentNum == visitorsLog.ApartmentNum && m.Room == visitorsLog.Room); ViewData["FullName"] = new SelectList(_context.ApprovalKits, "ID", "FullName"); ViewData["Apartments"] = new SelectList(_context.Apartments, "ApartmentNum", "ApartmentNum"); string Aut = HttpContext.Session.GetString("Aut"); ViewBag.Aut = Aut; try { visitorsLog.EnteryDate = DateTime.Now; visitorsLog.StudentId = u.StundetId; if (ModelState.IsValid) { _context.Add(visitorsLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(visitorsLog)); }
public async Task <IActionResult> Create([Bind("StundetId,LastName,FirstName,RoomType,LivingWithReligious,LivingWithSmoker,ReligiousType,HealthCondition,PartnerId1,PartnerId2,PartnerId3,PartnerId4")] ApprovalKit approvalKit) { var functions = new functions(); if (functions.Comper(new DateTime(2019, 9, 5))) { string Aut = HttpContext.Session.GetString("Aut"); ViewBag.Aut = Aut; string Id = HttpContext.Session.GetString("User"); var u = await _context.Registrations.SingleOrDefaultAsync(m => m.StundetId.ToString().Equals(Id)); approvalKit.FirstName = u.FirstName; approvalKit.LastName = u.LastName; approvalKit.StundetId = u.StundetId; approvalKit.Gender = u.gender; try { if (ModelState.IsValid) { //u.Authorization = 9; _context.Add(approvalKit); await _context.SaveChangesAsync(); return(RedirectToAction("Wellcome", "Home")); } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(approvalKit)); } return(RedirectToAction("NoMore", "Home")); }
public async Task <IActionResult> Create([Bind("Apartment,RoomNum,FullName,PhoneNumber,Description")] FaultForm faultForm) { string Id = HttpContext.Session.GetString("User"); string Aut = HttpContext.Session.GetString("Aut"); ViewBag.Aut = Aut; var u = await _context.Users.SingleOrDefaultAsync(m => m.StundetId.ToString().Equals(Id)); var r = await _context.Registrations.SingleOrDefaultAsync(m => m.StundetId.ToString().Equals(Id)); try { if (ModelState.IsValid) { faultForm.StundetId = u.StundetId; faultForm.RoomNum = u.Room; faultForm.Apartment = u.ApartmentNum; faultForm.FullName = u.FullName; faultForm.PhoneNumber = r.PhoneNumber; _context.Add(faultForm); await _context.SaveChangesAsync(); return(RedirectToAction("Wellcome", "Home")); } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(faultForm)); }
public async Task <IActionResult> Create([Bind("StundetId,FirstName,LastName,Password,Email,ApartmentNum,Room, Authorization")] User user) { ViewData["Authorization"] = new SelectList(_context.Authorizations, "Id", "AutName"); string Aut = HttpContext.Session.GetString("Aut"); if (Aut == null) { Aut = "0"; } try { if (user.Authorization == 0) { user.Authorization = 7; } if (ModelState.IsValid) { Boolean u = _context.Users.Any(e => e.StundetId == user.StundetId); if (u == false) { user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password); _context.Add(user); await _context.SaveChangesAsync(); if (Aut.Equals("1")) { ViewBag.Aut = Aut; return(RedirectToAction(nameof(Index))); } else { string s = user.StundetId.ToString(); HttpContext.Session.SetString("User", s); string a = user.Authorization.ToString(); HttpContext.Session.SetString("Aut", a); ViewBag.Aut = Aut; return(RedirectToAction("Wellcome", "Home")); } } else { TempData["msg"] = "<script>alert('משתמש קיים במערכת');</script>"; return(View(user)); } } } catch (DbUpdateException) { ModelState.AddModelError("", "לא היה ניתן לשמור את השינויים, נא נסה שנית במועד מאוחר יותר"); } return(View(user)); }
// after submintig the assainging form this function change the user field, //creating ner record of assinging and chacnge the apartment capacity. public async Task <IActionResult> ChangeA(Assigning assigning) { string Aut = HttpContext.Session.GetString("Aut"); if (!Aut.Equals("2")) { return(RedirectToAction("NotAut", "Home")); } var user = await _context.Users.SingleOrDefaultAsync(u => u.StundetId == assigning.StundetId.Value); var apartment = await _context.Apartments.SingleOrDefaultAsync(a => a.ApartmentNum == assigning.ApartmentNum.Value); if (ModelState.IsValid) { _context.Add(assigning); user.ApartmentNum = assigning.ApartmentNum.Value; if (assigning.Room == 0) { user.Room = RoomNum.OneA; } else if (assigning.Room == 1) { user.Room = RoomNum.TwoA; } else if (assigning.Room == 2) { user.Room = RoomNum.ThreeA; } else { user.Room = RoomNum.FourA; } _context.Update(user); apartment.capacity = apartment.capacity - 1; _context.Update(apartment); await _context.SaveChangesAsync(); } return(RedirectToAction("NotAssigning", "Apartments")); }
//capacity כמה מקום פנוי יש //The function goes through all the Approval kits and assigning the students to the apartments public async Task <IActionResult> Assigning() { //Couples ApprovalKit List <ApprovalKit> Couples = _context.ApprovalKits.Where( a => a.RoomType == RoomType.דירה_זוגית).ToList(); //Single ApprovalKit List <ApprovalKit> Single = _context.ApprovalKits.Where( r => r.RoomType == RoomType.חדר_ליחיד && r.HealthCondition == HealthCondition.ללא_מגבלה ).ToList(); //Accessible ApprovalKit List <ApprovalKit> Accessible = _context.ApprovalKits.Where( r => r.RoomType == RoomType.חדר_ליחיד && ( r.HealthCondition == HealthCondition.מגבלה_פיזית_אחרת || r.HealthCondition == HealthCondition.נכה_צהל || r.HealthCondition == HealthCondition.נכות) ).ToList(); //Couples foreach (ApprovalKit a in Couples) { var asaing = await _context.Assigning.SingleOrDefaultAsync(u => u.StundetId.Value == a.StundetId.Value); if (asaing == null) { //a main student || c main student parnter if (a.PartnerId1 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value); //find the partner of the main student if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value) { //get empty apartment var apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.Type.Equals("Couples") && m.capacity == 2); if (apartment != null) { apartment.capacity = 0; _context.Update(apartment); // the user obj of a var u1 = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == a.StundetId); //the user obj of c var u2 = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == c.StundetId); Assigning p1 = new Assigning { StundetId = a.StundetId.Value, ApartmentNum = apartment.ApartmentNum, Room = 1 }; u1.ApartmentNum = apartment.ApartmentNum; u1.Room = RoomNum.OneA; _context.Update(u1); Assigning p2 = new Assigning { StundetId = c.StundetId.Value, ApartmentNum = apartment.ApartmentNum, Room = 2 }; u2.ApartmentNum = apartment.ApartmentNum; u2.Room = RoomNum.TwoA; _context.Update(u2); _context.Add(p1); _context.Add(p2); await _context.SaveChangesAsync(); } } ; } ; //if there is no partner } } ; } ; //Accessible foreach (ApprovalKit a in Accessible) { var asaing = await _context.Assigning.SingleOrDefaultAsync(u => u.StundetId.Value == a.StundetId.Value); if (asaing == null) { ApprovalKit[] roomies = new ApprovalKit[3]; roomies[0] = a; int size = 1; if (a.PartnerId1 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value && m.Gender == a.Gender); if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value) { roomies[1] = c; size++; } ; } ; } ; if (a.PartnerId2 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId == a.PartnerId2.Value && m.Gender == a.Gender); if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value) { roomies[2] = c; size++; } ; } ; } ; //change proprties of apartment var apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.Type.Equals("Accessible") && m.capacity == 3); if (apartment != null) { int c = apartment.capacity.Value; apartment.LivingWithReligious = a.LivingWithReligious; apartment.LivingWithSmoker = a.LivingWithSmoker; apartment.Gender = a.Gender; apartment.capacity = apartment.capacity - size; _context.Update(apartment); await _context.SaveChangesAsync(); // save proprties of roomeis foreach (ApprovalKit u in roomies) { if (u != null) { var user = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == u.StundetId.Value); Assigning r = new Assigning { StundetId = u.StundetId.Value, ApartmentNum = apartment.ApartmentNum, Room = c, }; user.ApartmentNum = apartment.ApartmentNum; if (r.Room == 1) { user.Room = RoomNum.OneA; } else if (r.Room == 2) { user.Room = RoomNum.TwoA; } else if (r.Room == 3) { user.Room = RoomNum.ThreeA; } else { user.Room = RoomNum.FourA; } _context.Update(user); _context.Add(r); await _context.SaveChangesAsync(); c--; } ; } ; } } ; } ; //Single foreach (ApprovalKit a in Single) { var asaing = await _context.Assigning.FirstOrDefaultAsync(x => x.StundetId.Value == a.StundetId.Value); if (asaing == null) { ApprovalKit[] roomies = new ApprovalKit[4]; roomies[0] = a; int size = 1; if (a.PartnerId1 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value && m.Gender == a.Gender); if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value) { roomies[1] = c; size++; } ; } ; } ; if (a.PartnerId2 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId2.Value && m.Gender == a.Gender); if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value) { roomies[2] = c; size++; } } ; } ; if (a.PartnerId3 != null) { var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId == a.PartnerId3.Value && m.Gender == a.Gender); if (c != null) { if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value) { roomies[3] = c; size++; } } } ; Apartments apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.capacity >= size && m.Type.Equals("Single") && m.LivingWithReligious == a.LivingWithReligious && m.LivingWithSmoker == a.LivingWithSmoker && m.ReligiousType == a.ReligiousType && m.Gender == a.Gender); if (apartment == null) { apartment = _context.Apartments.FirstOrDefault(m => m.capacity >= size && m.Type.Equals("Single")); } ; if (apartment != null) { int c = apartment.capacity.Value; apartment.LivingWithReligious = a.LivingWithReligious; apartment.LivingWithSmoker = a.LivingWithSmoker; apartment.Gender = a.Gender; apartment.capacity = apartment.capacity - size; apartment.ReligiousType = a.ReligiousType; _context.Update(apartment); await _context.SaveChangesAsync(); foreach (ApprovalKit u in roomies) { if (u != null) { var user = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == u.StundetId); Assigning r = new Assigning { StundetId = u.StundetId.Value, ApartmentNum = apartment.ApartmentNum, Room = c, }; user.ApartmentNum = apartment.ApartmentNum; if (r.Room == 1) { user.Room = RoomNum.OneA; } else if (r.Room == 2) { user.Room = RoomNum.TwoA; } else if (r.Room == 3) { user.Room = RoomNum.ThreeA; } else { user.Room = RoomNum.FourA; } _context.Update(user); _context.Add(r); await _context.SaveChangesAsync(); c--; } ; //end if u!=null } ; //end foreach roomies }// apartment!=null } ; //assing==null } ; //foreach approval kit //await _context.SaveChangesAsync(); //ViewBag.NotAssigning = Globals.NotAssigning; return(RedirectToAction("NotAssigning", "Apartments")); }