public HttpResponseMessage AddActualHours([FromBody] ActualHours value, [FromUri] int userId) { if (ModelState.IsValid) { return((LogicHours.AddActualHours(value, userId)) ? new HttpResponseMessage(HttpStatusCode.Created) : new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter()) }); } ; List <string> ErrorList = new List <string>(); //if the code reached this part - the ActualHours is not valid foreach (var item in ModelState.Values) { foreach (var err in item.Errors) { ErrorList.Add(err.ErrorMessage); } } return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter()) }); }
{ public static bool AddActualHours(ActualHours actualHours) { try { var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:56028/api/Hours/AddActualHours/" + Global.UserId); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = new JavaScriptSerializer().Serialize(actualHours); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); if (httpResponse.StatusCode == HttpStatusCode.Created) { return(true); } else { return(false); } } catch (Exception ex) { MessageBox.Show("error", ex.Message.ToString()); return(false); } }
public double GetTotalActualHour() { if (!ActualHours.IsEmpty()) { return(ActualHours.Sum(o => o.Value)); } return(0); }
private void addActulHoursToWorker() { //-----------------------------צריך לסכום את מספר השעות!!!!!!!!!!!!------------ ActualHours actualHours = new ActualHours() { CountHours = time, date = DateTime.Now, UserId = Global.UserId, ProjectId = projectId }; HoursRequst.AddActualHours(actualHours); }
internal QueryParameters ToApiParameters(bool toCreate) { var parameters = new QueryParameters(); parameters.Add("summary", Summary, toCreate); parameters.Add("issueTypeId", Type.Id, toCreate); parameters.Add("priorityId", Priority.Id, toCreate); parameters.Add("description", Description ?? ""); parameters.Add("dueDate", DueDate?.ToString("yyyy-MM-dd") ?? ""); parameters.Add("startDate", StartDate?.ToString("yyyy-MM-dd") ?? ""); parameters.AddRange("categoryId[]", Categories.Select(x => x.Id)); parameters.AddRange("versionId[]", Versions.Select(x => x.Id)); parameters.AddRange("milestoneId[]", Milestones.Select(x => x.Id)); parameters.AddRange("attachmentId[]", Attachments.Select(x => x.Id)); parameters.Add("parentIssueId", ParentTicketId?.ToString() ?? ""); parameters.Add("estimatedHours", EstimatedHours?.ToString() ?? ""); parameters.Add("actualHours", ActualHours?.ToString() ?? ""); parameters.Add("assigneeId", Assignee?.Id.ToString() ?? ""); if (!toCreate) { parameters.Add("statusId", Status?.Id.ToString() ?? ""); parameters.Add("resolutionId", Resolution?.Id.ToString() ?? ""); } if (CustomFields != null) { foreach (var field in CustomFields) { parameters.Add($"customField_{field.Id}", field.ToJsonValue()); if (field.OtherValue != null) { parameters.Add($"customField_{field.Id}_otherValue", field.OtherValue); } } } return(parameters); }
public static bool AddActualHours(ActualHours actualHours, int userId) { string query = $"INSERT INTO `tasks`.`actual_hours`(`user_id`, `project_id`, `count_houers`, `date`) VALUES ('{actualHours.UserId}','{actualHours.ProjectId}','{actualHours.CountHours}','{actualHours.date.Year}-{actualHours.date.Month}-{actualHours.date.Day}')"; return(DBaccess.RunNonQuery(query) == 1); }