Exemplo n.º 1
0
        protected async Task <(ServiceAgreement agreement, EventServiceModel serivce)> SetupServiceAgreementAsync(int eventId, int serviceSlotId, int servicePersonId)
        {
            var serviceSlot = await _Context.ServiceSlots.FirstAsync(x => x.EventId == eventId && x.Id == serviceSlotId);

            var service = new EventServiceModel
            {
                Location = new Location(),
                PersonId = servicePersonId,
                TypeId   = serviceSlot.TypeId
            };

            _Context.EventService.Add(service);
            await _Context.SaveChangesAsync();

            var item = new ServiceAgreement
            {
                EventId             = eventId,
                EventServiceModelId = service.Id,
                ServiceSlotId       = serviceSlotId
            };

            _Context.ServiceAgreements.Add(item);
            await _Context.SaveChangesAsync();

            return(item, service);
        }
Exemplo n.º 2
0
        public async Task PostService_Success_Result()
        {
            var types = await CreateDefaultTypesAsync();

            var setup = await SetupServiceAsync();

            var model = new EventServiceModel
            {
                Id       = -1,
                PersonId = -1,
                Profile  = Guid.NewGuid().ToString(),
                Salary   = 10008,
                TypeId   = types.catererType.Id
            };

            var r = await _Client.PostAsync($"api/service/{setup.firstService.Id}", model.ToStringContent());

            r.EnsureSuccessStatusCode();

            var result = JsonConvert.DeserializeObject <EventServiceModel>(await r.Content.ReadAsStringAsync());

            Assert.NotNull(result);
            Assert.Equal(model.Profile, result.Profile);
            Assert.Equal(model.Salary, result.Salary);
            Assert.Equal(model.TypeId, result.TypeId);
            Assert.Equal(setup.firstService.Id, result.Id);
            Assert.Equal(setup.firstService.PersonId, result.PersonId);
        }
Exemplo n.º 3
0
        public async Task PostService_Success_Database()
        {
            var types = await CreateDefaultTypesAsync();

            var setup = await SetupServiceAsync();

            var model = new EventServiceModel
            {
                Id       = -1,
                PersonId = -1,
                Profile  = Guid.NewGuid().ToString(),
                Salary   = 10008,
                TypeId   = types.catererType.Id
            };

            var r = await _Client.PostAsync($"api/service/{setup.firstService.Id}", model.ToStringContent());

            r.EnsureSuccessStatusCode();

            var result = await CreateDataContext().EventService.FirstOrDefaultAsync(x => x.Id == setup.firstService.Id);

            Assert.NotNull(result);
            Assert.Equal(model.Profile, result.Profile);
            Assert.Equal(model.Salary, result.Salary);
            Assert.Equal(model.TypeId, result.TypeId);
            Assert.Equal(setup.firstService.Id, result.Id);
            Assert.Equal(setup.firstService.PersonId, result.PersonId);
        }
Exemplo n.º 4
0
        public async Task PutService_Created_Success_Result()
        {
            var types = await CreateDefaultTypesAsync();

            var setup = await SetupAuthenticationAsync();

            var model = new EventServiceModel
            {
                Id       = -1,
                PersonId = -1,
                Profile  = Guid.NewGuid().ToString(),
                Salary   = 1000,
                TypeId   = types.djType.Id
            };

            var r = await _Client.PutAsync("api/service", model.ToStringContent());

            Assert.Equal(HttpStatusCode.Created, r.StatusCode);

            var result  = JsonConvert.DeserializeObject <EventServiceModel>(await r.Content.ReadAsStringAsync());
            var dbEntry = await CreateDataContext().EventService.FirstOrDefaultAsync(x => x.Profile == model.Profile);

            Assert.NotNull(dbEntry);
            Assert.Equal(dbEntry.Id, result.Id);

            Assert.NotNull(result);
            Assert.Equal(model.Profile, result.Profile);
            Assert.Equal(model.Salary, result.Salary);
            Assert.Equal(model.TypeId, result.TypeId);
            Assert.Equal(setup.Person.Id, result.PersonId);
        }
 public void ValidateEventServiceModelSalary(EventServiceModel serviceModel)
 {
     if (serviceModel.Salary < 0)
     {
         throw new UnprocessableEntityException("Salary must be greater or equal to 0", Guid.Parse(ServiceErrorCodes.SALARY_MUST_BE_GREATER_OR_EQUAL_ZERO));
     }
 }
