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> 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); } }