public async Task Handle_Given_Invalid_EventSeriesId_Throws_ValidationException(int value)
        {
            // Arrange
            var validId              = 1;
            var validTitle           = "This is a valid title.";
            var validDescription     = "This is a valid Description";
            var validStartDate       = new DateTime(2020, 3, 1);
            var validEndDate         = new DateTime(2020, 3, 2);
            var validRegStartDate    = new DateTime(2020, 2, 3);
            var validRegEndDate      = new DateTime(2020, 2, 4);
            var validMaxRegs         = 10;
            var validEventTypeId     = 1;
            var inValidEventSeriesId = value;
            var command              = new UpdateEventCommand
            {
                Id            = validId,
                Title         = validTitle,
                Description   = validDescription,
                StartDate     = validStartDate,
                EndDate       = validEndDate,
                RegStartDate  = validRegStartDate,
                RegEndDate    = validRegEndDate,
                MaxRegsCount  = validMaxRegs,
                EventTypeId   = validEventTypeId,
                EventSeriesId = inValidEventSeriesId
            };
            // Act/Assert
            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.Equal(1, ex.Failures.Count);
        }
        public async Task Handle_Given_Invalid_EventId_Throws_NotFoundException()
        {
            // Arrange
            var inValidId            = 100;
            var newValidTitle        = "Updated Event Title";
            var newValidDescription  = "This is an updated Event description";
            var newValidStartDate    = new DateTime(2020, 10, 1);
            var newValidEndDate      = new DateTime(2020, 10, 2);
            var newValidRegStartDate = new DateTime(2020, 9, 1);
            var newValidRegEndDate   = new DateTime(2020, 9, 2);
            var newValidMaxRegs      = 20;
            var newValidEventTypeId  = 2;
            var command = new UpdateEventCommand
            {
                Id           = inValidId,
                Title        = newValidTitle,
                Description  = newValidDescription,
                StartDate    = newValidStartDate,
                EndDate      = newValidEndDate,
                RegStartDate = newValidRegStartDate,
                RegEndDate   = newValidRegEndDate,
                MaxRegsCount = newValidMaxRegs,
                EventTypeId  = newValidEventTypeId
            };

            // Act/Assert
            await Assert.ThrowsAsync <NotFoundException>(() => _sut.Handle(command, CancellationToken.None));
        }