Exemplo n.º 6
0
        public async Task Create_WithValidData_ShouldIncludeIntoDatabase()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context             = new ApplicationDbContext(options);
            var eventsService       = new EventsService(context);
            EventServiceModel model = new EventServiceModel
            {
                Name           = "Test Place 1",
                Place          = "somewhere",
                StartDate      = DateTime.UtcNow,
                EndDate        = DateTime.UtcNow,
                TotalTickets   = 5,
                PricePerTicket = 4.8m
            };

            await eventsService.CreateAsync(model);

            // Act
            var count = (eventsService.GetAll()).Count();

            // Assert
            Assert.Equal(1, count);
        }
Exemplo n.º 7
0
        public Task <EventServiceModel> CreateEventServiceModelAsync(EventServiceModel serviceModel)
        {
            _serviceTypeValidator.ValidateTypeExists(serviceModel.TypeId);


            _serviceValidator.ValidateEventServiceModelSalary(serviceModel);
            return(null);
        }
Exemplo n.º 8
0
        public async Task <EventServiceModel> GetByIdAsync(Guid id)
        {
            Event @event = await _uow.GetRepository <Event>()
                           .GetByIdAsync(id);

            EventServiceModel eventServiceModel = _mapper.Map <Event, EventServiceModel>(@event);

            return(eventServiceModel);
        }
        public async Task <EventServiceModel> CreateEventServiceModelAsync(EventServiceModel serviceModel)
        {
            serviceModel.Id       = 0;
            serviceModel.PersonId = (await _personService.GetPersonForUserAsync()).Id;
            _dataContext.EventService.Add(serviceModel);
            await _dataContext.SaveChangesAsync();

            return(serviceModel);
        }
Exemplo n.º 10
0
        public async Task RemoveAsync(EventServiceModel entity)
        {
            Event @event = _mapper
                           .Map <EventServiceModel, Event>(entity);

            _uow.GetRepository <Event>().Remove(@event);

            await _uow.SaveChangesAsync();
        }
        public async Task <EventServiceModel> UpdateEventServiceModelAsync(EventServiceModel serviceModel)
        {
            var dbServiceModel = await _dataContext.EventService.FirstOrDefaultAsync(x => x.Id == serviceModel.Id);

            dbServiceModel.Profile = serviceModel.Profile;
            dbServiceModel.Salary  = serviceModel.Salary;
            dbServiceModel.TypeId  = serviceModel.TypeId;
            await _dataContext.SaveChangesAsync();

            return(dbServiceModel);
        }
Exemplo n.º 12
0
        public async Task RemoveAsync(Guid id)
        {
            Event @event = await _uow.GetRepository <Event>()
                           .GetByIdAsync(id);

            EventServiceModel eventServiceModel = _mapper
                                                  .Map <Event, EventServiceModel>(@event);

            await RemoveAsync(eventServiceModel);

            await _schedulerService.UnscheduleEventById(id);
        }
        public async Task CreateAsync(EventServiceModel model)
        {
            if (!this.IsEntityStateValid(model))
            {
                return;
            }

            var ev = Mapper.Map <Event>(model);

            await this.context.AddAsync(ev);

            await this.context.SaveChangesAsync();
        }
Exemplo n.º 14
0
        public async Task <EventServiceModel> AddAsync(EventCreationServiceModel entity)
        {
            Event @event = _mapper.Map <EventCreationServiceModel, Event>(entity);
            await _uow.GetRepository <Event>().AddAsync(@event);

            await _uow.SaveChangesAsync();

            await _schedulerService.ScheduleEventById(@event.Id);

            EventServiceModel eventServiceModel = _mapper.Map <Event, EventServiceModel>(@event);

            return(eventServiceModel);
        }
Exemplo n.º 15
0
        public async Task RemoveAsync(EventServiceModel entity)
        {
            Event @event = await _uow.GetRepository <DAL.Models.Entities.Event>()
                           .GetFirstOrDefaultAsync(
                predicate: e => e.Id == entity.Id,
                disableTracking: false);

            //Event @event = _mapper
            //    .Map<EventServiceModel, Event>(entity);
            _uow.GetRepository <Event>().Remove(@event);

            await _uow.SaveChangesAsync();
        }
Exemplo n.º 16
0
        public async Task <EventServiceModel> GetByIdAsync(Guid id)
        {
            Event @event = await _uow.GetRepository <Event>()
                           .GetByIdAsync(id);

            //.GetFirstOrDefaultAsync(
            //   predicate: e => e.Id == id,
            //   include: query => query
            //       .Include(e => e.Calendar));
            EventServiceModel eventServiceModel = _mapper.Map <Event, EventServiceModel>(@event);

            return(eventServiceModel);
        }
