public async Task <Employee> SaveStatusAndAddTimelineEntry(
            Employee employee,
            EmployeeStatusEnum newStatus
            )
        {
            var newStatusCode = newStatus.Code;
            var oldStatusCode = employee.CurrentEmployeeStatusCode;

            // Update employee status.
            employee.CurrentEmployeeStatusCode = newStatusCode;

            // Create a new timeline entry.
            employee.TimelineEntries.Add(new EmployeeTimelineEntry
            {
                EmployeeActionCode = EmployeeActionEnum.UpdateByTask.Code,
                EmployeeStatusCode = newStatusCode,
                Comment            = $"Status updated by script: " +
                                     $"{oldStatusCode} → {newStatusCode}."
            });
            context.Entry(employee).State = EntityState.Modified;

            // Update in CallWeb.
            await callWeb.UpdateSurvey(employee);

            // Save.
            await context.SaveChangesAsync();

            return(employee);
        }
        public async Task <ActionResult <AdminSetting> > PatchAdminSetting(int id, AdminSettingPatchDto adminSetting)
        {
            var existingAdminSetting = await FindById(id);

            existingAdminSetting.Value = adminSetting.Value;

            context.Entry(existingAdminSetting).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();

                return(Ok(existingAdminSetting));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdminSettingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <IActionResult> PatchEmployee(int id, EmployeePatchDto employeePatchDto)
        {
            var existingEmployee = await FindById(id);

            var updatedEmployee = employeePatchDto
                                  .ApplyPatch(existingEmployee);

            context.Entry(updatedEmployee).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();

                // Patch the row in CallWeb.
                await callWebService.UpdateSurvey(updatedEmployee);

                return(Ok(updatedEmployee));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #4
0
        public async Task <ActionResult <EmployeeTimelineEntry> > PostEmployeeTimelineEntry(EmployeeTimelineEntry employeeTimelineEntry)
        {
            // TODO: Do proper validation here.
            context.EmployeeTimelineEntries.Add(employeeTimelineEntry);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetEmployeeTimelineEntry), new { id = employeeTimelineEntry.Id }, employeeTimelineEntry));
        }
Beispiel #5
0
        public async Task <ActionResult <TaskLogEntry> > PostTaskLogEntry(TaskLogEntry taskLogEntry)
        {
            // TODO: Do proper validation here.
            context.TaskLogEntries.Add(taskLogEntry);
            await context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTaskLogEntry), new { id = taskLogEntry.Id }, taskLogEntry));
        }
        public async Task <TaskLogEntry> Log(
            TaskEnum task, TaskOutcomeEnum taskOutcome, string comment
            )
        {
            var entry = new TaskLogEntry()
            {
                TaskCode        = task.Code,
                TaskOutcomeCode = taskOutcome.Code,
                Comment         = comment
            };

            context.TaskLogEntries.Add(entry);
            await context.SaveChangesAsync();

            return(entry);
        }