/// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="warrantyCardImage"></param>
        /// <param name="result"></param>
        public static void ValidateData(Helpers.ApiContext apiContext, Entities.WarrantyCardImage warrantyCardImage, ref Helpers.ActionResult result)
        {
            OnValidating(apiContext, warrantyCardImage, ref result);

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


            OnValidated(apiContext, warrantyCardImage, ref result);
        }
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="warrantyCardImage"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.WarrantyCardImage warrantyCardImage)
        {
            // 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.WarrantyCardImages.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)
                {
                    warrantyCardImage = qry;

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

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

            return(result);
        }
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.WarrantyCardImage warrantyCardImage, 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 (warrantyCardImage == 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, warrantyCardImage);

                context.AddObject("WarrantyCardImages", warrantyCardImage);

                context.SaveChanges();                 // Save Changes

                id = warrantyCardImage.Id;

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

            return(result);
        }
        /// <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.WarrantyCardImage, bool> > whereClause, out Entities.WarrantyCardImage 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.WarrantyCardImages.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);
            }
        }
 //	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.WarrantyCardImage warrantyCardImage);
 //	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.WarrantyCardImage warrantyCardImage, ref Helpers.ActionResult result);
 //	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.WarrantyCardImage warrantyCardImage);
 //	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.WarrantyCardImage warrantyCardImage, bool isBulkUpdate);
Ejemplo n.º 9
0
        public bool Insert(ApiContext apiContext,
                           Entities.Products_Services productService,
                           Entities.Receipt receipt,
                           Entities.WarrantyCard warrantyCard,
                           List <Entities.Image> receiptImageList,
                           List <Entities.Image> warranyCardImageList)
        {
            try
            {
                //Save Product Service
                long serviceId = 0;
                var  result    = CoreManagers.ProductsServicesManager.Add(apiContext, productService, out serviceId);

                //Save receipt
                long receiptId = 0;
                result = CoreManagers.ReceiptManager.Add(apiContext, receipt, out receiptId);

                //Save receipt images

                if (receiptImageList.Count > 0)
                {
                    List <Entities.ReceiptImage> receiptImages = new List <Entities.ReceiptImage>();
                    foreach (Entities.Image image in receiptImageList)
                    {
                        Entities.ReceiptImage receiptImage = new Entities.ReceiptImage();

                        receiptImage.ImageId   = image.Id;
                        receiptImage.ReceiptId = receiptId;

                        receiptImages.Add(receiptImage);
                    }

                    result = CoreManagers.ReceiptimageManager.Add(apiContext, receiptImages);
                }

                //Save receipt
                long warrantyCardId = 0;
                result = CoreManagers.WarrantycardManager.Add(apiContext, warrantyCard, out warrantyCardId);

                //Save warranty card images
                if (warranyCardImageList.Count > 0)
                {
                    List <Entities.WarrantyCardImage> warranyCardImages = new List <Entities.WarrantyCardImage>();
                    foreach (Entities.Image image in warranyCardImageList)
                    {
                        Entities.WarrantyCardImage warrantyCardImage = new Entities.WarrantyCardImage();

                        warrantyCardImage.ImageId        = image.Id;
                        warrantyCardImage.WarrantyCardId = warrantyCardId;

                        warranyCardImages.Add(warrantyCardImage);
                    }

                    result = CoreManagers.WarrantycardimageManager.Add(apiContext, warranyCardImages);
                }

                //Save My Product Service
                Entities.My_Products_Services myProdService = new Entities.My_Products_Services();

                myProdService.Product_Service_Id = serviceId;
                myProdService.ReceiptId          = receiptId;
                myProdService.WarrantyCardId     = warrantyCardId;
                myProdService.CreatedOn          = DateTime.Now;

                result = CoreManagers.MyProductsServicesManager.Add(apiContext, new List <Entities.My_Products_Services> {
                    myProdService
                });

                return(result.WasSuccessful);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }