public IActionResult Create([Bind("Title,Description,Date,RecordId,File")] EventCreateViewModel vm) { if (ModelState.IsValid) { var evt = new Event(); evt.Date = vm.Date; evt.Description = vm.Description; evt.Title = vm.Title; evt.RecordId = vm.RecordId; if (vm.File != null) { var file = vm.File; var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var filename = Path.Combine(_hostingEnvironment.WebRootPath, "images", "events", parsedContentDisposition.FileName.Trim('"')); using (var stream = System.IO.File.OpenWrite(filename)) { file.CopyTo(stream); } evt.ImagePath = parsedContentDisposition.FileName.Trim('"'); } _context.Add(evt); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> Create(EventCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var creatorId = this.userManager.GetUserId(User); var eventId = await this.events .CreateAsync( model.Name, model.StartDate, model.EndDate, creatorId, model.Limit ); if (eventId == 0) { TempData.AddErrorMessage($"Event start date should be equals ot greater than today, end date should be bigger than start date."); return(View(model)); } TempData.AddSuccessMessage($"Event {model.Name} is created succesfully."); return(RedirectToAction(nameof(Details), new { id = eventId })); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } List <EventStyle> StyleList = _context.EventStyle.Where(e => e.EventId == id).ToList(); EventCreateViewModel updateEvent = new EventCreateViewModel { Event = await _context.Event.FindAsync(id) }; foreach (EventStyle item in StyleList) { updateEvent.EventStyle.Add(item.StyleId); } //var @event = await _context.Event.FindAsync(id); if (updateEvent.Event == null) { return(NotFound()); } ViewData["StaffId"] = new SelectList(_context.Student.Where(s => s.InternalRankId != 1), "Id", "FullName", updateEvent.Event.StaffId); ViewData["Style"] = new SelectList(_context.Style, "Id", "Name", updateEvent.EventStyle); return(View(updateEvent)); }
public void Create_CreateAnEvent_OneEventIsCreated() { using (var controller = new EventController(this.fixture.context, null)) { var createEvent = new Event { Title = "Event6", Description = "Description 6", Date = DateTime.Now }; var createEvent2 = new EventCreateViewModel { Title = "Event6", Description = "Description 6", Date = DateTime.Now }; var result = controller.Create(createEvent2) as ViewResult; var resultEvent = this.fixture.context.Events.FirstOrDefault(g => g.Title == "Event6"); Assert.NotNull(resultEvent); Assert.Equal("Event6", resultEvent.Title); } }
public IActionResult SetAdministration(EventCreateViewModel createVM) { EventAdmin eventAdmin = new EventAdmin() { EventID = createVM.Event.ID, UserID = createVM.EventAdmin.UserID }; EventAdministration eventAdministration = new EventAdministration() { EventID = createVM.Event.ID, AdministrationType = "Писар", UserID = createVM.EventAdministration.UserID }; if (ModelState.IsValid) { _repoWrapper.EventAdmin.Create(eventAdmin); _repoWrapper.EventAdministration.Create(eventAdministration); _repoWrapper.Save(); return(RedirectToAction("EventInfo", "Action", new { id = createVM.Event.ID })); } else { Event events = _repoWrapper.Event.FindByCondition(i => i.ID == createVM.Event.ID).FirstOrDefault(); var model = new EventCreateViewModel() { Event = events, Users = _repoWrapper.User.FindAll() }; return(View(model)); } }
public IActionResult Create(EventCreateViewModel model) { var uploadResult = _fileService.Upload(model.PrimaryPicture, "Event", 1024 * 500); var serviceResult = new ServiceResult(); if (uploadResult.IsSuccess) { serviceResult = _adminService.CreateEvent(model.ToDto(uploadResult.Data)); if (serviceResult.IsSuccess) { Swal(true, "یک برنامه با موفقیت اضافه شد"); return(RedirectToAction(nameof(Create))); } } else { serviceResult.Errors = uploadResult.Errors; serviceResult.IsSuccess = false; } AddErrors(serviceResult); return(View(model)); }
public async Task <ActionResult> EventEdit([FromForm] EventCreateViewModel eventVM) { if (ModelState.IsValid) { var uploadedImage = ""; var editEvent = _mapper.Map <Event>(eventVM); if (eventVM.EventPhoto != null) { uploadedImage = await ProcessPhoto(eventVM.EventPhoto); } try { if (!string.IsNullOrWhiteSpace(uploadedImage)) { editEvent.ImgUrl = uploadedImage; } await _eventRepo.UpdateEvent(editEvent); TempData["Alert"] = "Event Edited Successfully"; return(RedirectToAction(nameof(EventIndex))); } catch (Exception ex) { ViewBag.Error = "Unable to add event, please try again or contact administrator"; return(View()); } } ViewBag.Error = "Please correct the error(s) in Form"; return(View()); }
public async Task PostEventWithSuggestedDates_V1_Happy() { // Arrange var eventName = "Event name"; var eventToBeCreated = new EventCreateViewModel { Name = eventName, Dates = new DateTime[] { DateTime.Today, DateTime.Today.AddDays(1), DateTime.Today.AddDays(2), } }; var apiVersion = "1"; var api = GetApiClient(); // Act var postResult = await api.PostEventAsync(apiVersion, eventToBeCreated); var result = await api.GetEventByIdAsync(postResult.Id, apiVersion); // Assert Assert.NotNull(result); Assert.Equal(postResult.Id, result.Id); Assert.Equal(eventName, result.Name); Assert.Equal(3, result.Dates.Count); Assert.Equal(0, result.Votes.Count); }
public ActionResult Create(EventCreateViewModel model) { if (ModelState.IsValid) { EventDto result = null; var eventInput = MapperManager.Map <EventInputDto>(model); try { result = _eventManageService.CreateEvent(eventInput); } catch (HasNoSeatsException) { ModelState.AddModelError("EventNoSeats", LanguageSummary.EventNoSeats); } catch (NotUniqueException) { ModelState.AddModelError("NotUnique", LanguageSummary.DescriptionOrNameNotUnique); } catch (DateInPastException) { ModelState.AddModelError("NotUnique", LanguageSummary.DateInPast); } if (result != null && result.Id > 0) { return(RedirectToAction("Index", "Event")); } } return(View(model)); }
private UIElement Add(IEnumerable <string> sports, IEnumerable <TournamentBaseModel> tournaments, IEnumerable <ParticipantTournamentModel> participants) { EventCreateViewModel viewModel = new EventCreateViewModel(sports, tournaments, participants); EventCreateControl control = new EventCreateControl(viewModel); viewModel.EventCreated += (s, e) => { EventCreateModel eventCreateModel = e.Event; EventCreateDTO eventCreateDTO = Mapper.Map <EventCreateModel, EventCreateDTO>(eventCreateModel); using (IEventService service = factory.CreateEventService()) { ServiceMessage serviceMessage = service.CreateWithParticipants(eventCreateDTO); RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message); if (serviceMessage.IsSuccessful) { viewModel.Notes = String.Empty; Notify(); } } }; return(control); }
public async Task <IActionResult> Create(EventCreateViewModel newEvent) { ViewData["StaffId"] = new SelectList(_context.Student.Where(s => s.InternalRankId != 1), "Id", "FullName", newEvent.Event.StaffId); ViewData["Style"] = new SelectList(_context.Style, "Id", "Name", newEvent.EventStyle); if (ModelState.IsValid) { _context.Add(newEvent.Event); foreach (int styleid in newEvent.EventStyle) { EventStyle styleForEvent = new EventStyle { StyleId = styleid, EventId = newEvent.Event.Id }; _context.EventStyle.Add(styleForEvent); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(newEvent)); }
public IActionResult AddEvent(EventCreateViewModel model) { if (ModelState.IsValid) { string uniqueFilename = null; if (model.Photo != null) { string uploadFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFilename = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadFolder, uniqueFilename); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } ClgEvent @event = new ClgEvent { Title = model.Title, Category = model.Category, Date = model.Date, Status = status.New, Venue = model.Venue, Description = model.Description, PhotoPath = uniqueFilename }; _eventRepository.AddEvent(@event); return(RedirectToAction("EventDetails", new { id = @event.Id, updated = false })); } return(View()); }
// GET: Event/Create public ActionResult Create() { var model = new EventCreateViewModel(); model.Date = DateTime.Now; return(View(model)); }
public IActionResult Create() { EventCreateViewModel evm = new EventCreateViewModel(); evm.Sports = DB.Sports.ToList(); evm.SkillLevels = DB.SkillLevels.ToList(); evm.PreferredGenders = DB.PreferredGenders.ToList(); return(View(evm)); }
public ActionResult Create(EventCreateViewModel model) { var newEvent = _mapper.Map <Event>(model); newEvent.Location = _mapper.Map <Location>(model.Location); newEvent.Participants = _mapper.Map <List <EventParticipant> >(model.Participants); _eventRepository.Create(newEvent); return(RedirectToAction("Create")); }
public async Task <IActionResult> Create(EventCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } await _EventsService.InsertEventAsync(model); return(RedirectToAction("List")); }
public ActionResult <EventViewModel> Create([FromBody] EventCreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUserId = User.Claims.FirstOrDefault(c => c.Type.Equals(ClaimTypes.NameIdentifier))?.Value; return(_mapper.Map <EventViewModel>(_eventService.CreateEvent(model.Name, currentUserId))); }
public string SaveFileAndGetName(EventCreateViewModel @event) { var fileName = $"{ Path.GetRandomFileName()}" + $".{Path.GetExtension(@event.Banner.FileName)}"; using (var stream = System.IO.File.Create(Path.Combine("wwwroot/img/events/", fileName))) { @event.Banner.CopyTo(stream); } return(fileName); }
// GET: Event/Create public ActionResult Create() { var viewModel = new EventCreateViewModel(); for (int i = 0; i < 2; i++) { viewModel.Participants.Add(new EventParticipant()); } return(View(viewModel)); }
public IActionResult Create(EventCreateViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } events.Create(model.Name, model.Place, model.Start, model.End, model.Tickets, model.PricePerTicket); this.logger.LogInformation("Event created: " + model.Name, model); return(this.RedirectToAction(nameof(All))); }
public IActionResult SetAdministration(string idUser, int id) { var model = new EventCreateViewModel() { Event = _repoWrapper.Event. FindByCondition(i => i.ID == id). FirstOrDefault(), Users = _repoWrapper.User.FindByCondition(i => i.Id != idUser) }; return(View(model)); }
public async Task <IActionResult> Create(string returnUrl) { var eventTypeResult = await _mediator.Send(new GetEventTypeListQuery()); var eventSeriesResult = await _mediator.Send(new GetEventSeriesesListQuery()); EventCreateViewModel vm = new EventCreateViewModel(eventTypeResult.EventTypes.ToList(), eventSeriesResult.EventSerieses.ToList(), _dateTime); ViewBag.ReturnUrl = returnUrl; ViewData["Title"] = "Create Event"; return(View(vm)); }
public ActionResult CreateEvent() { var viewModel = new EventCreateViewModel { ProbableEvent = new ProbableEvent { EventDate = DateTime.Today } }; return(View("EventForm", viewModel)); }
public async Task <IActionResult> PostEventAsync([FromBody] EventCreateViewModel eventToCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdEventId = await _eventService.CreateEventAsync(eventToCreate.Name, eventToCreate.Dates.ToList()); return(Created(nameof(GetEventByIdAsync), new BaseViewModel { Id = createdEventId })); }
public async Task <IActionResult> Create(EventCreateViewModel model) { if (!ModelState.IsValid) { return(this.View(model)); } await this.eventsService.CreateAsync(model.Name, model.Place, model.TicketPrice, model.TotalTickets, model.Start, model.End); this.logger.LogInformation("Event created: " + model.Name, model); return(this.Redirect("/Events/All")); }
public EventCreateViewModel GetEventCreateViewModel() { var model = new EventCreateViewModel { Event = new EventCreationViewModel { ID = 1, EventName = "тест", Description = "опис", Questions = "питання", EventDateStart = DateTime.Now, EventDateEnd = DateTime.Now, Eventlocation = "Львів", EventCategoryID = 3, EventStatusID = 2, EventTypeID = 1, FormOfHolding = "абв", ForWhom = "дітей", NumberOfPartisipants = 1 }, Сommandant = new EventAdministrationViewModel { UserId = "2", User = new UserInfoViewModel { }, Email = "[email protected]", FullName = "Ostap Shutiak" }, EventCategories = new List <EventCategoryViewModel> { new EventCategoryViewModel { EventCategoryId = 1, EventCategoryName = "КПЗ" } }, EventTypes = new List <EventTypeViewModel> { new EventTypeViewModel { ID = 1, EventTypeName = "подія" } }, Users = new List <UserInfoViewModel> { } }; return(model); }
public async Task <IActionResult> CreateEvent(EventCreateViewModel @event) { if (ModelState.IsValid) { var fileName = eventsService.SaveFileAndGetName(@event); Event eventobj = new Event { Name = @event.Name, Venue = @event.Venue, VenueId = @event.VenueId, Date = @event.Date, Banner = "events/" + fileName, Description = @event.Description }; await eventsService.AddEventToDb(eventobj); } return(RedirectToAction("Events")); }
public async Task <IActionResult> Create(EventCreateViewModel input) { try { if (!this.ModelState.IsValid) { return(this.View(input)); } using var stream = input.Img.OpenReadStream(); var user = await this.userManager.GetUserAsync(this.User); var @event = new Event { Title = input.Title, Description = input.Description, Date = input.Date, Entry = input.Entry, HostId = user.Id, Location = input.Location, }; ImageUploadParams uploadParams = new ImageUploadParams { Folder = "Events", Transformation = new Transformation().Crop("limit").Width(800).Height(600), File = new FileDescription($"{Guid.NewGuid()}_{@event.Title}", stream), }; UploadResult uploadResult = await this.cloudinary.UploadAsync(uploadParams); var imgUrl = uploadResult.SecureUri.AbsoluteUri; @event.Img = imgUrl; UsersEvents usersEvents = new UsersEvents { Event = @event, EventId = @event.Id, User = user, UserId = user.Id }; @event.EventsUser.Add(usersEvents); await this.eventRepository.AddAsync(@event); await this.eventRepository.SaveChangesAsync(); return(this.RedirectToAction("ById", new { Id = @event.Id })); } catch (Exception) { return(this.View("Error")); } }
/// <summary> /// User áltál létrhezott event viewModeljét átalakitja modelé és menti db-ben /// </summary> /// <param name="viewModel"></param> /// <param name="userId"></param> public void InsertOrUpdateUserEvent(EventCreateViewModel viewModel, string userId) { try { if (viewModel.ID != 0) { var model = new EventsModel { ID = viewModel.ID, Name = viewModel.Name, StartDate = viewModel.StartDate, EndDate = viewModel.EndDate, PurcheEnd = viewModel.PurcheEnd, Description = viewModel.Description, OwnerID = userId, LogoImgUrl = viewModel.LogoImgUrl, Fields = viewModel.Fields.Select(x => new FieldsModel { Name = x.Name, InputType = x.InputType.ToString() }).ToList() }; _db.EventModels.Add(model); _db.SaveChanges(); } else { var model = new EventsModel { Name = viewModel.Name, StartDate = viewModel.StartDate, EndDate = viewModel.EndDate, PurcheEnd = viewModel.PurcheEnd, Description = viewModel.Description, OwnerID = userId, LogoImgUrl = viewModel.LogoImgUrl, Fields = viewModel.Fields.Select(x => new FieldsModel { Name = x.Name, InputType = x.InputType.ToString() }).ToList() }; _db.EventModels.Add(model); _db.SaveChanges(); } } catch (Exception exp) { throw; } }
public static EventCreateDto ToDto(this EventCreateViewModel source, string fileName) { return(new EventCreateDto { Date = source.Date.ToDateTime(), Description = source.Description, EndDate = source.EndDate.ToDateTime(), MultiDay = source.MultiDay, PrimaryPicture = fileName, StartDate = source.StartDate.ToDateTime(), Time = source.Time, Title = source.Title }); }