public bool AddOccupannts(OccupantViewModel model) { try { HostelOccupant occupant = new HostelOccupant { FirstName = model.Firstname, Surname = model.Surname, DateOfBirth = model.DateOfBirth, Gender = model.Gender, MaritalStatus = model.MaritalStatus, PhoneNumber = model.PhoneNumber, RoomId = model.RoomID }; _context.HostelOccupant.Add(occupant); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public OccupantViewModel GetOccupantsDetails(int id) { try { HostelOccupant occupant = _context.HostelOccupant .Where(x => x.OccupantId == id) .Include(x => x.Room) .FirstOrDefault(); OccupantViewModel viewModel = new OccupantViewModel { OccupantID = occupant.OccupantId, Firstname = occupant.FirstName, Surname = occupant.Surname, DateOfBirth = occupant.DateOfBirth, Gender = occupant.Gender, MaritalStatus = occupant.MaritalStatus, PhoneNumber = occupant.PhoneNumber, RoomID = occupant.RoomId, RoomNumber = occupant.Room.RoomNumber, IsAvailable = occupant.Room.IsAvailable, RoomList = new SelectList(_roomService.GetRooms(), "RoomID", "RoomNumber", occupant.RoomId) }; return(viewModel); } catch (Exception) { throw; } }
public OccupantViewModel Create() { OccupantViewModel model = new OccupantViewModel(); model.RoomList = new SelectList(_roomService.GetRooms(), "RoomID", "RoomNumber"); return(model); }
public ActionResult Edit(int id, OccupantViewModel model) { try { bool result = _occupantsService.UpdateOccupant(model); if (result) { return(RedirectToAction(nameof(Index))); } throw new Exception(); } catch { ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!"); return(View()); } }
public bool UpdateOccupant(OccupantViewModel model) { try { HostelOccupant occupant = new HostelOccupant(); occupant = _context.HostelOccupant.Where(x => x.OccupantId == model.OccupantID).FirstOrDefault(); occupant.FirstName = model.Firstname; occupant.Surname = model.Surname; occupant.DateOfBirth = model.DateOfBirth; occupant.Gender = model.Gender; occupant.MaritalStatus = model.MaritalStatus; occupant.PhoneNumber = model.PhoneNumber; occupant.RoomId = model.RoomID; _context.HostelOccupant.Update(occupant); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }