public async Task <Result <ActivityModel, Error> > Delete(Guid activityId) { // Check authority var userId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value); var user = await _userRepository.GetById(userId); var userType = await _userTypeRepository.GetByName("Admin"); if (userType.Id != user.UserTypeId) { return(Result.Failure <ActivityModel, Error>(ErrorsList.UnauthorizedUser)); } var activity = await _activitiesRepository.GetById(activityId); if (activity == null) { return(Result.Failure <ActivityModel, Error>(ErrorsList.UnavailableActivity)); } _activitiesRepository.Delete(activity); await _activitiesRepository.SaveChanges(); return(_mapper.Map <ActivityModel>(activity)); }
public async Task <ActionResult <ActivityViewModel> > DeleteActivity(int id) { Activity activity = await _activitiesRepository.FindByIdAsync(id); if (activity == null) { return(NotFound($"No existe ninguna actividad con el código {id}.")); } _activitiesRepository.Delete(activity); await _unitWork.SaveAsync(); return(_mapper.Map <ActivityViewModel>(activity)); }
public async Task <Unit> Handle(DeleteCommand request, CancellationToken cancellationToken) { Activity activity = await _repository.GetActivity(request.Id); if (activity == null) { throw new RestException(HttpStatusCode.NotFound, new{ activity = "Not Found" }); } bool success = await _repository.Delete(activity); if (success) { return(Unit.Value); } throw new Exception("Problem with saving changes"); }
public void DeleteActivity(Activity activity) { IActivitiesRepository activitiesRepository = this.persistanceContext.GetActivitiesRepository(); foreach (var studentLink in activity.StudentsLink) { if (studentLink.Activity.Id == activity.Id) { foreach (var activityInfo in studentLink.Student.ActivityInfos) { if (activityInfo.Activity.Id == activity.Id) { activitiesRepository.RemoveActivityInfo(activityInfo); } } activitiesRepository.RemoveStudentActivity(studentLink); } } activitiesRepository.Delete(activity); }
public void Delete(Activities Entity) { _activitiesRepository.Delete(Entity); }
public void Delete(long id) { _activitiesRepository.Delete(id); }