예제 #3
0
        public async Task <IActionResult> UpdateEvent(int eventId, [FromBody] UpdateEventRequest request)
        {
            var updateEventCommand = new UpdateEventCommand(eventId, request);
            var result             = await mediator.Send(updateEventCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
예제 #4
0
        public async Task <IActionResult> Put(Guid eventId, [FromBody] UpdateEventCommand message)
        {
            message.Id = eventId;
            await _mediator.Send(message);

            return(NoContent());
        }
        public async Task Remove_A_Sponsors()
        {
            FillData();
            _newEvent.AddSponsor(_firstSponsor, "Razón");
            _newEvent.AddSponsor(_secondSponsor, "Razón");
            Context.SaveChanges();
            var update = new UpdateEventCommand
            {
                Sponsors = new List <SponsorEventViewModel> {
                    new SponsorEventViewModel {
                        SponsorId = _secondSponsor.Id, Detail = "Yeahh"
                    }
                }
            };

            var response = await HttpClient.PutAsync($"/events/{_newEvent.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(update), Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            RefreshContext();
            var eventToCheck = Context.Events.Include(x => x.Sponsors).First();

            eventToCheck.Sponsors.Count.Should().Be(1);
            eventToCheck.Sponsors.First().Detail.Should().Be(update.Sponsors.First().Detail);
        }
예제 #6
0
        public async Task <ActionResult> Put(
            [FromServices] DataContext context,
            [FromServices] EventRepository repository,
            [FromBody] UpdateEventCommand command,
            int id)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(BadRequest(ModelState));
                }

                var @event = await repository.GetByIdAsync(id);

                if (@event == null)
                {
                    return(NotFound(new { message = "O Evento não foi localizado." }));
                }

                var date = new DateTime(
                    Convert.ToInt32(command.Date.Substring(6, 4)),
                    Convert.ToInt32(command.Date.Substring(3, 2)),
                    Convert.ToInt32(command.Date.Substring(0, 2)),
                    0, 0, 0);

                DateTime?startH = null;
                DateTime?endH   = null;

                if (command.StartHour != "")
                {
                    startH = new DateTime(01, 01, 01, Convert.ToInt32(command.StartHour.Substring(0, 2)), Convert.ToInt32(command.StartHour.Substring(3, 2)), 0);
                }

                if (command.EndHour != "")
                {
                    endH = new DateTime(01, 01, 01, Convert.ToInt32(command.EndHour.Substring(0, 2)), Convert.ToInt32(command.EndHour.Substring(3, 2)), 0);
                }

                @event.UpdateEvent(command.Name.Trim(),
                                   date,
                                   startH,
                                   endH,
                                   command.Local,
                                   command.Note,
                                   command.Status);

                @event.LastModifiedDate = DateTime.Now;

                repository.Update(@event);
                await context.SaveChangesAsync();

                return(Ok(new { @event }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  new { message = ex.Message }));
            }
        }
        public async Task Update_Event_Details()
        {
            FillData();

            var update = new UpdateEventCommand
            {
                Description     = "Description 2",
                Title           = "Title 2",
                ImageUrl        = "ImageUrl 2",
                Url             = "Url 2",
                Done            = true,
                GeneralAttended = true,
                Online          = true,
                OnlineLink      = "https://randomlink.com"
            };

            var response = await HttpClient.PutAsync($"/events/{_newEvent.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(update), Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            RefreshContext();
            var eventToCheck = Context.Events.First();

            eventToCheck.Description.Should().Be(update.Description);
            eventToCheck.Title.Should().Be(update.Title);
            eventToCheck.Online.Should().BeTrue();
            eventToCheck.ImageUrl.Should().Be(update.ImageUrl);
            eventToCheck.OnlineLink.Should().Be(update.OnlineLink);
            eventToCheck.Url.Should().Be(update.Url);
            eventToCheck.GeneralAttended.Should().Be(update.GeneralAttended.Value);
            eventToCheck.Done.Should().BeTrue();
            eventToCheck.Live.Should().BeFalse();
        }
        public async Task Handle_Given_MaxRegs_Zero_Throws_ValidattionException()
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "This is a valid title.";
            var validDescription  = "This is a valid Description";
            var validStartDate    = new DateTime(2020, 3, 1);
            var validEndDate      = new DateTime(2020, 3, 2);
            var validRegStartDate = new DateTime(2020, 2, 3);
            var validRegEndDate   = new DateTime(2020, 2, 4);
            var inValidMaxRegs    = 0;
            var validEventTypeId  = 1;
            var command           = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = inValidMaxRegs,
                EventTypeId  = validEventTypeId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, x => x.PropertyName == "MaxRegsCount");
        }
        public async Task Validate_Given_Invalid_EventSeriesId_Validator_Is_Invalid(int value)
        {
            // Arrange
            var validId              = 1;
            var validTitle           = "This is a valid title.";
            var validDescription     = "This is a valid Description";
            var validStartDate       = new DateTime(2020, 3, 1);
            var validEndDate         = new DateTime(2020, 3, 2);
            var validRegStartDate    = new DateTime(2020, 2, 3);
            var validRegEndDate      = new DateTime(2020, 2, 4);
            var validMaxRegs         = 10;
            var inValidEventTypeId   = 0;
            var inValidEventSeriesId = value;
            var command              = new UpdateEventCommand
            {
                Id            = validId,
                Title         = validTitle,
                Description   = validDescription,
                StartDate     = validStartDate,
                EndDate       = validEndDate,
                RegStartDate  = validRegStartDate,
                RegEndDate    = validRegEndDate,
                MaxRegsCount  = validMaxRegs,
                EventTypeId   = inValidEventTypeId,
                EventSeriesId = inValidEventSeriesId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, x => x.PropertyName == "EventSeriesId");
        }
