Example #1
0
        private void FixupProducts_Services(Products_Services previousValue)
        {
            if (previousValue != null && previousValue.My_Products_Services.Contains(this))
            {
                previousValue.My_Products_Services.Remove(this);
            }

            if (Products_Services != null)
            {
                if (!Products_Services.My_Products_Services.Contains(this))
                {
                    Products_Services.My_Products_Services.Add(this);
                }
                if (Product_Service_Id != Products_Services.Id)
                {
                    Product_Service_Id = Products_Services.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.
                 */
                //Product_Service_Id = null;
            }
        }
Example #2
0
        private void SaveReceipts(Models.ProductServiceModel prodServiceModel)
        {
            Entities.Products_Services prodService = new Entities.Products_Services();

            //TODO: Hack: Fix it later. Allow null value in Name field
            prodService.Name = string.IsNullOrEmpty(prodServiceModel.ServiceName) ? string.Empty : prodServiceModel.ServiceName;

            prodService.Description   = prodServiceModel.ServiceDescription;
            prodService.PurchaseDate  = prodServiceModel.ServicePurchaseDate;
            prodService.Tags          = prodServiceModel.ServiceTags;
            prodService.CreatedOn     = DateTime.Now;
            prodService.CategoryId    = 1; //prodServiceModel.ServiceCategoryId;
            prodService.SubCategoryId = 1; //prodServiceModel.ServiceSubCategoryId;

            Entities.Receipt receipt = new Entities.Receipt();

            receipt.Title        = prodServiceModel.ReceiptTitle;
            receipt.SerialNumber = prodServiceModel.ReceiptSerialNumber;
            receipt.Description  = prodServiceModel.ReceiptDescription;
            receipt.ReceiptDate  = prodServiceModel.ReceiptDate;

            List <Entities.Image> receiptImageList = new List <Entities.Image>();

            if (prodServiceModel.ReceiptUploadedFiles != null)
            {
                foreach (Models.Image imageModel in prodServiceModel.ReceiptUploadedFiles)
                {
                    Entities.Image image = imageModel;
                    receiptImageList.Add(image);
                }
            }

            Entities.WarrantyCard warrantyCard = new Entities.WarrantyCard();

            warrantyCard.Description      = prodServiceModel.ReceiptDescription;
            warrantyCard.Title            = prodServiceModel.WarrantyTitle;
            warrantyCard.WarrantyExpireOn = prodServiceModel.WarrantyExpireOn;
            warrantyCard.CardNumber       = prodServiceModel.WarrantyCardNumber;

            List <Entities.Image> warranyCardImageList = new List <Entities.Image>();

            if (prodServiceModel.WarrantyCardUploadedFiles != null)
            {
                foreach (Models.Image imageModel in prodServiceModel.WarrantyCardUploadedFiles)
                {
                    Entities.Image image = imageModel;
                    warranyCardImageList.Add(image);
                }
            }

            Managers.MyProductServiceManager manager = new Managers.MyProductServiceManager();
            manager.Insert(Context.GetContext(), prodService, receipt, warrantyCard, receiptImageList, warranyCardImageList);
        }
Example #3
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="products_Services"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.Products_Services products_Services)
        {
            // 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.Products_Services.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)
                {
                    products_Services = qry;

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

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

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

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

            if (System.String.IsNullOrWhiteSpace(products_Services.Name))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(products_Services, "Name is required.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

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

            OnValidated(apiContext, products_Services, ref result);
        }
Example #5
0
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.Products_Services products_Services, 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 (products_Services == 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, products_Services);

                context.AddObject("Products_Services", products_Services);

                context.SaveChanges();                 // Save Changes

                id = products_Services.Id;

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

            return(result);
        }
Example #6
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;
            }
        }
Example #7
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.Products_Services, bool> > whereClause, out Entities.Products_Services 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.Products_Services.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);
            }
        }
Example #8
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.Products_Services products_Services);
Example #9
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.Products_Services products_Services, ref Helpers.ActionResult result);
Example #10
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.Products_Services products_Services);
Example #11
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.Products_Services products_Services, bool isBulkUpdate);