/// <summary> Retrieves the related entity of type 'OfferingEntity', using a relation of type 'n:1'</summary>
 /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
 /// <returns>A fetched entity of type 'OfferingEntity' which is related to this entity.</returns>
 public virtual OfferingEntity GetSingleOffering(bool forceFetch)
 {
     if ((!_alreadyFetchedOffering || forceFetch || _alwaysFetchOffering) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode)
     {
         bool           performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.OfferingEntityUsingOfferingId);
         OfferingEntity newEntity          = new OfferingEntity();
         bool           fetchResult        = false;
         if (performLazyLoading)
         {
             AddToTransactionIfNecessary(newEntity);
             fetchResult = newEntity.FetchUsingPK(this.OfferingId);
         }
         if (fetchResult)
         {
             newEntity = (OfferingEntity)GetFromActiveContext(newEntity);
         }
         else
         {
             if (!_offeringReturnsNewIfNotFound)
             {
                 RemoveFromTransactionIfNecessary(newEntity);
                 newEntity = null;
             }
         }
         this.Offering           = newEntity;
         _alreadyFetchedOffering = fetchResult;
     }
     return(_offering);
 }
Example #2
0
        protected override async Task Handle(AddOfferingCommand request, CancellationToken cancellationToken)
        {
            var productId       = request.ProductKey.DecodeKeyToId();
            var isProductActive = await _context.Products
                                  .AnyAsync(p => p.ProductId == productId &&
                                            p.EffectiveStartDate <= request.OrderStartDate &&
                                            p.EffectiveEndDate > request.OrderStartDate);

            if (!isProductActive)
            {
                throw new ValidationException($"No active product found for Product Key '{request.ProductKey}' and Order Effective date of '{request.OrderStartDate}'");
            }

            var offering = new OfferingEntity
            {
                EffectiveStartDate   = request.OrderStartDate ?? DateTime.UtcNow,
                EffectiveEndDate     = DateTime.MaxValue,
                ProductId            = request.ProductKey.DecodeKeyToId(),
                OfferingFormatCode   = request.OfferingFormatCode,
                OfferingPlatformCode = request.OfferingPlatformCode,
                OfferingStatusCode   = request.OfferingStatusCode,
                OfferingEdition      = request.OfferingEdition,
                AddedBy    = "ProductAuthority",
                AddedOnUtc = DateTime.UtcNow
            };

            await _context.Offerings.AddAsync(offering);

            await _context.SaveChangesAndPublishEventsAsync(request.CommandEvents);
        }
        /// <summary>Creates a new, empty OfferingEntity object.</summary>
        /// <returns>A new, empty OfferingEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new OfferingEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewOffering
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
 /// <summary> setups the sync logic for member _offering</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncOffering(IEntityCore relatedEntity)
 {
     if (_offering != relatedEntity)
     {
         DesetupSyncOffering(true, true);
         _offering = (OfferingEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity(_offering, new PropertyChangedEventHandler(OnOfferingPropertyChanged), "Offering", KSI.RelationClasses.StaticClassRegistrationRelations.OfferingEntityUsingOfferingIdStatic, true, ref _alreadyFetchedOffering, new string[] {  });
     }
 }
 public static bool DeleteOffering(int offeringId, out string error)
 {
     error = null;
     try
     {
         var toDelete = new OfferingEntity(offeringId);
         return(toDelete.Delete());
     }
     catch (Exception ex)
     {
         error = "<h3>Oops...Something went wrong! Item can not be deleted!</h3> <b>Reason:</b>" + ex.Message;
         return(false);
     }
 }
 /// <summary>Private CTor for deserialization</summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected OfferingScheduleEntity(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     _offering = (OfferingEntity)info.GetValue("_offering", typeof(OfferingEntity));
     if (_offering != null)
     {
         _offering.AfterSave += new EventHandler(OnEntityAfterSave);
     }
     _offeringReturnsNewIfNotFound = info.GetBoolean("_offeringReturnsNewIfNotFound");
     _alwaysFetchOffering          = info.GetBoolean("_alwaysFetchOffering");
     _alreadyFetchedOffering       = info.GetBoolean("_alreadyFetchedOffering");
     this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
     // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
     // __LLBLGENPRO_USER_CODE_REGION_END
 }
        public static bool UpdateOffering(int offeringId, int offeringsemester, int offeringcourse, int instructor1, int instructor2, int capacity, string room, out string error)
        {
            error = String.Empty;

            var offering = new OfferingEntity(offeringId)
            {
                Id            = offeringId,
                SemesterId    = offeringsemester,
                CourseId      = offeringcourse,
                InstructorId  = instructor1,
                Instructor2Id = instructor2,
                Capacity      = capacity,
                RoomNumber    = room
            };

            return(offering.Save());
        }
Example #8
0
        protected override async Task Handle(UpdateOfferingCommand request, CancellationToken cancellationToken)
        {
            var      offeringId = request.OfferingKey.DecodeKeyToId();
            long     productId;
            DateTime offeringEffectiveEndDate;

            var offering = await _context.Offerings
                           .FirstOrDefaultAsync(o => o.OfferingId == offeringId &&
                                                o.EffectiveStartDate <= request.ChangeEffectiveDate &&
                                                o.EffectiveEndDate > request.ChangeEffectiveDate);

            if (offering != null)
            {
                offeringEffectiveEndDate = offering.EffectiveEndDate;
                productId = offering.ProductId;

                offering.EffectiveEndDate = request.ChangeEffectiveDate;
                offering.UpdatedBy        = "ProductAuthority";
                offering.UpdatedOnUtc     = DateTime.UtcNow;

                _context.Update(offering);
            }
            else
            {
                throw new ValidationException($"No offering found for Offering Key '{request.OfferingKey}' and Change Effective date of '{request.ChangeEffectiveDate}'");
            }

            var newOffering = new OfferingEntity
            {
                OfferingId           = offeringId,
                EffectiveStartDate   = request.ChangeEffectiveDate,
                EffectiveEndDate     = offeringEffectiveEndDate,
                OfferingKey          = request.OfferingKey,
                ProductId            = productId,
                OfferingFormatCode   = request.OfferingFormatCode,
                OfferingPlatformCode = request.OfferingPlatformCode,
                OfferingStatusCode   = request.OfferingStatusCode,
                OfferingEdition      = request.OfferingEdition,
                AddedBy    = "ProductAuthority",
                AddedOnUtc = DateTime.UtcNow,
            };

            await _context.AddAsync(newOffering);

            await _context.SaveChangesAsync();
        }
Example #9
0
        public static OfferingEntity GetOffering(int offeringId)
        {
            var toReturn = new OfferingEntity(offeringId);

            return(toReturn.IsNew ? null : toReturn);
        }
 /// <summary> Removes the sync logic for member _offering</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncOffering(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity(_offering, new PropertyChangedEventHandler(OnOfferingPropertyChanged), "Offering", KSI.RelationClasses.StaticClassRegistrationRelations.OfferingEntityUsingOfferingIdStatic, true, signalRelatedEntity, "ClassRegistrations", resetFKFields, new int[] { (int)ClassRegistrationFieldIndex.OfferingId });
     _offering = null;
 }