예제 #10
0
        public IActionResult Update([FromBody] UpdateEventCommand command)
        {
            var commandResult = _mediator.Send(command);

            if (commandResult.IsFaulted)
            {
                return(BadRequest(commandResult.Exception.InnerException.Message));
            }

            return(Ok(new { message = "Event updated" }));
        }
예제 #11
0
        public async Task <IActionResult> Put(Guid eventId,
                                              [FromBody]
                                              UpdateEventCommand updateEventCommand)
        {
            try {
                await _eventService.UpdateAsync(
                    eventId, updateEventCommand.Name, updateEventCommand.Description
                    );

                return(NoContent());
            } catch (EventNotFoundException) {
                return(NotFound());
            } catch (EventAlreadyExistsException) {
                return(Conflict());
            }
        }
예제 #12
0
        public async Task <ApiResponse <Guid> > UpdateEvent(EventDetailViewModel eventDetailViewModel)
        {
            try
            {
                UpdateEventCommand updateEventCommand = _mapper.Map <UpdateEventCommand>(eventDetailViewModel);
                await _client.UpdateEventAsync(updateEventCommand);

                return(new ApiResponse <Guid>()
                {
                    Success = true
                });
            }
            catch (ApiException ex)
            {
                return(ConvertApiExceptions <Guid>(ex));
            }
        }
        public async Task UpdateEvent(UpdateEventCommand updateEventCommand)
        {
            var documentResult = await _eventsBucket.MutateIn <EventDocument>(updateEventCommand.EventId.ToString())
                                 .Replace("subject", updateEventCommand.Subject)
                                 .Replace("description", updateEventCommand.Description)
                                 .Replace("date", updateEventCommand.Date)
                                 .Replace("endDate", updateEventCommand.EndDate)
                                 .Replace("capacity", updateEventCommand.Capacity)
                                 .Replace("address", updateEventCommand.Address)
                                 .Replace("location.lat", updateEventCommand.Latitude)
                                 .Replace("location.lon", updateEventCommand.Longitude)
                                 .ExecuteAsync();

            if (!documentResult.Success)
            {
                throw documentResult.Exception;
            }
        }
예제 #14
0
        public async Task Validate_Given_Invalid_City_Validator_Is_Invalid(string value)
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 3);
            var validEndDate      = new DateTime(2020, 3, 4);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var validStreet       = "123 Anywhere St.";
            var validSuite        = "Room #3";
            var inValidCity       = value;
            var validState        = "MD";
            var validZip          = "12345";

            var command = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId,
                Street       = validStreet,
                Suite        = validSuite,
                City         = inValidCity,
                State        = validState,
                Zip          = validZip
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider());

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Contains(result.Errors, x => x.PropertyName == "City");
        }
        public async Task Set_Event_UnLive()
        {
            FillData();

            var update = new UpdateEventCommand
            {
                Live = false
            };

            var response = await HttpClient.PutAsync($"/events/{_newEvent.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(update), Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            RefreshContext();
            var eventToCheck = Context.Events.First();

            eventToCheck.Live.Should().BeFalse();
            eventToCheck.EndLiveTime.Should().NotBeNull();
        }
        public async Task Enable_event_General_Attendance()
        {
            FillData();

            var update = new UpdateEventCommand
            {
                GeneralAttended = true
            };

            var response = await HttpClient.PutAsync($"/events/{_newEvent.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(update), Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            RefreshContext();
            var eventToCheck = Context.Events.First();

            eventToCheck.GeneralAttended.Should().BeTrue();
            eventToCheck.GeneralAttendedCode.Should().NotBeNull();
        }
        public Task <bool> Handle(UpdateEventCommand request, CancellationToken cancellationToken)
        {
            var _event = new Event()
            {
                Id          = request.Id,
                Name        = request.Name,
                Price       = request.Price,
                Description = request.Description,
                EventDate   = request.EventDate,
                Address     = request.Address,
                Image       = request.Image,
            };

            _eventRepository.Update(_event);

            _unitOfWork.Commit();

            return(Task.FromResult(true));
        }
예제 #18
0
        public async Task Validate_Given_Valid_Zip_Validator_Is_Valid(string value)
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 3);
            var validEndDate      = new DateTime(2020, 3, 4);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var validStreet       = "123 Anywhere St.";
            var validSuite        = "Room #3";
            var validCity         = "Yourtown";
            var validState        = "MD";
            var validZip          = value;

            var command = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId,
                Street       = validStreet,
                Suite        = validSuite,
                City         = validCity,
                State        = validState,
                Zip          = validZip
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider());

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            Assert.True(result.IsValid);
        }