Exemplo n.º 17
0
        public async Task <ActionResult <EventModel> > GetEvent(Guid eventId, Guid userId)
        {
            UserServiceModel user = await _userService.GetByPrincipalAsync(User);

            if (user == null || user.Id != userId)
            {
                return(Unauthorized());
            }

            EventServiceModel eventServiceModel = await _eventService.GetByIdAsync(eventId);

            EventModel eventModel = _mapper.Map <EventServiceModel, EventModel>(eventServiceModel);

            return(Ok(eventModel));
        }
        public async Task <bool> Create(EventServiceModel eventServiceModel)
        {
            Event eve = new Event()
            {
                Name     = eventServiceModel.Name,
                Start    = eventServiceModel.Start,
                Venue    = eventServiceModel.Venue,
                MoreInfo = eventServiceModel.MoreInfo
            };

            await context.Events.AddAsync(eve);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
Exemplo n.º 19
0
        protected async Task <(User firstUser, EventServiceModel firstService, User secondUser, EventServiceModel secodnService)> SetupServiceAsync()
        {
            var setup = await SetupAuthenticationAsync();

            var secondUser = CreateUser();
            var types      = await CreateDefaultTypesAsync();

            var firstService = new EventServiceModel
            {
                Profile  = Guid.NewGuid().ToString(),
                PersonId = setup.Person.Id,
                Salary   = 2000,
                TypeId   = types.djType.Id,
                Location =
                {
                    Country = Guid.NewGuid().ToString(),
                    State   = Guid.NewGuid().ToString(),
                    Street  = Guid.NewGuid().ToString(),
                    ZipCode = Guid.NewGuid().ToString()
                }
            };


            var secondService = new EventServiceModel
            {
                Profile  = Guid.NewGuid().ToString(),
                Person   = secondUser.Person,
                Salary   = 1000,
                TypeId   = types.catererType.Id,
                Location =
                {
                    Country = Guid.NewGuid().ToString(),
                    State   = Guid.NewGuid().ToString(),
                    Street  = Guid.NewGuid().ToString(),
                    ZipCode = Guid.NewGuid().ToString()
                }
            };


            _Context.Users.Add(secondUser);
            _Context.EventService.Add(firstService);
            _Context.EventService.Add(secondService);
            await _Context.SaveChangesAsync();

            return(setup, firstService, secondUser, secondService);
        }
Exemplo n.º 20
0
        public async Task GetServiceProvider_Success()
        {
            var types = await CreateDefaultTypesAsync();

            var setup = await SetupAuthenticationAsync();

            var service1 = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.RealPersonId.Value,
                TypeId   = types.djType.Id,
                Profile  = Guid.NewGuid().ToString()
            };

            var service2 = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.RealPersonId.Value,
                TypeId   = types.djType.Id,
                Profile  = Guid.NewGuid().ToString()
            };

            var service3 = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.RealPersonId.Value,
                TypeId   = types.catererType.Id,
                Profile  = Guid.NewGuid().ToString()
            };

            _Context.EventService.AddRange(service1, service2, service3);
            await _Context.SaveChangesAsync();

            var r = await _Client.GetAsync($"api/serviceTypes/{types.djType.Id}/serviceProvider");

            r.EnsureSuccessStatusCode();

            var result = JsonConvert.DeserializeObject <List <EventServiceModel> >(await r.Content.ReadAsStringAsync());

            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
            Assert.True(result.Any(x => x.Profile == service1.Profile));
            Assert.True(result.Any(x => x.Profile == service2.Profile));
        }
        public async Task Create_WithCorrectData_ShouldSuccesfullyCreate()
        {
            string errorMessagePrefix = "EventsService Method CreateEvent() does not work properly.";

            var context = CDGBulgariaInmemoryFactory.InitializeContext();

            this.eventsService = new EventsService(context);

            EventServiceModel eve = new EventServiceModel()
            {
                Name     = "CDGHealthMeeting",
                Venue    = "Sofia",
                Start    = DateTime.ParseExact("05/03/2019 14:00", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture),
                MoreInfo = "src/pics/something/sofia.pdf"
            };

            bool actualResult = await this.eventsService.Create(eve);

            Assert.True(actualResult, errorMessagePrefix);
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Create(EventCreateInputModel eventCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(eventCreateInputModel));
            }

            string fileUrl = await this.cloudinaryService.UploadFile(eventCreateInputModel.MoreInfo, eventCreateInputModel.Name);

            EventServiceModel eventServiceModel = new EventServiceModel()
            {
                Name     = eventCreateInputModel.Name,
                Start    = eventCreateInputModel.Start,
                Venue    = eventCreateInputModel.Venue,
                MoreInfo = fileUrl
            };

            await this.eventsService.Create(eventServiceModel);

            return(this.Redirect("/"));
        }
