Ejemplo n.º 1
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="receiptImage"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.ReceiptImage receiptImage)
        {
            // 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.ReceiptImages.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)
                {
                    receiptImage = qry;

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

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

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="querySettings"></param>
        /// <param name="imageTypes"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, Helpers.QuerySettings <Entities.ImageType> querySettings, out System.Collections.Generic.List <Entities.ImageType> imageTypes)
        {
            // API doesn't allow null parameters.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (querySettings == null)
            {
                throw new System.ArgumentNullException("querySettings");
            }

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

                // make entities query and set the NoTracking option to stop tracking of entities by entity framework
                System.Data.Objects.ObjectQuery <Entities.ImageType> query = context.ImageTypes;
                query.MergeOption = System.Data.Objects.MergeOption.NoTracking;

                // include entities
                foreach (System.String include in querySettings.IncludedEntities)
                {
                    query = query.Include(include);
                }

                // execute the query with query settings applied
                imageTypes = query
                             .Where(querySettings.GetWhereExpression())
                             .OrderBy(querySettings.SortExpression)
                             .Skip(querySettings.ResultsStartIndex)
                             .Take(querySettings.MaxResultsSize)
                             .ToList();
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.GetEntityException.Factory(ex);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.ImageType imageType, 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 (imageType == 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, imageType);

                context.AddObject("ImageTypes", imageType);

                context.SaveChanges();                 // Save Changes

                id = imageType.Id;

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

            return(result);
        }
Ejemplo n.º 4
0
        protected static int SoftDeleteObjectMappings(Helpers.ApiContext apiContext, Entities.EntityObject entity)
        {
            Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

            System.Guid     id         = (System.Guid)entity.GetType().GetProperty("Id").GetValue(entity, null);
            System.Guid     modifiedBy = (System.Guid)entity.GetType().GetProperty("ModifiedBy").GetValue(entity, null);
            System.DateTime modifiedOn = (System.DateTime)entity.GetType().GetProperty("ModifiedOn").GetValue(entity, null);

            string sqlQuery = string.Format(@"UPDATE    [ObjectMappings] 
                                                SET    
                                                        [IsDeleted]  = 1, 
                                                        [ModifiedBy] = '{0}',
                                                        [ModifiedOn] = '{1}'
                                                WHERE  
                                                        [ParentId]   = @p0", modifiedBy, modifiedOn);

            int recordCount = apiContext.CurrentContext.ExecuteStoreCommand(sqlQuery, id);

            return(recordCount);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        public static bool IsExists(Helpers.ApiContext apiContext, System.Linq.Expressions.Expression <System.Func <Entities.ImageType, bool> > whereClause)
        {
            // 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");
            }

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
                return(context.ImageTypes.Any(whereClause));
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.ExistsException.Factory(ex);
            }
        }
Ejemplo n.º 6
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.ImageType, bool> > whereClause, out Entities.ImageType 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.ImageTypes.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);
            }
        }
Ejemplo n.º 7
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);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// ApplyOriginalValues for Concurrency check in Update and Delete
 /// </summary>
 /// <param name="apiContext"></param>
 /// <param name="entity"></param>
 protected static void ApplyOriginalValues(Helpers.ApiContext apiContext, Entities.EntityObject entity)
 {
     Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
     System.Data.Objects.ObjectStateEntry ose = context.ObjectStateManager.GetObjectStateEntry(entity);
     ose.ApplyOriginalValues(entity);
 }
Ejemplo n.º 9
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="imageTypes"></param>
        /// <returns></returns>
        public static Helpers.ActionResult BulkUpdate(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.ImageType> imageTypes)
        {
            // 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");
            }

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

                OnBulkUpdating(apiContext, imageTypes);

                foreach (Entities.ImageType imageType in imageTypes)
                {
                    OnUpdating(apiContext, imageType, true);

                    // ATTACH object
                    AttachObject(apiContext, "ImageTypes", imageType);

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

                    // PARTIAL update
                    OnPartialUpdate(apiContext, imageType);
                }

                context.SaveChanges();                 // Save Changes
                DetachObjects(apiContext, imageTypes); // Clean ObjectState cache

                foreach (Entities.ImageType imageType in imageTypes)
                {
                    OnUpdated(apiContext, imageType, true);
                }

                OnBulkUpdated(apiContext, imageTypes);
            }
            catch (System.Data.OptimisticConcurrencyException ex)
            {
                object forDebugging = ex;
                HandleOptimisticConcurrencyException(apiContext, imageTypes, ex, ref result);
                //throw Helpers.Exceptions.OptimisticConcurrencyException.Factory(ex);
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.UpdateEntityException.Factory(ex);
            }

            return(result);
        }
Ejemplo n.º 10
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);
        }
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="product_Service_SubCategoriesList"></param>
        /// <param name="clientWins">if true system properties will not be overwritten by Api</param>
        /// <returns></returns>
        public static Helpers.ActionResult Update(Helpers.ApiContext apiContext, System.Collections.Generic.IEnumerable <Entities.Product_Service_SubCategories> product_Service_SubCategoriesList, System.Boolean clientWins)
        {
            // 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 (product_Service_SubCategoriesList == null)
            {
                throw new System.ArgumentNullException("product_Service_SubCategoriesList");
            }
            if (product_Service_SubCategoriesList.Count() == 0)
            {
                throw new System.ArgumentOutOfRangeException("product_Service_SubCategoriesList");
            }

            // 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.Product_Service_SubCategories product_Service_SubCategories in product_Service_SubCategoriesList)
                {
                    OnUpdating(apiContext, product_Service_SubCategories, false);

                    // ATTACH object
                    AttachObject(apiContext, "Product_Service_SubCategories", product_Service_SubCategories);

                    if (!clientWins)
                    {
                        // SET system level properties
                        SetSystemProperties(apiContext, product_Service_SubCategories);
                    }

                    // SET modified
                    SetModified(apiContext, product_Service_SubCategories);
                }

                if (clientWins)
                {
                    context.Refresh(System.Data.Objects.RefreshMode.ClientWins, product_Service_SubCategoriesList);
                }

                context.SaveChanges();                                        // Save Changes
                DetachObjects(apiContext, product_Service_SubCategoriesList); // Clean ObjectState cache

                foreach (Entities.Product_Service_SubCategories product_Service_SubCategories in product_Service_SubCategoriesList)
                {
                    OnUpdated(apiContext, product_Service_SubCategories, false);
                }
            }
            catch (System.Data.OptimisticConcurrencyException ex)
            {
                object forDebugging = ex;
                HandleOptimisticConcurrencyException(apiContext, product_Service_SubCategoriesList, ex, ref result);
                //throw Helpers.Exceptions.OptimisticConcurrencyException.Factory(ex);
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.UpdateEntityException.Factory(ex);
            }

            return(result);
        }