public void ValidateCanUpdate(ServiceAgreement agreement)
 {
     if (!IsProviderForAgreement(agreement.EventId, agreement.ServiceSlotId))
     {
         throw new ForbiddenException("User doesnt have permission to update Agreement", Guid.Parse(ServiceAgreementErrorCodes.NO_UPDATE_PERMISSIONS));
     }
 }
Esempio n. 2
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);
        }
 public void ValidateStartBeforeEnd(ServiceAgreement agreement)
 {
     if (agreement.End < agreement.Start)
     {
         throw new UnprocessableEntityException("Start must be before end", Guid.Parse(ServiceAgreementErrorCodes.AGREEMENT_START_BEFORE_END));
     }
 }
Esempio n. 4
0
 public Customer(Car car)
 {
     MyCar    = car;
     Name     = NamesList[Rand.Next(0, NamesList.Count)];
     LastName = LastNamesList[Rand.Next(0, NamesList.Count)];
     SetCheckCarTimer();
     MyAgreement = new ServiceAgreement(Name);
 }
        public Task <ServiceAgreement> UpdateServiceAgreement(ServiceAgreement agreement)
        {
            _eventValidator.ValidateEventExists(agreement.EventId);
            _serviceSlotValidator.ValidateServiceProviderSlotExists(agreement.EventId, agreement.ServiceSlotId);
            _agreementValidator.ValidateAgreementExists(agreement.EventId, agreement.ServiceSlotId);

            _agreementValidator.ValidateCanUpdate(agreement);
            _agreementValidator.ValidateCanUpdateValues(agreement.EventId, agreement.ServiceSlotId);
            _agreementValidator.ValidateStartBeforeEnd(agreement);

            return(null);
        }
Esempio n. 6
0
        internal static ServiceAgreement FromPRO_ConvenioSeleccPaciOSC_ResultToServiceAgreement(PRO_ConvenioSeleccPaciOSC_Result result)
        {
            var output = new ServiceAgreement
            {
                Name             = result.NomConvenio,
                Code             = result.CodConvenio,
                EstadoAfiliacion = result.EstadoAfiliacion,
                Nivel            = result.Nivel,
                Copago           = result.Copago
            };

            return(output);
        }
Esempio n. 7
0
        public async Task <ServiceAgreement> UpdateServiceAgreement(ServiceAgreement agreement)
        {
            var oldAgreement = await _dataContext.ServiceAgreements.FirstAsync(x => x.EventId == agreement.EventId && x.ServiceSlotId == agreement.ServiceSlotId);

            oldAgreement.Comment = agreement.Comment;
            oldAgreement.Cost    = agreement.Cost;
            oldAgreement.Start   = agreement.Start;
            oldAgreement.End     = agreement.End;

            await _dataContext.SaveChangesAsync();

            return(oldAgreement);
        }
        public async Task PostAgreement_Success()
        {
            var setup = await SetupEventServiceSlotsAsync();

            var agreementService = await SetupServiceAgreementAsync(setup.secondEvent.Id, setup.secondSlot.Id, setup.firstUser.RealPersonId.Value);

            agreementService.agreement.State = ServiceAgreementStates.Request;
            await _Context.SaveChangesAsync();

            var serviceAgreement = new ServiceAgreement
            {
                Comment = Guid.NewGuid().ToString(),
                Cost    = 199292,
                Start   = DateTime.UtcNow,
                End     = DateTime.UtcNow.AddDays(1),
                State   = ServiceAgreementStates.Declined
            };

            var r = await _Client.PostAsync($"api/event/{setup.secondEvent.Id}/sps/{setup.secondSlot.Id}/agreement", serviceAgreement.ToStringContent());

            r.EnsureSuccessStatusCode();

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

            Assert.NotNull(result);
            Assert.Equal(serviceAgreement.Comment, result.Comment);
            Assert.Equal(serviceAgreement.Cost, result.Cost);
            Assert.Equal(serviceAgreement.Start, result.Start);
            Assert.Equal(serviceAgreement.End, result.End);
            Assert.Equal(ServiceAgreementStates.Request, result.State);

            result = await _Context.ServiceAgreements.FirstOrDefaultAsync(x => x.EventId == setup.secondEvent.Id &&
                                                                          x.EventServiceModelId == agreementService.serivce.Id &&
                                                                          x.ServiceSlotId == setup.secondSlot.Id);

            await _Context.Entry(result).ReloadAsync();

            Assert.NotNull(result);
            Assert.Equal(serviceAgreement.Comment, result.Comment);
            Assert.Equal(serviceAgreement.Cost, result.Cost);
            // Removed from test since time formats and database saves etc create differences of a couple nano secs or so....
            //Assert.Equal(serviceAgreement.Start, result.Start.ToUniversalTime());
            //Assert.Equal(serviceAgreement.End, result.End.ToUniversalTime());
            Assert.Equal(ServiceAgreementStates.Request, result.State);
        }
Esempio n. 9
0
        public async Task <ServiceAgreement> CreateServiceAgreement(int eventId, int spsId, int serviceId)
        {
            var eventObj = await _dataContext.Events.FirstAsync(x => x.Id == eventId);

            var slot = await _dataContext.ServiceSlots.FirstAsync(x => x.EventId == eventId && x.Id == spsId);


            var agreement = new ServiceAgreement
            {
                EventId             = eventId,
                End                 = slot.End ?? eventObj.End,
                Start               = slot.Start ?? eventObj.Start,
                EventServiceModelId = serviceId,
                ServiceSlotId       = spsId,
                State               = ServiceAgreementStates.Request
            };

            _dataContext.ServiceAgreements.Add(agreement);
            await _dataContext.SaveChangesAsync();

            return(agreement);
        }
        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));
        }
Esempio n. 11
0
 public static void GetServiceRequesters(ServiceAgreement selectedAgreement, AsyncTaskCompletedEventHandler resultadoOperacion)
 {
     new AsyncTask(selectedAgreement, GetServiceRequestersAction, resultadoOperacion);
 }
Esempio n. 12
0
 public static void GetServiceProviders(ServiceAgreement agreement, AsyncTaskCompletedEventHandler resultadoOperacion)
 {
     new AsyncTask(agreement, GetServiceProvidersAction, resultadoOperacion);
 }
Esempio n. 13
0
 public virtual Task <ServiceAgreement> UpdateServiceAgreement(int eventId, int spsId, [FromBody] ServiceAgreement agreement)
 {
     agreement.EventId       = eventId;
     agreement.ServiceSlotId = spsId;
     return(_agreementService.UpdateServiceAgreement(agreement));
 }