コード例 #1
0
        public async Task <IActionResult> Delete(int id)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Delete Attempted on record with id: {id} ");
                if (id < 1)
                {
                    _logger.LogWarn($"{location}: Delete failed with bad data - id: {id}");
                    return(BadRequest());
                }
                var isExists = await _professionRepository.isExists(id);

                if (!isExists)
                {
                    _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}");
                    return(NotFound());
                }
                var profession = await _professionRepository.FindById(id);

                var isSuccess = await _professionRepository.Delete(profession);

                if (!isSuccess)
                {
                    return(InternalError($"{location}: Delete failed for record with id: {id}"));
                }
                _logger.LogInfo($"{location}: Record with id: {id} successfully deleted");
                return(NoContent());
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }
コード例 #2
0
        public void Delete(int id)
        {
            var entity = repository.GetById(id);

            repository.Delete(entity);
            Save();
        }
コード例 #3
0
 /// <summary>
 /// Method whose purpose is to delete an existing
 /// profession record from the database
 /// </summary>
 /// <param name="profession">
 /// Existing ProfessionModel object.
 /// </param>
 /// <returns>
 /// Returns true if the query is successfully executed
 /// otherwise returns false.
 /// </returns>
 public bool Delete(ProfessionModel profession)
 {
     return(_professionRepository.Delete(profession) > 0 ? true : false);
 }
コード例 #4
0
 public void Delete(Int32 id)
 {
     repository.Delete(repository.GetById(id));
 }