private void FixupPeriodType1(PeriodType previousValue)
        {
            if (previousValue != null && previousValue.EventsInfoes1.Contains(this))
            {
                previousValue.EventsInfoes1.Remove(this);
            }

            if (PeriodType1 != null)
            {
                if (!PeriodType1.EventsInfoes1.Contains(this))
                {
                    PeriodType1.EventsInfoes1.Add(this);
                }
                if (Reoccurance_PeriodTypeId != PeriodType1.Id)
                {
                    Reoccurance_PeriodTypeId = PeriodType1.Id;
                }
            }
            else if (!_settingFK)
            {
                /* [NOTE] --
                 * I have commented following, as in case of detaching entities from ObjectState it was making EntityId Null into referenced entities,
                 * which is not desired behavior for us.
                 */
                //Reoccurance_PeriodTypeId = null;
            }
        }
Beispiel #2
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="periodType"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.PeriodType periodType)
        {
            // API doesn't allow null parameters.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (id == null)
            {
                throw new System.ArgumentNullException("id");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);
            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
                var qry = context.PeriodTypes.Where(r => r.Id.Equals(id)).FirstOrDefault();

                // See what would be default value in this case
                // Also to see if no value found what shall be put into Action Result
                if (qry != null)
                {
                    periodType = qry;

                    // must detach the object before return
                    DetachObject(apiContext, periodType);
                }
                else
                {
                    periodType    = new Entities.PeriodType();
                    periodType.Id = id;

                    result.WasSuccessful = false;
                    result.Messages.Add(Helpers.ActionResultMessage.Factory(periodType, "Object not Found", Helpers.ActionResultMessageType.Warning));
                }
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.GetEntityException.Factory(ex);
            }

            return(result);
        }
Beispiel #3
0
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.PeriodType periodType, out long id)
        {
            // API doesn't allow null parameters. This method requires at least 1 item in the collection.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (periodType == null)
            {
                throw new System.ArgumentNullException("image");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);

            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

                // ADD to context
                OnAdding(apiContext, periodType);

                context.AddObject("PeriodTypes", periodType);

                context.SaveChanges();                 // Save Changes

                id = periodType.Id;

                DetachObjects(apiContext, new System.Collections.Generic.List <Entities.PeriodType> {
                    periodType
                });                                                                                                                // Clean ObjectState cache
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;                // Helpers.Exceptions.AddEntityException.Factory(ex);
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="periodType"></param>
        /// <param name="result"></param>
        public static void ValidateData(Helpers.ApiContext apiContext, Entities.PeriodType periodType, ref Helpers.ActionResult result)
        {
            OnValidating(apiContext, periodType, ref result);

            if (periodType.Id == null)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(periodType, "Id is required.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            if (!System.String.IsNullOrWhiteSpace(periodType.Title) && periodType.Title.Length > 50)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(periodType, "Title must be 50 characters or less.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(periodType.Title) && !System.Text.RegularExpressions.Regex.IsMatch(periodType.Title, alphaNumeric))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(periodType, "Title contains invalid characters.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            OnValidated(apiContext, periodType, ref result);
        }
Beispiel #5
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="whereClause"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool IsExists(Helpers.ApiContext apiContext, System.Linq.Expressions.Expression <System.Func <Entities.PeriodType, bool> > whereClause, out Entities.PeriodType entity)
        {
            // API doesn't allow null parameters. This method requires at least 1 item in the collection.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (whereClause == null)
            {
                throw new System.ArgumentNullException("whereClause");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);
            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
                var query = context.PeriodTypes.Where(whereClause).FirstOrDefault();

                if (query != null)
                {
                    entity = query;
                    DetachObject(apiContext, entity);     // must detach the object before return
                }
                else
                {
                    entity = null;
                }

                return(query != null);
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.ExistsException.Factory(ex);
            }
        }
Beispiel #6
0
 //	This partial method gives us a way to access an object after it has been purged from the system.
 static partial void OnPurged(Helpers.ApiContext apiContext, Entities.PeriodType periodType);
Beispiel #7
0
 //	This partial method gives us a way to access an object after it has been validated in the system.
 static partial void OnValidated(Helpers.ApiContext apiContext, Entities.PeriodType periodType, ref Helpers.ActionResult result);
Beispiel #8
0
 //	This partial method gives us a way to access an object during it is bulk updated in the system.
 static partial void OnPartialUpdate(Helpers.ApiContext apiContext, Entities.PeriodType periodType);
Beispiel #9
0
 //	This partial method gives us a way to update an object before it is imported into the system.
 static partial void OnImporting(Helpers.ApiContext apiContext, Entities.PeriodType periodType);
Beispiel #10
0
 //	This partial method gives us a way to access an object after it has been updated in the system.
 static partial void OnUpdated(Helpers.ApiContext apiContext, Entities.PeriodType periodType, bool isBulkUpdate);