public JsonResult Nuevo(NuevaReservaFormModel model) { if (ModelState.IsValid) { try { // var user = UserManager.FindById(User.Identity.GetUserId()); ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); string estadoPago = model.EstadoPago; if (User.IsInRole("Vendedor")) { estadoPago = "Pendiente"; } int ultimoFolio = 1; try { ultimoFolio = db.Reserva.Max(x => x.Folio) + 1; } catch { } Reserva obj = new Reserva() { Cerrada = false, Estado = "Sin confirmar", EstadoPago = estadoPago, EstadoPagoEmpleador = "Pendiente", FechaIngreso = DateTime.Now, FechaSalida = model.FechaSalida, Habitacion = model.Habitacion, Id = Guid.NewGuid(), IdCliente = model.IdCliente, IdServicio = model.IdServicio, IdUsuario = user.Id, Observaciones = model.Observaciones, PaxAdulto = model.PaxAdulto, PaxInfante = model.PaxInfante, PrecioAdulto = model.PrecioAdulto, PrecioInfante = model.PrecioInfante, Total = model.Total, Folio = ultimoFolio }; db.Reserva.Add(obj); db.SaveChanges(); } catch (Exception ex) { return(Json(new { Retorno = ex.Message + ". Stack trace: " + ex.StackTrace, Error = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { Retorno = "Exito", Error = false }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Retorno = "Contacte al administrador", Error = true }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Editar(NuevaReservaFormModel model) { if (ModelState.IsValid) { try { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); Reserva obj = db.Reserva.First(x => x.Id == model.Id); if (User.IsInRole("Administrador")) { obj.EstadoPago = model.EstadoPago; } obj.FechaIngreso = DateTime.Now; obj.FechaSalida = model.FechaSalida; obj.Habitacion = model.Habitacion; obj.IdCliente = model.IdCliente; obj.IdServicio = model.IdServicio; obj.IdUsuario = user.Id; obj.Observaciones = model.Observaciones; obj.PaxAdulto = model.PaxAdulto; obj.PaxInfante = model.PaxInfante; obj.PrecioAdulto = model.PrecioAdulto; obj.PrecioInfante = model.PrecioInfante; obj.Total = model.Total; obj.Id = model.Id; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { return(Json(new { Retorno = ex.Message + ". Stack trace: " + ex.StackTrace, Error = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { Retorno = "Exito", Error = false }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Retorno = "Contacte al administrador", Error = true }, JsonRequestBehavior.AllowGet)); } }