Ejemplo n.º 1
0
        private void FixupWarrantyCard(WarrantyCard previousValue)
        {
            if (previousValue != null && previousValue.My_Products_Services.Contains(this))
            {
                previousValue.My_Products_Services.Remove(this);
            }

            if (WarrantyCard != null)
            {
                if (!WarrantyCard.My_Products_Services.Contains(this))
                {
                    WarrantyCard.My_Products_Services.Add(this);
                }
                if (WarrantyCardId != WarrantyCard.Id)
                {
                    WarrantyCardId = WarrantyCard.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.
                 */
                //WarrantyCardId = null;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        // POST api/receipt
        public HttpResponseMessage Post(Models.WarrantyCardModel warrantyCardModel)
        {
            try
            {
                Entities.WarrantyCard warrantyCard = warrantyCardModel;

                new Managers.WarrantyCardManager().Insert(Context.GetContext(), warrantyCard);

                return(Request.CreateResponse(HttpStatusCode.OK, "Receipt Added Successfully"));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="warrantyCard"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.WarrantyCard warrantyCard)
        {
            // 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.WarrantyCards.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)
                {
                    warrantyCard = qry;

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

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

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

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

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

            OnValidated(apiContext, warrantyCard, ref result);
        }
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.WarrantyCard warrantyCard, 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 (warrantyCard == 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, warrantyCard);

                context.AddObject("WarrantyCards", warrantyCard);

                context.SaveChanges();                 // Save Changes

                id = warrantyCard.Id;

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

            return(result);
        }
Ejemplo n.º 7
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;
            }
        }
        /// <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.WarrantyCard, bool> > whereClause, out Entities.WarrantyCard 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.WarrantyCards.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.WarrantyCard warrantyCard);
 //	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.WarrantyCard warrantyCard, ref Helpers.ActionResult result);
 //	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.WarrantyCard warrantyCard);
 //	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.WarrantyCard warrantyCard);
 //	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.WarrantyCard warrantyCard, bool isBulkUpdate);