public async Task <IActionResult> PostInscricaoDia(int id, [FromBody] InscricaoDia dia) { var user = GetUser(); if (id != dia.InscricaoId) { ModelState.AddModelError(nameof(InscricaoDia.InscricaoId), "InscricaoId diferente do especificado na URL"); } if (user.Inscricao.Id != id) { ModelState.AddModelError(nameof(InscricaoDia.InscricaoId), "Não é possível alterar a inscrição de outro usuário, espertinho."); } if (ModelState.IsValid) { var inscricao = user.Inscricao; if (!inscricao.Dias.Any(d => d.Dia == dia.Dia)) { inscricao.UltimaModificacao = DateTimeOffset.Now; inscricao.UltimaModificacao = DateTimeOffset.Now; _context.InscricaoDias.Add(dia); _context.SaveChanges(); await HubSend(SyncHub.InscricaoChanged, user.Inscricao); return(Created($"{inscricao.Id}/Dias/{dia.Id}", dia)); } return(Ok(dia)); } return(BadRequest(ModelState)); }
private async Task ExecutaChangingAsync() { using (var ws = new WebService()) { try { if (Habilitado) { var dia = new InscricaoDia { Dia = Dia, InscricaoId = App.Current.Usuario.Inscricao.Id }; InscricaoDia = await ws.PostDiaAsync(dia); App.Current.AddDia(InscricaoDia); } else { await ws.DeleteDiaAsync(InscricaoDia); App.Current.RemoveDia(InscricaoDia); InscricaoDia = null; } } catch (ServerException) { Habilitado = !Habilitado; } } }
public void RemoveDia(InscricaoDia dia) { db.DeleteDia(dia); Usuario.Inscricao.Dias.Remove(dia); }
public void AddDia(InscricaoDia dia) { db.InsertDia(dia); Usuario.Inscricao.Dias.RemoveAll(d => d.InscricaoId == dia.InscricaoId && d.Dia == dia.Dia); Usuario.Inscricao.Dias.Add(dia); }
public async Task DeleteDiaAsync(InscricaoDia dia) => await RequestAsync(client.DeleteAsync, $"Inscricoes/{dia.InscricaoId}/Dias/{dia.Id}");
public async Task <InscricaoDia> PostDiaAsync(InscricaoDia dia) => await RequestAsync <InscricaoDia>(client.PostAsync, $"Inscricoes/{dia.InscricaoId}/Dias", dia);