예제 #19
0
        public async Task Handle_Given_Invalid_Zip_Throws_ValidationException(string value)
        {
            // Arrange
            var validId           = 1;
            var validTitle        = "Event Created from Unit Tests.";
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 3);
            var validEndDate      = new DateTime(2020, 3, 4);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var validStreet       = "123 Anywhere St.";
            var validSuite        = "Room #3";
            var validCity         = "Yourtown";
            var validState        = "MD";
            var inValidZip        = value;

            var command = new UpdateEventCommand
            {
                Id           = validId,
                Title        = validTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId,
                Street       = validStreet,
                Suite        = validSuite,
                City         = validCity,
                State        = validState,
                Zip          = inValidZip
            };

            // Act/Assert
            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.Equal(1, ex.Failures.Count);
        }
예제 #20
0
        public async Task <ActionResult <Event> > UpdateAsync(int id, UpdateEventCommand data)
        {
            var foundEvent = await _eventRepository.FindByIdAsync(id);

            if (foundEvent == null)
            {
                return(NotFound());
            }

            var operationResult = foundEvent.UpdateEventDetails(data);

            if (!operationResult.IsValid)
            {
                ModelState.AddFromOperationResult(operationResult);
                return(BadRequest(ModelState));
            }

            await _eventRepository.UpdateAsync(foundEvent);

            return(Ok(foundEvent));
        }
