protected void buttonAddParticipant_Click(object sender, EventArgs e) { var projectId = ProjectId.Value; var projectDetailId = ProjectDetailId.Value; try { AddParticipantDTO newParticipant = new AddParticipantDTO() { ProjectId = Convert.ToInt64(ProjectId.Value), ProjectDetailId = Convert.ToInt64(ProjectDetailId.Value), UserTypeId = Convert.ToInt32(UserType.SelectedValue), UserId = Convert.ToInt32(UserFirstLastName.SelectedValue) }; ServiceResult <long> serviceResult = new ServiceResult <long>(); var queryString = new Dictionary <string, string>(); var response = ApiHelper.CallSendApiMethod(ApiKeys.ProjectApiUrl, "AddNewParticipant", queryString, newParticipant); if (!response.IsSuccessStatusCode) { throw new Exception("Hata oluştu!"); } var data = response.Content.ReadAsStringAsync().Result; serviceResult = JsonConvert.DeserializeObject <ServiceResult <long> >(data); if (serviceResult.ServiceResultType != EnumServiceResultType.Success) { throw new Exception(serviceResult.ErrorMessage); } labelErrorMessage.Text = "Katılımcı eklendi."; labelErrorMessage.Visible = true; GetParticipantList(Convert.ToInt64(projectId), Convert.ToInt64(projectDetailId)); } catch (Exception ex) { labelErrorMessage.Text = ex.Message; labelErrorMessage.Visible = true; } }
public IHttpActionResult AddNewParticipant(AddParticipantDTO model) { if (!Request.Headers.Contains("apiKey")) { return(Unauthorized()); } string apiKey = Request.Headers.GetValues("apiKey").First(); if (!ApiHelper.CheckKey(apiKey)) { return(Unauthorized()); } try { var serviceResult = _projectService.AddNewParticipant(model); return(Ok(serviceResult)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected void Register_Click(object sender, EventArgs e) { try { //Remove messages displayed in the page if any. ErrorMessage.Text = ""; SuccessMessage.Text = ""; //Fill the data transfer object parameters from form fields AddParticipantDTO objParticipant = new AddParticipantDTO(); objParticipant.Email = txtEmail.Text; objParticipant.FirstName = txtFirstName.Text; string[] dateFormats = { "dd/MM/yyyy HH:mm" }; DateTime arrivalDate = new DateTime(); if (!string.IsNullOrEmpty(txtArrivalDate.Text)) { DateTime dateValue; if (DateTime.TryParseExact(txtArrivalDate.Text, dateFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue)) { arrivalDate = dateValue; } else { ErrorMessage.Text = Constants.ArrivalDateError; } } objParticipant.ArrivalDate = arrivalDate; objParticipant.RegistrationDate = DateTime.Now; objParticipant.Country = ddlCountries.SelectedValue; objParticipant.EventId = int.Parse(ddlEvents.SelectedValue); string jsonData = new JavaScriptSerializer().Serialize(objParticipant); //Send a post requst to the restful webservice string response = ServiceManager.DoPostRequest("AddParticipant", jsonData); if (!string.IsNullOrEmpty(response)) { //Check if the response is an error response ErrorResponse errorResponse = new ErrorResponse(); errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(response); if (errorResponse != null && !string.IsNullOrEmpty(errorResponse.ErrorCode)) { if (errorResponse.ErrorCode == "ParticipantExists") { ErrorMessage.Text = errorResponse.ErrorDescription; } else { ErrorMessage.Text = Constants.DefaultError; } } else { //Response contains no error, display a success message. SuccessMessage.Text = Constants.SuccessfulRegistration; } } } catch (Exception ex) { ErrorMessage.Text = Constants.DefaultError; } }