private void Create_Click(object sender, EventArgs e) { var version = VersionTextBox.Text; var commitHash = CommitHashTextBox.Text; var description = DescriptionRichBox.Text; var createdDate = DateTime.Now; if (string.IsNullOrEmpty(commitHash) || string.IsNullOrEmpty(description)) { MessageBox.Show(@"Please enter value to create.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var classVersion = new ClassVersionEntity() { Version = version, CommitHash = commitHash, CreatedDate = createdDate }; var check = _classVersionService.Create(classVersion); if (check) { MessageBox.Show(@"Create success!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); Version.Instance.ReLoadData(); Close(); } else { MessageBox.Show(@"Create failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool Create(ClassVersionEntity classVersion) { var url = CommonService.GetUrlApi(); var client = new RestClient(url); var request = new RestRequest($"versions", Method.POST); request.AddHeader("Authorization", UserLoginModel.AccessToken); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Charset", "utf-8"); request.AddHeader("Connection", "close"); var json = JsonConvert.SerializeObject(classVersion); request.AddJsonBody(json); var response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.Created) { return(true); } return(false); }
public bool Update(ClassVersionEntity classVersion) { var url = CommonService.GetUrlApi(); var client = new RestClient(url); var request = new RestRequest($"versions/{classVersion.Id}", Method.PUT); request.AddHeader("Authorization", UserLoginModel.AccessToken); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Charset", "utf-8"); request.AddHeader("Connection", "close"); var body = JObject.FromObject(classVersion); request.AddJsonBody(body.ToString()); var response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.NoContent) { return(true); } return(false); }
private void Update_Click(object sender, EventArgs e) { var commitHash = CommitHashTextBox.Text; var classVersion = new ClassVersionEntity() { CommitHash = commitHash, Id = IdTextBox.Text, Description = DescriptionRichTextBox.Text }; var check = _classVersionService.Update(classVersion); if (check) { MessageBox.Show(@"Update success!"); Version.Instance.ReLoadData(); this.Close(); } else { MessageBox.Show(@"Update failed!"); } }