public IHttpActionResult PutINSCRICAO(int id, INSCRICAO iNSCRICAO) { if (id != iNSCRICAO.COD_INSCRICAO) { return(BadRequest()); } db.Entry(iNSCRICAO).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!INSCRICAOExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Subscribe(INSCRICAO iNSCRICAO, int id = 0) { IEnumerable <EVENTO> eventsList; HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("events").Result; eventsList = response.Content.ReadAsAsync <IEnumerable <EVENTO> >().Result; var eventDetails = eventsList.Where(x => x.COD_EVENTO == id).FirstOrDefault(); var userAuth = (ClaimsIdentity)User.Identity; if (userAuth.IsAuthenticated) { var identity = userAuth.Claims.Where(c => c.Type == ClaimTypes.Sid).FirstOrDefault().Value; IEnumerable <INSCRICAO> subsList; HttpResponseMessage responseMessage = GlobalVariables.WebApiClient.GetAsync("subs").Result; if (responseMessage.IsSuccessStatusCode) { subsList = responseMessage.Content.ReadAsAsync <IEnumerable <INSCRICAO> >().Result; var subExists = subsList.Where(x => x.COD_USUARIO == Convert.ToInt32(identity) && x.COD_EVENTO == id) .Any(x => x.COD_EVENTO == id && x.COD_USUARIO == Convert.ToInt32(identity)); if (userAuth.Claims.Any(c => c.Type == ClaimTypes.Role && (c.Value == "3" || c.Value == "4" || c.Value == "5"))) { TempData["Error"] = "Seu nível de acesso não permite participar de eventos."; return(Redirect("/Events/Details/" + id)); } else if (subExists) { TempData["Error"] = "Você já está cadastrado nesse evento."; return(Redirect("/Events/Details/" + id)); } else { iNSCRICAO.COD_USUARIO = Convert.ToInt32(identity); iNSCRICAO.COD_EVENTO = id; eventDetails.VAGAS -= 1; response = GlobalVariables.WebApiClient.PutAsJsonAsync("events/" + id.ToString(), eventDetails).Result; responseMessage = GlobalVariables.WebApiClient.PostAsJsonAsync("subs", iNSCRICAO).Result; TempData["Success"] = "Inscrição realizada com sucesso!"; return(RedirectToAction("MyEvents")); } } else { TempData["Error"] = "Ocorreu um erro ao efetuar sua requisição."; return(Redirect("/Events/Details/" + id)); } } else { TempData["Error"] = "Inicie a sessão para continuar."; return(RedirectToAction("Login", "Users")); } }
public IHttpActionResult GetINSCRICAO(int id) { INSCRICAO iNSCRICAO = db.INSCRICAO.Find(id); if (iNSCRICAO == null) { return(NotFound()); } return(Ok(iNSCRICAO)); }
public IHttpActionResult DeleteINSCRICAO(int id) { INSCRICAO iNSCRICAO = db.INSCRICAO.Find(id); if (iNSCRICAO == null) { return(NotFound()); } db.INSCRICAO.Remove(iNSCRICAO); db.SaveChanges(); return(Ok(iNSCRICAO)); }
public IHttpActionResult PostINSCRICAO(INSCRICAO iNSCRICAO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } iNSCRICAO.FEEDBACK = new HashSet <FEEDBACK>(); iNSCRICAO.DATA_HORA_INSC = DateTime.Now; iNSCRICAO.DATA_HORA_PARTICIPACAO = null; iNSCRICAO.COD_VALIDADO = 0; db.INSCRICAO.Add(iNSCRICAO); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = iNSCRICAO.COD_INSCRICAO }, iNSCRICAO)); }