Example #1
0
        protected override IServiceDto Update(int performingUserId, IServiceDto service)
        {
            using (var context = new PrometheusContext())
            {
                if (!context.Services.Any(x => x.Id == service.Id))
                {
                    throw new InvalidOperationException("Service record must exist in order to be updated.");
                }
                var updatedService = ManualMapper.MapDtoToService(service);

                context.Services.Attach(updatedService);
                context.Entry(updatedService).State = EntityState.Modified;
                context.SaveChanges(performingUserId);
                return(ManualMapper.MapServiceToDto(updatedService));
            }
        }
Example #2
0
 protected override IServiceDto Create(int performingUserId, IServiceDto service)
 {
     using (var context = new PrometheusContext())
     {
         var existingService = context.Services.Find(service.Id);
         if (existingService == null)
         {
             var savedService = context.Services.Add(ManualMapper.MapDtoToService(service));
             context.SaveChanges(performingUserId);
             return(ManualMapper.MapServiceToDto(savedService));
         }
         else
         {
             throw new InvalidOperationException(string.Format("Service with ID {0} already exists.", service.Id));
         }
     }
 }
        /// <summary>
        /// Makes a fake Service in the DB and returns its ID.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="lifecycleStatusId">Lifecycle status to link to</param>
        /// <param name="bundleId">Service Bundle to link to</param>
        /// <returns></returns>
        private int CreateFakeService(string name, int lifecycleStatusId, int?bundleId = null)
        {
            var fakeService = A.Fake <IServiceDto>();

            A.CallTo(() => fakeService.Name).Returns(name);
            A.CallTo(() => fakeService.LifecycleStatusId).Returns(lifecycleStatusId);
            A.CallTo(() => fakeService.ServiceBundleId).Returns(bundleId);

            using (var context = new PrometheusContext())
            {
                var service = ManualMapper.MapDtoToService(fakeService);
                context.Services.Add(service);
                context.SaveChanges();

                return(service.Id);
            }
        }