public ActionResult Index() { try { ViewBag.PageKey = "MyReservations"; var userId = Convert.ToInt32(Session["userId"]); if (userId == 0) { return(RedirectToAction("Login", "Account")); } using (var context = new UnicesumarBdEntities()) { var listLabsReserve = context.ListLaboratoryReserve .Include(p => p.Laboratory) .Include(p => p.Laboratory.Block) .Include(p => p.Class) .Where(p => p.UserId == userId) .Select(p => new LaboratoryReserveViewModel { Id = p.Id, LaboratoryName = p.Laboratory.Name, LaboratoryBlockName = p.Laboratory.Block.Title, ClassTitle = p.Class.Title, Date = p.Date, DateStart = p.DateStart, DateEnd = p.DateEnd, TypeReserveId = p.TypeReserveId, }) .OrderByDescending(p => p.Id) .ToList(); return(View(listLabsReserve)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> CancelReserve(LaboratoryReserveViewModel model) { try { using (var context = new UnicesumarBdEntities()) { var reserve = await context.ListLaboratoryReserve.FirstOrDefaultAsync(p => p.Id == model.Id); context.Entry(reserve).State = EntityState.Deleted; await context.SaveChangesAsync(); return(RedirectToAction("Index")); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> CancelReserveModal(int id) { try { using (var context = new UnicesumarBdEntities()) { var viewModel = new LaboratoryReserveViewModel { Id = id, }; var content = LayoutHelper.GetPartialViewData("_ModalCancel", ControllerContext, ViewData, TempData, viewModel).ToString(); return(Json(content)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> ViewReserve(int id) { try { using (var context = new UnicesumarBdEntities()) { var reserveLab = await context.ListLaboratoryReserve .Include(p => p.Laboratory) .Include(p => p.Laboratory.Block) .Include(p => p.Class) .Include(p => p.Horary) .Where(p => p.Id == id) .Select(p => new LaboratoryReserveViewModel { TypeReserveId = p.TypeReserveId, Date = p.Date, DateStart = p.DateStart, DateEnd = p.DateEnd, LaboratoryName = p.Laboratory.Name, LaboratoryBlockName = p.Laboratory.Block.Title, DisciplineTitle = p.Discipline.Title, ClassTitle = p.Class.Title, ShiftTitle = p.Shift.Title, HoraryTitle = p.Horary.Title, }) .FirstOrDefaultAsync(); reserveLab.TypeReserveDescription = LayoutHelper.GetEnumDescription(reserveLab.TypeReserveId); var content = LayoutHelper.GetPartialViewData("_ModalBody", ControllerContext, ViewData, TempData, reserveLab).ToString(); return(Json(content)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> ReserveLab(LaboratoryReserveViewModel model) { try { using (var context = new UnicesumarBdEntities()) { var userId = Convert.ToInt32(Session["userId"]); if (userId == 0) { return(RedirectToAction("Login", "Account")); } var labReserve = new LaboratoryReserve { LaboratoryId = model.LaboratoryId, UserId = userId, TypeReserveId = model.TypeReserveId, ClassId = model.ClassId, ShiftId = model.ShiftId, DisciplineId = model.DisciplineId, Date = model.TypeReserveId == ETypeReserve.Simple ? model.Date : null, DateStart = model.TypeReserveId == ETypeReserve.Recorrent ? model.DateStart : null, DateEnd = model.TypeReserveId == ETypeReserve.Recorrent ? model.DateEnd : null, HoraryId = model.HoraryId, }; context.Entry(labReserve).State = EntityState.Added; await context.SaveChangesAsync(); return(RedirectToAction("Index", "MyReservations")); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Login(LoginViewModel viewModel) { ViewBag.SideMenu = false; using (var context = new UnicesumarBdEntities()) { var user = context.ListUser.Where(p => p.UserName == viewModel.UserName && p.Password == viewModel.Password).FirstOrDefault(); if (user != null) { Session["userId"] = user.Id.ToString(); Session["userName"] = user.UserName.ToString(); return(RedirectToAction("Index", "Home")); } else { viewModel.ErrorMenssage = "Nome de usuário ou senha inválidos"; return(View(viewModel)); } } }
public ActionResult Filter(FilterViewModel viewModel) { try { using (var context = new UnicesumarBdEntities()) { var laboratory = new LaboratoryViewModel(); laboratory.ListLab = context.ListLaboratory .Include(p => p.HeadOffice) .Include(p => p.Block) .Include(p => p.LaboratoryCapacity) .Include(p => p.LaboratoryCategory) .Where(p => p.HeadOfficeId == viewModel.HeadOfficeId) .Select(p => new LabViewModel { Id = p.Id, Name = p.Name, HeadOfficeTitle = p.HeadOffice.Title, BlockTitle = p.Block.Title, LaboratoryCapacityTitle = p.LaboratoryCapacity.Title, LaboratoryCategoryTitle = p.LaboratoryCategory.Title, BlockId = p.BlockId, HeadOfficeId = p.HeadOfficeId, LaboratoryCategoryId = p.LaboratoryCategoryId, LaboratoryCapacityId = p.LaboratoryCapacityId, }).ToList(); if (viewModel.BlockId != 0) { laboratory.ListLab = laboratory.ListLab.Where(p => p.BlockId == viewModel.BlockId).ToList(); } if (viewModel.LaboratoryCapacityId != 0) { laboratory.ListLab = laboratory.ListLab.Where(p => p.LaboratoryCapacityId == viewModel.LaboratoryCapacityId).ToList(); } if (viewModel.LaboratoryCategoryId != 0) { laboratory.ListLab = laboratory.ListLab.Where(p => p.LaboratoryCategoryId == viewModel.LaboratoryCategoryId).ToList(); } laboratory.ListHeadOffice = context.ListHeadOffice .Select(p => new HeadOfficeViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListBlock = context.ListBlock .Select(p => new BlockViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListLaboratoryCategory = context.ListLaboratoryCategory .Select(p => new LaboratoryCategoryViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListLaboratoryCapacity = context.ListLaboratoryCapacity .Select(p => new LaboratoryCapacityViewModel { Id = p.Id, Title = p.Title, }) .ToList(); var content = LayoutHelper.GetPartialViewData("_ListLabs", ControllerContext, ViewData, TempData, laboratory.ListLab).ToString(); return(Json(content)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Index(LaboratoryViewModel viewModel) { try { ViewBag.PageKey = "ViewLabs"; var userId = Convert.ToInt32(Session["userId"]); if (userId == 0) { return(RedirectToAction("Login", "Account")); } using (var context = new UnicesumarBdEntities()) { var laboratory = new LaboratoryViewModel(); laboratory.ListLab = context.ListLaboratory .Include(p => p.HeadOffice) .Include(p => p.Block) .Include(p => p.LaboratoryCapacity) .Include(p => p.LaboratoryCategory) .Where(p => p.HeadOfficeId == _headOfficeDefault) .Select(p => new LabViewModel { Id = p.Id, Name = p.Name, HeadOfficeTitle = p.HeadOffice.Title, BlockTitle = p.Block.Title, LaboratoryCapacityTitle = p.LaboratoryCapacity.Title, LaboratoryCategoryTitle = p.LaboratoryCategory.Title, }).ToList(); laboratory.ListHeadOffice = context.ListHeadOffice .Select(p => new HeadOfficeViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListBlock = context.ListBlock .Select(p => new BlockViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListLaboratoryCategory = context.ListLaboratoryCategory .Select(p => new LaboratoryCategoryViewModel { Id = p.Id, Title = p.Title, }) .ToList(); laboratory.ListLaboratoryCapacity = context.ListLaboratoryCapacity .Select(p => new LaboratoryCapacityViewModel { Id = p.Id, Title = p.Title, }) .ToList(); return(View(laboratory)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> ManageScheduleLab(int id) { try { using (var context = new UnicesumarBdEntities()) { var viewModel = new LaboratoryReserveViewModel(); viewModel.LaboratoryId = id; var laboratory = context.ListLaboratory.FirstOrDefault(p => p.Id == id); viewModel.LaboratoryName = laboratory.Name; viewModel.ListTypeReserve = new SelectList(GetListExamsStatusTypes(), "Value", "Description"); var listClass = await context.ListClass .Select(p => new GetDropDownListViewModel { Id = p.Id, Title = p.Title }) .ToListAsync(); viewModel.ListClass = new SelectList(listClass, "Id", "Title"); var listShift = await context.ListShift .Select(p => new GetDropDownListViewModel { Id = p.Id, Title = p.Title }) .ToListAsync(); viewModel.ListShift = new SelectList(listShift, "Id", "Title"); if (laboratory.LaboratoryCategoryId == 1) { var listDiscipline = await context.ListDiscipline .Where(p => p.Id <= 6) .Select(p => new GetDropDownListViewModel { Id = p.Id, Title = p.Title }) .ToListAsync(); viewModel.ListDiscipline = new SelectList(listDiscipline, "Id", "Title"); } else { var listDiscipline = await context.ListDiscipline .Where(p => p.Id >= 7) .Select(p => new GetDropDownListViewModel { Id = p.Id, Title = p.Title }) .ToListAsync(); viewModel.ListDiscipline = new SelectList(listDiscipline, "Id", "Title"); } var listHorary = await context.ListHorary. Select(p => new GetDropDownListViewModel { Id = p.Id, Title = p.Title }) .ToListAsync(); viewModel.ListHorary = new SelectList(listHorary, "Id", "Title"); var content = LayoutHelper.GetPartialViewData("_ModalBody", ControllerContext, ViewData, TempData, viewModel).ToString(); return(Json(content)); } } catch (Exception ex) { throw new Exception(ex.Message); } }