public async Task <IActionResult> PutAnnouncementRequest([FromRoute] int id, [FromBody] AnnouncementRequest announcementRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != announcementRequest.AnnouncementId) { return(BadRequest()); } _context.Entry(announcementRequest).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnouncementRequestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostAnnouncementRequest([FromBody] AnnouncementRequest announcementRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AnnouncementRequest.Add(announcementRequest); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAnnouncementRequest", new { id = announcementRequest.AnnouncementId }, announcementRequest)); }
public async Task <AnnouncementRequest> CreateAnnouncement([Body] AnnouncementRequest announcement) { return(await _client.CreateAnnouncement(announcement, token)); }
/// <summary> /// This is called when the submit button is pressed. /// </summary> /// <param name="sender">The object that causes the event.</param> /// <param name="e">Event arguments.</param> private async void BtnSubmit_Clicked(object sender, EventArgs e) { // First, ensure that the user is logged in. if (!Application.Current.Properties.ContainsKey("Username")) { UserDialogs.Instance.Toast(new ToastConfig("Error! You are not logged in! Please log in and try again.") { BackgroundColor = App.toastColor }); } // Also, ensure that there is information in the title textbox. else if (txtTitle.Text == null || txtTitle.Text.Length < 1) { UserDialogs.Instance.Toast(new ToastConfig("Error! No title!") { BackgroundColor = App.toastColor }); } // Finally, ensure that there is information in the description of the announcement. else if (txtDescription.Text == null || txtDescription.Text.Length < 1) { UserDialogs.Instance.Toast(new ToastConfig("Error! No description!") { BackgroundColor = App.toastColor }); } else { try { // Let the user know that there is something happening. UserDialogs.Instance.Toast(new ToastConfig("Attempting to post announcement request...") { BackgroundColor = App.toastColor, Duration = TimeSpan.FromMilliseconds(App.timeoutTime) }); // Get the user so we can get the user ID. User user = await client.GetUser(Application.Current.Properties["Username"].ToString()); // Create the announcement model. AnnouncementRequest announcement = new AnnouncementRequest() { AnnouncementDate = DateTime.Now, UserId = user.UserId, Announcement = txtTitle.Text + " - " + txtDescription.Text, }; // Post the announcement to the database. await client.CreateAnnouncement(announcement); txtDescription.Text = ""; // Clear the txtTitle.Text = ""; // entry form. // Let the user know it has been submitted! UserDialogs.Instance.Toast(new ToastConfig("Succeeded in posting the announcement request!") { BackgroundColor = App.toastColor }); } catch (ValidationApiException) // The information is bad. { UserDialogs.Instance.Toast(new ToastConfig("Error! The server may be temporarily down. Please try again later.") { BackgroundColor = App.toastColor }); } catch (ApiException) // The user doesn't exist. { UserDialogs.Instance.Toast(new ToastConfig("Error! There was an error posting your announcement.") { BackgroundColor = App.toastColor }); } catch (System.Net.Http.HttpRequestException) // Connection was lost. { UserDialogs.Instance.Toast(new ToastConfig("Access denied! Connection blocked. Please try again later.") { BackgroundColor = App.toastColor }); } catch (System.Threading.Tasks.TaskCanceledException) // Request timed out. { UserDialogs.Instance.Toast(new ToastConfig("Error! Request timed out! Please try again later.") { BackgroundColor = App.toastColor }); } } }