Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteStudent(StudentModifyInputModel inputModel, string onSubmitAction)
        {
            if (onSubmitAction.IsNullOrEmpty() || onSubmitAction == "Cancel")
            {
                return(RedirectToAction(nameof(Index)));
            }

            try
            {
                await _studentsService.DeleteAsync(inputModel.Id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An exception occured during student DELETE operation for student with id {inputModel.Id}. Ex: {e.Message}");
                return(RedirectToAction("Error", "Home"));
            }
        }
        public async Task <IActionResult> DeleteStudentAsync(Guid id)
        {
            var st = await _studentsService.GetByIdAsync(id);

            if (st == null)
            {
                return(BadRequest("Student with id " + id + " doesn't exist"));
            }
            try
            {
                await _studentsService.DeleteAsync(st);

                return(Ok("Student with id " + id + " deleted"));
            }
            catch
            {
                return(this.ServerError("Failed to delete student"));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Delete(string id)
        {
            await _service.DeleteAsync(id);

            return(RedirectToAction("Index"));
        }