Beispiel #1
0
 /// <summary>
 /// Set CustomerId, ModifiedBy and ModifiedOn properties modified for update/delete
 /// </summary>
 /// <param name="apiContext"></param>
 /// <param name="entity"></param>
 protected static void SetSystemPropertiesModified(Helpers.ApiContext apiContext, Entities.EntityObject entity)
 {
     Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
     System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity);
     ose.SetModifiedProperty("ModifiedBy");
     ose.SetModifiedProperty("ModifiedOn");
     ose.SetModifiedProperty("CustomerId");
 }
Beispiel #2
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public static Helpers.ActionResult UpdateStatus(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.User> users)
        {
            // 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 (users == null)
            {
                throw new System.ArgumentNullException("users");
            }
            if (users.Count() == 0)
            {
                throw new System.ArgumentOutOfRangeException("users");
            }

            // 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;

                foreach (Entities.User user in users)
                {
                    // ATTACH object
                    AttachObject(apiContext, "Users", user);

                    // SET system level properties
                    SetSystemProperties(apiContext, user);
                    SetSystemPropertiesModified(apiContext, user);

                    // SET IsActive property modified
                    System.Data.Objects.ObjectStateEntry ose = apiContext.CurrentContext.ObjectStateManager.GetObjectStateEntry(user);
                    ose.SetModifiedProperty("IsActive");
                }

                context.SaveChanges();                 // Save Changes
                DetachObjects(apiContext, users);      // Clean ObjectState cache
            }
            catch (System.Data.OptimisticConcurrencyException ex)
            {
                object forDebugging = ex;
                //HandleOptimisticConcurrencyException(apiContext, users, ex, ref result);
                //throw Helpers.Exceptions.OptimisticConcurrencyException.Factory(ex);
                throw;
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.UpdateEntityException.Factory(ex);
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// SetDeleted for SoftDelete
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="entity"></param>
        protected static void SetDeleted(Helpers.ApiContext apiContext, Entities.EntityObject entity)
        {
            Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

            // SET IsDeleted = true
            entity.GetType().GetProperty("IsDeleted").SetValue(entity, true, null);

            // SET IsDeleted modified
            System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity);
            ose.SetModifiedProperty("IsDeleted");
        }
Beispiel #4
0
        /// <summary>
        /// SetModified for Update
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="entity"></param>
        protected static void SetModified(Helpers.ApiContext apiContext, Entities.EntityObject entity)
        {
            Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
            System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity);

            System.Data.Metadata.Edm.ItemCollection colleciton = null;
            if (context.MetadataWorkspace.TryGetItemCollection(System.Data.Metadata.Edm.DataSpace.CSpace, out colleciton))
            {
                System.String  typeFullName = entity.GetType().ToString();
                Edm.EntityType entiyType    =
                    colleciton.GetItems <Edm.EntityType>()
                    .Where(e => e.FullName.Equals(typeFullName, System.StringComparison.InvariantCultureIgnoreCase))
                    .First();

                // SET all properties modified except those who are in ignore list
                foreach (Edm.EdmProperty property in entiyType.Properties)
                {
                    if (!IsInIgnoreList(property.Name))
                    {
                        ose.SetModifiedProperty(property.Name);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="imageTypes"></param>
        /// <param name="columnExpression"></param>
        /// <returns></returns>
        public static Helpers.ActionResult PartialUpdate(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.ImageType> imageTypes, params System.Linq.Expressions.Expression <System.Func <Entities.ImageType, object> >[] columnExpression)
        {
            // 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 (imageTypes == null)
            {
                throw new System.ArgumentNullException("imageTypes");
            }
            if (imageTypes.Count() == 0)
            {
                throw new System.ArgumentOutOfRangeException("imageTypes");
            }
            if (columnExpression == null)
            {
                throw new System.ArgumentNullException("columnExpression");
            }
            if (columnExpression.Count() == 0)
            {
                throw new System.ArgumentOutOfRangeException("columnExpression");
            }

            ValidateColumnExpression <Entities.ImageType>(columnExpression);

            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);
            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

                foreach (Entities.ImageType imageType in imageTypes)
                {
                    // ATTACH object
                    AttachObject(apiContext, "ImageTypes", imageType);

                    // SET system level properties
                    SetSystemProperties(apiContext, imageType);
                    SetSystemPropertiesModified(apiContext, imageType);

                    // SET IsActive property modified
                    System.Data.Objects.ObjectStateEntry ose = apiContext.CurrentContext.ObjectStateManager.GetObjectStateEntry(imageType);

                    foreach (var item in columnExpression)
                    {
                        ose.SetModifiedProperty(item.GetPropertyName());
                    }
                }

                context.SaveChanges();                 // Save Changes
                DetachObjects(apiContext, imageTypes); // Clean ObjectState cache
            }
            catch (System.Data.OptimisticConcurrencyException ex)
            {
                object forDebugging = ex;
                HandleOptimisticConcurrencyException(apiContext, imageTypes, ex, ref result);
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.UpdateEntityException.Factory(ex);
            }

            return(result);
        }