예제 #21
0
        public async Task Handle_Given_Minimum_Valid_Values_Updates_Event()
        {
            // Arrange
            var validId              = 1;
            var newValidTitle        = "Updated Event Title";
            var newValidDescription  = "This is an updated Event description";
            var newValidStartDate    = new DateTime(2020, 10, 1);
            var newValidEndDate      = new DateTime(2020, 10, 2);
            var newValidRegStartDate = new DateTime(2020, 9, 1);
            var newValidRegEndDate   = new DateTime(2020, 9, 2);
            var newValidMaxRegs      = 20;
            var newValidEventTypeId  = 2;
            var command              = new UpdateEventCommand
            {
                Id           = validId,
                Title        = newValidTitle,
                Description  = newValidDescription,
                StartDate    = newValidStartDate,
                EndDate      = newValidEndDate,
                RegStartDate = newValidRegStartDate,
                RegEndDate   = newValidRegEndDate,
                MaxRegsCount = newValidMaxRegs,
                EventTypeId  = newValidEventTypeId
            };
            // Act
            await _sut.Handle(command, CancellationToken.None);

            Event e = _context.Events.Find(validId);

            // Assert
            Assert.NotNull(e);
            Assert.Equal(e.Title, newValidTitle);
            Assert.Equal(e.Description, newValidDescription);
            Assert.Equal(e.Dates.StartDate, newValidStartDate);
            Assert.Equal(e.Dates.EndDate, newValidEndDate);
            Assert.Equal(e.Dates.RegistrationStartDate, newValidRegStartDate);
            Assert.Equal(e.Dates.RegistrationEndDate, newValidRegEndDate);
            Assert.Equal((int)e.Rules.MaxRegistrations, newValidMaxRegs);
            Assert.Equal(e.EventTypeId, newValidEventTypeId);
        }
        public async Task Add_Sponsors()
        {
            FillData();

            var update = new UpdateEventCommand
            {
                Sponsors = new List <SponsorEventViewModel>
                {
                    new SponsorEventViewModel {
                        SponsorId = 2, Detail = "Detail test"
                    }
                }
            };

            var response = await HttpClient.PutAsync($"/events/{_newEvent.Id}",
                                                     new StringContent(JsonConvert.SerializeObject(update), Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            RefreshContext();
            var eventToCheck = Context.Events.Include(x => x.Sponsors).First();

            eventToCheck.Sponsors.Count.Should().Be(1);
        }
예제 #23
0
        public async Task Handle_Given_Invalid_Title_Throws_ValidationException(string value)
        {
            // Arrange
            var validId           = 1;
            var inValidTitle      = value;
            var validDescription  = "This event was created from a Unit Test.";
            var validStartDate    = new DateTime(2020, 3, 1);
            var validEndDate      = new DateTime(2020, 3, 2);
            var validRegStartDate = new DateTime(2020, 2, 1);
            var validRegEndDate   = new DateTime(2020, 2, 2);
            var validMaxRegs      = 10;
            var validEventTypeId  = 1;
            var command           = new UpdateEventCommand
            {
                Id           = validId,
                Title        = inValidTitle,
                Description  = validDescription,
                StartDate    = validStartDate,
                EndDate      = validEndDate,
                RegStartDate = validRegStartDate,
                RegEndDate   = validRegEndDate,
                MaxRegsCount = validMaxRegs,
                EventTypeId  = validEventTypeId
            };
            var validator = new UpdateEventCommandValidator(new DateTimeTestProvider()); // manually invoke to test the Validator

            // Act/Assert
            var result = await validator.ValidateAsync(command);

            var ex = await Assert.ThrowsAsync <ValidationException>(() => _sut.Handle(command, CancellationToken.None));

            Assert.Equal(1, ex.Failures.Count);
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Contains(result.Errors, x => x.PropertyName == "Title");
        }
예제 #24
0
 public async Task <IActionResult> UpdateEvent(UpdateEventCommand request)
 {
     return(Ok(await _mediator.Send(request)));
 }
예제 #25
0
 public void HandleCommand(UpdateEventCommand command)
 {
     eventRepository.UpdateEvent(command.Event);
 }
예제 #26
0
        public async Task <IActionResult> Edit(int id, [Bind(
                                                            "Id," +
                                                            "EventTypeId," +
                                                            "EventSeriesId," +
                                                            "Title," +
                                                            "Description," +
                                                            "FundCenter," +
                                                            "StartDate," +
                                                            "EndDate," +
                                                            "RegistrationOpenDate," +
                                                            "RegistrationClosedDate," +
                                                            "MinRegistrationCount," +
                                                            "MaxRegistrationCount," +
                                                            "AllowStandby," +
                                                            "MaxStandbyRegistrationCount," +
                                                            "AddressLine1," +
                                                            "AddressLine2," +
                                                            "City," +
                                                            "State," +
                                                            "Zip"
                                                            )] EventEditViewModel form, string returnUrl)
        {
            if (id != form.Id)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                var eventTypeResult = await _mediator.Send(new GetEventTypeListQuery());

                var eventSeriesResult = await _mediator.Send(new GetEventSeriesesListQuery());

                form.EventTypes = eventTypeResult.EventTypes.ToList().ConvertAll(x => new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                });
                form.EventSerieses = eventSeriesResult.EventSerieses.ToList().ConvertAll(x => new SelectListItem {
                    Text = x.Title, Value = x.Id.ToString()
                });
                ViewBag.ReturnUrl = returnUrl;
                ViewData["Title"] = "Edit Event: Error";
                return(View(form));
            }
            try
            {
                var command = new UpdateEventCommand
                {
                    Id              = form.Id,
                    EventTypeId     = form.EventTypeId,
                    EventSeriesId   = form.EventSeriesId,
                    Title           = form.Title,
                    Description     = form.Description,
                    StartDate       = form.StartDate,
                    EndDate         = form.EndDate,
                    RegStartDate    = form.RegistrationOpenDate,
                    RegEndDate      = form.RegistrationClosedDate,
                    MaxRegsCount    = form.MaxRegistrationCount,
                    MinRegsCount    = form.MinRegistrationCount,
                    MaxStandbyCount = form.MaxStandbyRegistrationCount,
                    Street          = form.AddressLine1,
                    Suite           = form.AddressLine2,
                    City            = form.City,
                    State           = form.State,
                    Zip             = form.Zip
                };
                await _mediator.Send(command);

                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (ValidationException ex)
            {
                foreach (var failure in ex.Failures)
                {
                    foreach (var message in failure.Value)
                    {
                        ModelState.AddModelError(failure.Key, message);
                    }
                }
                var eventTypeResult = await _mediator.Send(new GetEventTypeListQuery());

                var eventSeriesResult = await _mediator.Send(new GetEventSeriesesListQuery());

                form.EventTypes = eventTypeResult.EventTypes.ToList().ConvertAll(x => new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                });
                form.EventSerieses = eventSeriesResult.EventSerieses.ToList().ConvertAll(x => new SelectListItem {
                    Text = x.Title, Value = x.Id.ToString()
                });
                ViewBag.ReturnUrl = returnUrl;
                ViewData["Title"] = "Create Event: Error";
                return(View(form));
            }
        }
