public async Task HandleAsync(CreateEvent command) { command.Id = Guid.NewGuid(); await _eventService.AddAsync(command.Id, command.UserId, (Discipline)command.Discipline, command.Description, command.Slots, command.Price, command.Date, command.ApproximateDuration, command.Place); }
public async Task <IActionResult> Create(EventViewModel model, int competitionInstanceId, int competitionId) { ViewBag.Disciplines = _disciplineService.GetAllDisciplines(); ViewBag.InstanceId = model.CompetitionInstanceId; if (ModelState.IsValid && model.Name != null) { try { var _event = await _eventService.AddAsync(model); // Create a Overall Category automatically var overall = new CategoryViewModel { Name = "Overall", AgeFrom = 0, AgeTo = 99, CountryId = 0, EventId = _event.Id, Gender = Gender.All }; await _categoryService.AddAsync(overall); } catch (Exception e) { return(Json(e.Message)); } return(RedirectToAction("CompetitionInstance", "Admin", new { competitionId, competitionInstanceId })); } return(View(model)); }
public override async Task <IActionResult> PostAsync(EventDto eventDto) { int.TryParse(_userManager.GetUserId(User), out var userId); var result = await _eventService.AddAsync(eventDto, userId).ConfigureAwait(true); return(result == null ? (IActionResult)NotFound($"Could not add {typeof(EventDto).Name}") : Ok(result)); }
public async Task <IHttpActionResult> CreateEvent([FromBody] EventDto @event) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } @event.OwnerUserId = User.Identity.GetUserId(); var result = await _eventService.AddAsync(@event); await _userEventService.AddAsync(User.Identity.GetUserId(), result.EventId); return(Created(Url.Request.RequestUri + "/" + result.EventId, result)); }
public async Task <IActionResult> PostAsync([FromBody] EventResource resource) { var eventToSave = _mapper.Map <EventResource, Event>(resource); var result = await _eventService.AddAsync(eventToSave); if (!result.Success) { return(BadRequest(new ErrorResource(result.Message))); } var eventResource = _mapper.Map <Event, EventResource>(result.Resource); return(Ok(eventResource)); }
public async Task <IActionResult> Create(CreateEventRequest request) { if (!ModelState.IsValid || request.Photo?.Length < 0) { return(View(request)); } var guid = Guid.NewGuid().ToString() + ".jpg"; var filepath = Path.Combine("images", guid); var filename = Path.Combine(_wwwroot, filepath); using (var stream = System.IO.File.Create(filename)) { await request.Photo.CopyToAsync(stream); } filepath = $"/{filepath.Replace("//","/").Replace("\\","/")}"; var eve = new Event(); eve.NamePl = request.NamePl; eve.NameEn = request.NameEn; eve.City = request.City; eve.DescriptionEn = request.DescriptionPl; eve.DescriptionPl = request.DescriptionEn; eve.EventType = request.EventType; eve.Date = request.Date; eve.Latitude = request.Latitude.Value; eve.Longitude = request.Longitude.Value; eve.PhotoPath = filepath; eve.TicketPrice = request.TicketPrice; await _eventService.AddAsync(eve); if (await _eventService.SaveChangesAsync() <= 0) { _logger.LogError("Failed to save new Event."); //TODO: LOCALISATION ViewData["Error"] = "Failed to save new Event."; return(View(request)); } //TODO: LOCALISATION ViewData["Message"] = "Created successfully"; return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult <EventModel> > CreateEvent(Guid userId, [FromBody] EventCreationModel eventCreationModel) { UserServiceModel user = await _userService.GetByPrincipalAsync(User); if (user == null || user.Id != userId) { return(Unauthorized()); } EventCreationServiceModel eventCreationServiceModel = _mapper .Map <EventCreationModel, EventCreationServiceModel>(eventCreationModel); EventServiceModel eventServiceModel = await _eventService.AddAsync(eventCreationServiceModel); EventModel eventModel = _mapper.Map <EventServiceModel, EventModel>(eventServiceModel); return(CreatedAtAction(nameof(GetEvent), new { eventId = eventModel.Id, userId = user.Id }, eventModel)); }
public async Task <IActionResult> Post([FromBody] EventViewModel value) { EventViewModel result = null; if (ModelState.IsValid) { var exist = false; var events = await eventService.GetAllAsync(); events.ToList().ForEach(element => { if (element.EntryDate == value.EntryDate) { exist = true; } }); if (!exist) { result = (await eventService.AddAsync(value.ToDto())).ToViewModel(); return(Created("{id}", result)); } } return(BadRequest()); }
public async Task <IActionResult> SetEvent([FromBody] Event request) { var response = await _eventService.AddAsync(request); return(Ok(response)); }
public async Task <bool> AddAsync(List <Event> eventSummaryDetails) { return(await _eventService.AddAsync(eventSummaryDetails)); }