public async Task <IActionResult> PutPrenotazione(int id, DettaglioPrenotazione prenotazione) { string UserID = User.Claims.First(c => c.Type == "UserID").Value; Utente user = await _userManager.FindByIdAsync(UserID); var roles = await _userManager.GetRolesAsync(user); if (roles.FirstOrDefault() == "UtenteAutorizzato") { if (!user.AbilitatoAlleNotifiche) { return(BadRequest()); } } return(Ok()); }
public async Task <IActionResult> postCart([FromBody] JObject data) { var idStrumento = data["IdStrumento"].ToObject <string>(); var inizio = data["DataInizio"].ToObject <DateTime>().Date; var fine = data["DataFine"].ToObject <DateTime>().Date; var posizioneUtilizzo = data["PosizioneUtilizzo"].ToObject <string>(); if (await checkPrenotazioniStrumento(idStrumento, inizio, fine)) { var cart = SessionHelper.GetObjectFromJson <ICollection <DettaglioPrenotazione> >(HttpContext.Session, "cart"); if (cart == null) { cart = new List <DettaglioPrenotazione>(); } var s = _context.Strumento.Find(idStrumento); var dettaglio = new DettaglioPrenotazione(); dettaglio.IdStrumento = idStrumento; dettaglio.dataInizio = inizio; dettaglio.dataFine = fine; dettaglio.PosizioneUtilizzo = posizioneUtilizzo; if (s.Delicato) { dettaglio.Checked = false; } else { dettaglio.Checked = true; } if (cart.All(d => !(d.IdStrumento == dettaglio.IdStrumento))) { cart.Add(dettaglio); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); return(Ok()); } else { SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); return(BadRequest()); } } else { return(BadRequest()); } }