예제 #27
0
        public Event SaveEvent()
        {
            string category         = Request.Form.Get("Event.CategoryId.Id");
            string eventVenue       = Request.Form.Get("Event.Venue");
            string eventName        = Request.Form.Get("Event.EventName");
            string eventDate        = Request.Form.Get("Event.EventDate");
            string ticketQuantity   = Request.Form.Get("Event.Quantity");
            string maxClaims        = Request.Form.Get("Event.Claims");
            string eventDescription = Request.Form.Get("Event.EventDescription");
            string eventId          = Request.Form.Get("Event.EventId");


            DateTime enteredDate           = DateTime.Parse(eventDate);
            DateTime datePosted            = DateTime.Now;
            int      enteredTicketQuantity = int.Parse(ticketQuantity);
            int      categoryId            = int.Parse(category);
            int      enteredMaxClaims      = int.Parse(maxClaims);
            int      postStatus            = 1;
            int      totalHandsRaised      = 0;
            int      maxWinners            = Convert.ToInt32(Math.Floor(Convert.ToDecimal((enteredTicketQuantity / enteredMaxClaims))));
            int      remainingWinners      = maxWinners;

            if (eventId != "")
            {
                int updateEventId = int.Parse(eventId);

                Event updateEvent = ConvertToEvent(eventVenue, eventName, enteredDate, enteredTicketQuantity, enteredMaxClaims,
                                                   categoryId, datePosted, postStatus, eventDescription, totalHandsRaised, maxWinners, remainingWinners);
                updateEvent.EventId = updateEventId;

                UpdateEventCommand updateCommand = new UpdateEventCommand(updateEvent);
                commandBus.Execute(updateCommand);


                List <String> updateImagePaths = ImagePathCreation();

                foreach (string path in updateImagePaths)
                {
                    InsertPictureCommand eventCommand = new InsertPictureCommand(new Picture(0, path, updateEvent.EventId));
                    commandBus.Execute(eventCommand);
                }

                return(updateEvent);
            }

            Event newEvent = ConvertToEvent(eventVenue, eventName, enteredDate, enteredTicketQuantity, enteredMaxClaims, categoryId,
                                            datePosted, postStatus, eventDescription, totalHandsRaised, maxWinners, remainingWinners);
            InsertEventCommand command = new InsertEventCommand(newEvent);

            commandBus.Execute(command, delegate(Event result) { newEvent = result; });

            List <String> imagePaths = ImagePathCreation();

            foreach (string path in imagePaths)
            {
                InsertPictureCommand eventCommand = new InsertPictureCommand(new Picture(0, path, newEvent.EventId));
                commandBus.Execute(eventCommand);
            }

            return(newEvent);
        }
