public IActionResult Create(CreateEventInputModel model) { if (!ModelState.IsValid) { return(View()); } var newEvent = new Event { Name = model.Name, Place = model.Place, Start = model.Start, End = model.End, TotalTickets = model.TotalTickets, PricePerTicket = model.PricePerTicket }; this.dbContext.Events.Add(newEvent); try { this.dbContext.SaveChanges(); return(this.RedirectToAction("All")); } catch (Exception e) { return(this.BadRequest(e.Message)); } }
public async Task CreateAsync(CreateEventInputModel inputModel) { Event @event = new Event { Theme = inputModel.Theme, Address = inputModel.Address, StartDate = inputModel.StartDate, EndDate = inputModel.EndDate, CreatorId = inputModel.CreatorId, Description = inputModel.Description, }; foreach (var file in inputModel.Files) { string extension = System.IO.Path.GetExtension(file.FileName); string fileName = $"Events_{Guid.NewGuid()}" + extension; string remoteUrl = await this.cloudinaryService.UploadFile(file, fileName, extension, FILES_FOLDER); File uploadFile = new File { Extension = extension, RemoteUrl = remoteUrl, }; @event.Files.Add(uploadFile); } await this.eventsRepository.AddAsync(@event); await this.eventsRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(CreateEventInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.eventsService.CreateAsync(input); return(this.RedirectToAction(nameof(this.All))); }
public IActionResult Create(CreateEventInputModel input) { if (!ModelState.IsValid) { return(this.View(input)); } var userId = userManager.GetUserId(HttpContext.User); this.eventService.CreateEvent(input.Name, input.Description, input.Start, input.End, input.Address, input.ImageUrl, userId); return(this.RedirectToAction("MyEvents")); }
public IActionResult Create(CreateEventInputModel model, OrganizerInputModel modelOrganizer) { var user = this.userManager.GetUserId(this.User); if (!ModelState.IsValid) { return(View(model)); } var inputEvent = this.eventsService.CreateEvent(model, user); var organizer = this.organizersService.CreateOrganizer(modelOrganizer); return(this.View()); }
public async Task <IActionResult> Create(CreateEventInputModel inputModel) { ApplicationUser user = await this.userManager.GetUserAsync(this.User); if (!this.ModelState.IsValid) { return(this.View(inputModel)); } inputModel.CreatorId = user.Id; await this.eventsService.CreateAsync(inputModel); return(this.RedirectToAction("AllCreated", "Events", new { Id = user.Id })); }
public async Task CreateAsync(CreateEventInputModel input) { var events = new Event { Title = input.Title, Name = input.Name, Date = input.Date, Place = input.Place, Description = input.Description, }; await this.eventRepository.AddAsync(events); await this.eventRepository.SaveChangesAsync(); }
public IActionResult Create(CreateEventInputModel inputModel) { var newEvent = new Event { Name = inputModel.Name, Place = inputModel.Place, Start = inputModel.Start, End = inputModel.End, PricePerTicket = inputModel.PricePerTicket, TotalTickets = inputModel.TotalTickets }; this.context.Add(newEvent); this.context.SaveChanges(); return(this.Redirect("All")); }
public IActionResult Create(CreateEventInputModel model) { var eventuresEvent = this.mapper.Map <Event>(model); if (ModelState.IsValid) { this.eventsService.AddEvent(eventuresEvent, this.User); this.logger.LogInformation($"Event created: {model.Name}"); return(this.Redirect("/Events/All")); } else { return(this.View(model)); } }
public Event CreateEvent(CreateEventInputModel model, string userId) { var eventToCreate = new Event { Title = model.eventInputModel.Title, Performer = model.eventInputModel.Performer, DoorTime = model.eventInputModel.DoorTime, EndTime = model.eventInputModel.EndTime, Duration = model.eventInputModel.Duration, Description = model.eventInputModel.Description, EventSchedule = model.eventInputModel.EventSchedule, MaximumAttendeeCapacity = model.eventInputModel.MaximumAttendeeCapacity, IsAccessibleForFree = model.eventInputModel.IsAccessibleForFree, Price = model.eventInputModel.Price, CreatorId = userId, }; return(eventToCreate); }
public async Task <IActionResult> FillForm(CreateEventInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); var ev = new Event { Name = input.Name, Time = input.Time, EntranceFee = input.EntranceFee, EntranceType = input.EntranceType, Description = input.Description, PlaceUrl = "p/" + input.Name.Replace(' ', '-'), Initiator = user, }; if (this.Db.Places.Any(p => p.Name.Equals(input.PlaceName) && p.City.Equals(input.PlaceCity) && p.Address.Equals(input.PlaceCity))) { ev.Place = this.Db.Places.FirstOrDefault(p => p.Name.Equals(input.PlaceName)); } else { ev.Place = new Place { Address = input.PlaceCity, Name = input.PlaceName, City = input.PlaceCity, }; } var expectedFileExt = new[] { ".jpg", ".jpeg" }; if (input.Photos != null) { foreach (var photo in input.Photos) { if (expectedFileExt.Any(x => photo.FileName.EndsWith(x))) { var fileFolder = $"wwwroot\\images\\{input.PlaceName}"; System.IO.Directory.CreateDirectory(fileFolder); var path = $"{fileFolder}\\{photo.FileName}"; using (var fileStream = new FileStream(path, FileMode.Create)) { await photo.CopyToAsync(fileStream); } ev.Place.Images.Add(new Image { Path = $"images\\{input.PlaceName}\\{photo.FileName}", }); } } } else { if (ev.Place.Images.Count() == 0) { ev.Place.Images.Add(new Image { Path = $"images\\defaultPlaceImage.png", }); } } this.Db.Events.Add(ev); this.Db.SaveChanges(); return(this.Redirect("/")); }