private async void button_delete_Click(object sender, EventArgs e) { if (workedTimes.Count < 1) { return; } DialogResult result = MessageBox.Show("Вы действительно хотите удалить запись?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { int row = dataGridView_workedTimes.CurrentRow.Index; int id = (int)dataGridView_workedTimes[0, row].Value; try { WorkedTime workedTime = await RestApi.WorkedTimeService.Delete(id); DeleteWorkedTime(workedTime); Filter(); } catch (Exception exception) { HandleError(exception); } } }
private void DeleteWorkedTime(WorkedTime workedTime) { workedTime = workedTimes .Where(d => d.WorkedTimeId == workedTime.WorkedTimeId) .FirstOrDefault(); if (workedTime != null) { workedTimes.Remove(workedTime); } }
public async Task <IActionResult> PostWorkedTime(string session, [FromBody] WorkedTime workedTime) { if (!SessionLogic.Instance.Valid(session)) { Response.StatusCode = 403; return(Json(ErrorType.AuthanticationFaild)); } _context.WorkedTimes.Add(workedTime); await _context.SaveChangesAsync(); return(await GetWorkedTime(session, workedTime.WorkedTimeId)); }
private async void setWorkedTime(int workedTimeId) { try { workedTime = await RestApi.WorkedTimeService.Get(workedTimeId); textBox_id.Text = workedTime.WorkedTimeId.ToString(); comboBox_employeeId.Text = workedTime.EmployeeId.ToString(); dateTimePicker_date.Text = workedTime.Date.ToString(); dateTimePicker_arrivalTime.Text = workedTime.ArrivalTime.ToString(); dateTimePicker_leavingTime.Text = workedTime.LeavingTime.ToString(); } catch (Exception exception) { HandleError(exception); } }
private void UpdateWorkedTime(WorkedTime newWorkedTime) { WorkedTime oldWorkedTime = workedTimes .Where(d => d.WorkedTimeId == newWorkedTime.WorkedTimeId) .FirstOrDefault(); if (oldWorkedTime == null) { return; } oldWorkedTime.EmployeeId = newWorkedTime.EmployeeId; oldWorkedTime.Deleted = newWorkedTime.Deleted; oldWorkedTime.Date = newWorkedTime.Date; oldWorkedTime.ArrivalTime = newWorkedTime.ArrivalTime; oldWorkedTime.LeavingTime = newWorkedTime.LeavingTime; oldWorkedTime.Employee = newWorkedTime.Employee; }
private async void button_save_Click(object sender, EventArgs e) { if (!Validate()) { return; } try { Employee employee = employees[Int32.Parse(comboBox_employeeId.Text)]; WorkedTime workedTime = new WorkedTime(); workedTime.EmployeeId = employee.EmployeeId; workedTime.Date = dateTimePicker_date.Value.Date; workedTime.ArrivalTime = dateTimePicker_arrivalTime.Value.TimeOfDay; workedTime.LeavingTime = dateTimePicker_leavingTime.Value.TimeOfDay; int id = (textBox_id.Text != "") ? Int32.Parse(textBox_id.Text) : -1; if (id == -1) { workedTime = await RestApi.WorkedTimeService.Add(workedTime); } else { workedTime.WorkedTimeId = id; await RestApi.WorkedTimeService.Update(id, workedTime); workedTime.Employee = employee; } MessageBox.Show("Запись успешно сохранена!"); OnValueChanged(workedTime); Close(); } catch (Exception exception) { HandleError(exception); } }
public async Task <IActionResult> PutWorkedTime(string session, [FromRoute] int id, [FromBody] WorkedTime workedTime) { if (!SessionLogic.Instance.Valid(session)) { Response.StatusCode = 403; return(Json(ErrorType.AuthanticationFaild)); } if (id != workedTime.WorkedTimeId) { Response.StatusCode = 405; return(Json(ErrorType.NotFoundObject)); } _context.Entry(workedTime).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(NoContent()); } catch (Exception) { Response.StatusCode = 500; return(Json(ErrorType.InternalError)); } }