Esempio n. 1
0
        protected override IServiceRequestPackageDto Create(int performingUserId, IServiceRequestPackageDto entity)
        {
            using (var context = new PrometheusContext())
            {
                var servicePackage = context.ServiceRequestPackages.Find(entity.Id);
                if (servicePackage != null)
                {
                    throw new InvalidOperationException(string.Format("Service Request Package with ID {0} already exists.", entity.Id));
                }
                var savedPackage = context.ServiceRequestPackages.Add(ManualMapper.MapDtoToServiceRequestPackage(entity));

                //Set tags to match DTO tags
                var categoryTags = new List <ServiceOptionCategoryTag>();
                foreach (var tag in entity.ServiceOptionCategoryTags)
                {
                    categoryTags.Add(ManualMapper.MapDtoToServiceOptionCategoryTag(tag));
                }
                savedPackage.ServiceOptionCategoryTags = categoryTags;

                var serviceTags = new List <ServiceTag>();
                foreach (var tag in entity.ServiceTags)
                {
                    serviceTags.Add((ManualMapper.MapDtoToServiceTag(tag)));
                }
                savedPackage.ServiceTags = serviceTags;

                context.SaveChanges(performingUserId);

                return(ManualMapper.MapServiceRequestPackageToDto(savedPackage));
            }
        }