public async Task <ObjectResult> Get(string studentId) { Guid _studentId; try { if (!Guid.TryParse(studentId, out _studentId)) { return(BadRequest(studentId)); } var response = await _studentProvider.Retrieve(studentId); return(response.Success ? StatusCode((int)HttpStatusCode.OK, response) : StatusCode((int)HttpStatusCode.NotFound, response)); } catch (Exception ex) { /* * await _firehoseProvider.PublishAsync(Topics.Logs, new Activity<string>(){ Id = Guid.NewGuid().ToString(), * Timestamp = DateTime.UtcNow, * Payload = new ActivityPayload<string>() * { Data = string.Format($"StudentsController: Get(), StudentId: {studentId}, Error: {ex}")}, * ActivityType = ActivityType.Log}); */ return(StatusCode((int)HttpStatusCode.InternalServerError, new ProviderResponse <IClass>() { Success = false, ResponseStatus = CustomResponseErrors.StudentRetrieveFailed.ToString("f"), Exception = ex, Message = ex.Message })); } }
public async Task <ObjectResult> Delete(string classId) { Guid _classId; try { if (!Guid.TryParse(classId, out _classId)) { return(BadRequest(classId)); } var response = await _classProvider.Delete(classId); if (response.Success) { List <Task> deleteTasks = new List <Task>(), updateIndexTasks = new List <Task>(); var retrieveUpdatedTasks = new List <Task <IProviderResponse <IStudent> > >(); /* * await _firehoseProvider.PublishAsync(Topics.Logs | Topics.SearchIndexes, new Activity<IClass>() * { * Id = Guid.NewGuid().ToString(), * ActivityType = ActivityType.ClassDelete, * Timestamp = DateTime.UtcNow, * Payload = new ActivityPayload<IClass>(){ * Data = response.Data * } * } * ); */ updateIndexTasks.Add(_searchProvider.RemoveFromElastic(response.Data)); foreach (var studentId in response.Data.EnrolleeIds) { deleteTasks.Add(_studentProvider.UnEnroll(response.Data.Code, studentId)); } await Task.WhenAll(deleteTasks); foreach (var studentId in response.Data.EnrolleeIds) { retrieveUpdatedTasks.Add(_studentProvider.Retrieve(studentId)); } await Task.WhenAll(retrieveUpdatedTasks); foreach (var completedTask in retrieveUpdatedTasks) { if (completedTask.Result.Success) { var updatedStudent = completedTask.Result.Data; updateIndexTasks.Add(_searchProvider.UpdateElastic(updatedStudent)); } } await Task.WhenAll(updateIndexTasks); return(StatusCode((int)HttpStatusCode.OK, response)); } else { /* * await _firehoseProvider.PublishAsync(Topics.Logs, new Activity<string>(){ Id = Guid.NewGuid().ToString(), * Timestamp = DateTime.UtcNow, * Payload = new ActivityPayload<string>() * { Data = string.Format($"ClassesController: Edit(), RequestJson: {classUpdateRequestJson}, ErrorResponse: {response}")}, * ActivityType = ActivityType.Log}); */ return(StatusCode((int)HttpStatusCode.InternalServerError, response)); } } catch (Exception ex) { /* * await _firehoseProvider.PublishAsync(Topics.Logs, new Activity<string>(){ Id = Guid.NewGuid().ToString(), * Timestamp = DateTime.UtcNow, * Payload = new ActivityPayload<string>() * { Data = string.Format($"ClassesController: Delete(), ClassId: {classId}, Exception: {ex}")}, * ActivityType = ActivityType.Log}); */ return(StatusCode((int)HttpStatusCode.InternalServerError, new ProviderResponse <IClass>() { Success = false, ResponseStatus = CustomResponseErrors.ClassUpdateFailed.ToString("f"), Exception = ex, Message = ex.Message })); } }