예제 #28
0
        public async Task <ActionResult> Update([FromBody] UpdateEventCommand updateEventCommand)
        {
            await _mediator.Send(updateEventCommand);

            return(NoContent());
        }
예제 #29
0
        public async Task Handle_Given_All_Valid_Values_Updates_Event()
        {
            // Arrange
            var validId              = 1;
            var validTitle           = "Event Created from Unit Tests.";
            var validDescription     = "This event was created from a Unit Test.";
            var validStartDate       = new DateTime(2020, 3, 1);
            var validEndDate         = new DateTime(2020, 3, 2);
            var validRegStartDate    = new DateTime(2020, 2, 1);
            var validRegEndDate      = new DateTime(2020, 2, 2);
            var validMaxRegs         = 10;
            var validMinRegs         = 1;
            var validMaxStandbyCount = 10;
            var validEventTypeId     = 1;
            var validEventSeriesId   = 1;
            var validStreet          = "123 Anywhere St.";
            var validSuite           = "Room #3";
            var validCity            = "Yourtown";
            var validState           = "MD";
            var validZip             = "12345";
            var command              = new UpdateEventCommand
            {
                Id              = validId,
                Title           = validTitle,
                Description     = validDescription,
                StartDate       = validStartDate,
                EndDate         = validEndDate,
                RegStartDate    = validRegStartDate,
                RegEndDate      = validRegEndDate,
                MaxRegsCount    = validMaxRegs,
                MinRegsCount    = validMinRegs,
                MaxStandbyCount = validMaxStandbyCount,
                EventSeriesId   = validEventSeriesId,
                EventTypeId     = validEventTypeId,
                Street          = validStreet,
                Suite           = validSuite,
                City            = validCity,
                State           = validState,
                Zip             = validZip
            };

            // Act
            var result = await _sut.Handle(command, CancellationToken.None);

            Event e = _context.Events.Find(validId);

            // Assert
            Assert.NotNull(e);
            Assert.Equal(e.Title, validTitle);
            Assert.Equal(e.Description, validDescription);
            Assert.Equal(e.Dates.StartDate, validStartDate);
            Assert.Equal(e.Dates.EndDate, validEndDate);
            Assert.Equal(e.Dates.RegistrationStartDate, validRegStartDate);
            Assert.Equal(e.Dates.RegistrationEndDate, validRegEndDate);
            Assert.Equal((int)e.Rules.MaxRegistrations, validMaxRegs);
            Assert.Equal((int)e.Rules.MinRegistrations, validMinRegs);
            Assert.Equal((int)e.Rules.MaxStandbyRegistrations, validMaxStandbyCount);
            Assert.Equal(e.EventSeriesId, validEventSeriesId);
            Assert.Equal(e.EventTypeId, validEventTypeId);
            Assert.Equal(e.Address.Street, validStreet);
            Assert.Equal(e.Address.Suite, validSuite);
            Assert.Equal(e.Address.City, validCity);
            Assert.Equal(e.Address.State, validState);
            Assert.Equal(e.Address.ZipCode, validZip);
        }
 public async Task <IActionResult> UpdateEvent(int id, UpdateEventCommand command)
 {
     command.Id = id;
     return(await _iMediator.Send(command));
 }