public async Task HandleAsync(CreateActivity command) { var activity = await _activitiesCreator.CreateAsync(command.Id, command.Name, command.Type); _activitiesRepository.Add(activity); await _lifeLogContext.SaveChangesAsync(); }
public async Task <IHttpActionResult> PostActivity(Activity activity) { if (await _Repo.ActivityExists(activity.ActivityName)) { return(BadRequest("Kegiatan sudah pernah dibuat")); } activity.CreatedDate = DateTime.Now; activity.UpdatedDate = DateTime.Now; await _Repo.Add(activity); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken) { var activity = new Activity { Id = request.Id, Title = request.Title, Description = request.Description, Category = request.Category, Date = request.Date, City = request.City, Venue = request.Venue }; bool success = await _repository.Add(activity); if (success) { return(Unit.Value); } throw new Exception("Save not impossible"); }
public async Task <Result <ActivityModel, Error> > Add(CreateActivityModel model) { // 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 isActivityTypeNull = (await _activityTypesRepository.GetById(model.ActivityTypeId)) == null; if (isActivityTypeNull) { return(Result.Failure <ActivityModel, Error>(ErrorsList.UnavailableActivityType)); } var isCityNull = (await _cityRepository.GetById(model.CityId)) == null; if (isCityNull) { return(Result.Failure <ActivityModel, Error>(ErrorsList.InvalidCity)); } var activityModel = await _activitiesRepository.GetByName(model.Name); if (activityModel != null) { return(Result.Failure <ActivityModel, Error>(ErrorsList.ActivityExists)); } var activityEntity = _mapper.Map <Activity>(model); await _activitiesRepository.Add(activityEntity); await _activitiesRepository.SaveChanges(); return(_mapper.Map <ActivityModel>(activityEntity)); }
public void AddActivity(Activity activity) { IActivitiesRepository activitiesRepository = this.persistanceContext.GetActivitiesRepository(); activitiesRepository.Add(activity); }
public long Add(Activity activity) { return(_activitiesRepository.Add(activity)); }