Esempio n. 1
0
        private async void button_delete_Click(object sender, EventArgs e)
        {
            if (firedEmployees.Count < 1)
            {
                return;
            }

            DialogResult result = MessageBox.Show("Вы действительно хотите удалить запись?", "", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                int row = dataGridView_firedEmployees.CurrentRow.Index;
                int id  = (int)dataGridView_firedEmployees[0, row].Value;

                try
                {
                    FiredEmployee firedEmployee = await RestApi.FiredEmployeeService.Delete(id);

                    DeleteFiredEmployee(firedEmployee);
                    Filter();
                }
                catch (Exception exception)
                {
                    HandleError(exception);
                }
            }
        }
Esempio n. 2
0
        private void DeleteFiredEmployee(FiredEmployee firedEmployee)
        {
            firedEmployee = firedEmployees
                            .Where(d => d.FiredEmployeeId == firedEmployee.FiredEmployeeId)
                            .FirstOrDefault();

            if (firedEmployee != null)
            {
                firedEmployees.Remove(firedEmployee);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> PostFiredEmployee(string session, [FromBody] FiredEmployee firedEmployee)
        {
            if (!SessionLogic.Instance.Valid(session))
            {
                Response.StatusCode = 403;
                return(Json(ErrorType.AuthanticationFaild));
            }

            _context.FiredEmployees.Add(firedEmployee);
            await _context.SaveChangesAsync();

            return(await GetFiredEmployee(session, firedEmployee.FiredEmployeeId));
        }
Esempio n. 4
0
        private async void setFiredEmployee(int firedEmployeeId)
        {
            try
            {
                firedEmployee = await RestApi.FiredEmployeeService.Get(firedEmployeeId);

                textBox_id.Text                     = firedEmployee.FiredEmployeeId.ToString();
                comboBox_employeeId.Text            = firedEmployee.EmployeeId.ToString();
                dateTimePicker_dateOfDismissal.Text = firedEmployee.DateOfDismissal.ToString();
                textBox_reason.Text                 = firedEmployee.Reason.ToString();
            }
            catch (Exception exception)
            {
                HandleError(exception);
            }
        }
Esempio n. 5
0
        private void UpdateFiredEmployee(FiredEmployee newFiredEmployee)
        {
            FiredEmployee oldFiredEmployee = firedEmployees
                                             .Where(d => d.FiredEmployeeId == newFiredEmployee.FiredEmployeeId)
                                             .FirstOrDefault();

            if (oldFiredEmployee == null)
            {
                return;
            }

            oldFiredEmployee.Deleted         = newFiredEmployee.Deleted;
            oldFiredEmployee.EmployeeId      = newFiredEmployee.EmployeeId;
            oldFiredEmployee.DateOfDismissal = newFiredEmployee.DateOfDismissal;
            oldFiredEmployee.Reason          = newFiredEmployee.Reason;
            oldFiredEmployee.Employee        = newFiredEmployee.Employee;
        }
Esempio n. 6
0
        private async void button_save_Click(object sender, EventArgs e)
        {
            if (!Validate())
            {
                return;
            }

            try
            {
                Employee employee = employees[Int32.Parse(comboBox_employeeId.Text)];

                FiredEmployee firedEmployee = new FiredEmployee();
                firedEmployee.EmployeeId      = employee.EmployeeId;
                firedEmployee.DateOfDismissal = dateTimePicker_dateOfDismissal.Value.Date;
                firedEmployee.Reason          = textBox_reason.Text;

                int id = (textBox_id.Text != "") ? Int32.Parse(textBox_id.Text) : -1;
                if (id == -1)
                {
                    firedEmployee = await RestApi.FiredEmployeeService.Add(firedEmployee);
                }
                else
                {
                    firedEmployee.FiredEmployeeId = id;
                    await RestApi.FiredEmployeeService.Update(id, firedEmployee);

                    firedEmployee.Employee = employee;
                }
                MessageBox.Show("Запись успешно сохранена!");

                OnValueChanged(firedEmployee);
                Close();
            }
            catch (Exception exception)
            {
                HandleError(exception);
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> PutFiredEmployee(string session, [FromRoute] int id, [FromBody] FiredEmployee firedEmployee)
        {
            if (!SessionLogic.Instance.Valid(session))
            {
                Response.StatusCode = 403;
                return(Json(ErrorType.AuthanticationFaild));
            }

            if (id != firedEmployee.FiredEmployeeId)
            {
                Response.StatusCode = 405;
                return(Json(ErrorType.NotFoundObject));
            }

            _context.Entry(firedEmployee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception)
            {
                Response.StatusCode = 500;
                return(Json(ErrorType.InternalError));
            }
        }