Exemplo n.º 23
0
        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 PutAgreement_Forbidden()
        {
            var setup = await SetupEventServiceSlotsAsync();

            var service = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.secondUser.RealPersonId.Value,
                TypeId   = setup.firstSlot.TypeId
            };

            _Context.EventService.Add(service);
            await _Context.SaveChangesAsync();


            var r = await _Client.PutAsync($"api/event/{setup.secondEvent.Id}/sps/{setup.secondSlot.Id}/request/{service.Id}", "".ToStringContent());

            Assert.Equal(HttpStatusCode.Forbidden, r.StatusCode);
            var error = JsonConvert.DeserializeObject <ExceptionDTO>(await r.Content.ReadAsStringAsync());

            Assert.Equal(Guid.Parse(EventErrorCodes.NO_UPDATE_PERMISSIONS), error.ErrorCode);
        }
        public async Task PutAgreement_Success_Host()
        {
            var setup = await SetupEventServiceSlotsAsync();

            var service = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.secondUser.RealPersonId.Value,
                TypeId   = setup.firstSlot.TypeId
            };

            _Context.EventService.Add(service);
            await _Context.SaveChangesAsync();

            var r = await _Client.PutAsync($"api/event/{setup.firstEvent.Id}/sps/{setup.firstSlot.Id}/request/{service.Id}", "".ToStringContent());

            r.EnsureSuccessStatusCode();

            var result = JsonConvert.DeserializeObject <ServiceAgreement>(await r.Content.ReadAsStringAsync());

            Assert.NotNull(result);
            Assert.Equal(ServiceAgreementStates.Request, result.State);
        }
Exemplo n.º 26
0
 public virtual Task <EventServiceModel> UpdateService(int serviceId, [FromBody] EventServiceModel serviceModel)
 {
     serviceModel.Id = serviceId;
     return(_eventServiceModelService.UpdateEventServiceModelAsync(serviceModel));
 }
Exemplo n.º 27
0
 public virtual Task <EventServiceModel> CreateEventService([FromBody] EventServiceModel serviceModel)
 {
     HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;
     return(_eventServiceModelService.CreateEventServiceModelAsync(serviceModel));
 }
        public async Task GetAgreements_Success()
        {
            var setup = await SetupServiceAsync();

            var myEvent = new Event
            {
                HostId   = setup.secondUser.RealPersonId.Value,
                Location = new Location()
            };

            _Context.Events.Add(myEvent);
            await _Context.SaveChangesAsync();

            var slot = new ServiceSlot
            {
                EventId = myEvent.Id,
                TypeId  = setup.firstService.TypeId
            };

            var badSlot = new ServiceSlot
            {
                EventId = myEvent.Id,
                TypeId  = setup.secodnService.TypeId
            };

            var otherSlot = new ServiceSlot
            {
                EventId = myEvent.Id,
                TypeId  = setup.secodnService.Id
            };

            _Context.ServiceSlots.AddRange(slot, badSlot, otherSlot);
            await _Context.SaveChangesAsync();

            var otherService = new EventServiceModel
            {
                Location = new Location(),
                PersonId = setup.firstService.PersonId,
                TypeId   = setup.secodnService.TypeId
            };

            _Context.EventService.Add(otherService);

            var firstAgreement = new ServiceAgreement
            {
                EventId             = myEvent.Id,
                EventServiceModelId = setup.firstService.Id,
                ServiceSlotId       = slot.Id,
                Comment             = Guid.NewGuid().ToString()
            };

            var badAgreement = new ServiceAgreement
            {
                EventId             = myEvent.Id,
                EventServiceModelId = setup.secodnService.Id,
                ServiceSlotId       = badSlot.Id,
                Comment             = Guid.NewGuid().ToString()
            };

            var otherAgreement = new ServiceAgreement
            {
                EventId             = myEvent.Id,
                EventServiceModelId = otherService.Id,
                ServiceSlotId       = otherSlot.Id,
                Comment             = Guid.NewGuid().ToString()
            };

            _Context.ServiceAgreements.AddRange(firstAgreement, badAgreement, otherAgreement);
            await _Context.SaveChangesAsync();

            var r = await _Client.GetAsync("api/service/my/agreements");

            r.EnsureSuccessStatusCode();

            var result = JsonConvert.DeserializeObject <List <ServiceAgreement> >(await r.Content.ReadAsStringAsync());

            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
            Assert.True(result.Any(x => x.Comment == otherAgreement.Comment));
            Assert.True(result.Any(x => x.Comment == firstAgreement.Comment));
            Assert.False(result.Any(x => x.Comment == badAgreement.Comment));
        }