Пример #1
0
        public ActionResult AI_New(AIModel newAI)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/ActiveIngredients";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT>(newAI.AI), ParameterType.RequestBody);
                ACTIVE_INGREDIENT createdAI = serviceCaller.Execute<ACTIVE_INGREDIENT>(request);

                //if Products were chosen, add to PRODUCT_ACTIVE_INGREDIENT
                if (newAI.AIProdsToAdd != null)
                {
                    if (newAI.AIProdsToAdd.Length >= 1)
                    {
                        string[] prods = Regex.Split(newAI.AIProdsToAdd, ",");
                        List<PRODUCT> productList = new List<PRODUCT>();

                        foreach (string pr in prods)
                        {
                            if (!string.IsNullOrWhiteSpace(pr))
                            {
                                request = new RestRequest(Method.POST);
                                request.Resource = "/Products/{entityID}/AddProductToAI";
                                request.AddParameter("entityID", Convert.ToDecimal(pr), ParameterType.UrlSegment);
                                request.RequestFormat = DataFormat.Xml;
                                request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                                request.AddBody(createdAI);
                                serviceCaller.Execute<PRODUCT_ACTIVE_INGREDIENT>(request);
                            }
                        }
                    }
                }
                //if AIClasses were chosen, add to ACTIVE_INGREDIENT_AI_CLASS
                if (newAI.AIClassesToAdd != null)
                {
                    if (newAI.AIClassesToAdd.Length >= 1)
                    {
                        string[] AIclasses = Regex.Split(newAI.AIClassesToAdd, ",");
                        List<AI_CLASS> aiClList = new List<AI_CLASS>();

                        foreach (string aic in AIclasses)
                        {
                            if (!string.IsNullOrWhiteSpace(aic))
                            {
                                //now post it
                                request = new RestRequest(Method.POST);
                                request.Resource = "/AIClasses/{entityID}/AddAIClass";
                                request.AddParameter("entityID", Convert.ToDecimal(aic), ParameterType.UrlSegment);
                                request.RequestFormat = DataFormat.Xml;
                                request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                                request.AddBody(createdAI);
                                ACTIVE_INGREDIENT_AI_CLASS newAIcAI = serviceCaller.Execute<ACTIVE_INGREDIENT_AI_CLASS>(request);
                            }
                        }
                    }
                }
                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
Пример #2
0
        public ActionResult AI_Edit(int id, AIModel updatedAIModel)
        {
            ACTIVE_INGREDIENT thisAI = updatedAIModel.AI;
            string AIClasses2Add = updatedAIModel.AIClassesToAdd;
            string AIClasses2Remove = updatedAIModel.AIClassesIDsToRemove;

            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest();
            //see if any products have been related or any removed from relationship
            //if prodsToRemove != null -> expire those
            if (!string.IsNullOrWhiteSpace(AIClasses2Remove))
            {
                //parse entityIDs
                string[] RemoveAIC = Regex.Split(AIClasses2Remove, ",");
                foreach (string p in RemoveAIC)
                {
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        if (thisAI != null)
                        {
                            //send request to expire it
                            request = new RestRequest(Method.POST);
                            request.Resource = "/AIClasses/{entityID}/RemoveAIClassFromAI?activeIngredientID={aiEntityID}";
                            request.AddParameter("entityID", Convert.ToDecimal(p), ParameterType.UrlSegment);
                            request.AddParameter("aiEntityID", Convert.ToDecimal(thisAI.ACTIVE_INGREDIENT_ID), ParameterType.UrlSegment);
                            request.AddHeader("X-HTTP-Method-Override", "DELETE");
                            request.AddHeader("Content-Type", "application/xml");
                            serviceCaller.Execute<AI_CLASS>(request);
                        }
                    }
                }
            }
            // if prodsToAdd != null -> post those (there's a check to see if they already exist)
            if (!string.IsNullOrWhiteSpace(AIClasses2Add))
            {
                //parse
                string[] AddAIC = Regex.Split(AIClasses2Add, ",").ToArray();
                foreach (string a in AddAIC)
                {
                    if (!string.IsNullOrWhiteSpace(a))
                    {
                        if (thisAI != null)
                        {
                            request = new RestRequest(Method.POST);
                            request.Resource = "/AIClasses/{entityID}/AddAIClass";
                            request.AddParameter("entityID", Convert.ToDecimal(a), ParameterType.UrlSegment);
                            request.RequestFormat = DataFormat.Xml;
                            request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                            request.AddBody(thisAI);
                            ACTIVE_INGREDIENT_AI_CLASS newAIC = serviceCaller.Execute<ACTIVE_INGREDIENT_AI_CLASS>(request);
                        }
                    }
                }
            }

            request = new RestRequest(Method.POST);
            request.Resource = "/ActiveIngredients/{entityID}";
            request.RequestFormat = DataFormat.Xml;
            request.AddParameter("entityID", id, ParameterType.UrlSegment);
            request.AddHeader("X-HTTP-Method-Override", "PUT");
            //Use extended serializer
            BLTWebSerializer serializer = new BLTWebSerializer();
            request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT>(thisAI), ParameterType.RequestBody);
            ACTIVE_INGREDIENT updatedAI = serviceCaller.Execute<ACTIVE_INGREDIENT>(request);

            //update the AI and go back to the AI index
            return RedirectToAction("Index");
        }
Пример #3
0
        //want to edit the Product - AI relationship
        public ActionResult PAIEdit(int id)
        {
            //get the logged in user's role
            ViewData["Role"] = GetLoggedInMember();

            ACTIVE_INGREDIENT thisAI = GetAnAI(id);

            //get the AI Class
            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest();
            request.Resource = "/ActiveIngredients/{activeIngredientID}/AIClass?publishedDate={date}";
            request.RootElement = "ArrayOfAI_CLASS";
            request.AddParameter("activeIngredientID", thisAI.ACTIVE_INGREDIENT_ID, ParameterType.UrlSegment);
            List<AI_CLASS> AIClasses = serviceCaller.Execute<List<AI_CLASS>>(request);

            if (AIClasses != null)
                ViewData["AIClasses"] = AIClasses.OrderBy(a => a.AI_CLASS_NAME).ToList();

            //get the Products linked to this AI by ID
            serviceCaller = BLTServiceCaller.Instance;
            request = new RestRequest();
            request.Resource = "/ActiveIngredients/{activeIngredientID}/Product?publishedDate={date}";
            request.RootElement = "ArrayOfPRODUCT";
            request.AddParameter("activeIngredientID", thisAI.ACTIVE_INGREDIENT_ID, ParameterType.UrlSegment);
            List<PRODUCT> AIProducts = serviceCaller.Execute<List<PRODUCT>>(request);
            ViewData["AIProducts"] = AIProducts;

            //Populate model for view
            AIModel thisAIModel = new AIModel();

            //the AI
            thisAIModel.AI = thisAI;

            //the product IDs for hidden input to maintain
            string prID = string.Empty;
            string trimmedprID = string.Empty;
            if (AIProducts.Count >= 1)
            {
                foreach (PRODUCT pr in AIProducts)
                {
                    prID += pr.PRODUCT_ID + ",";
                }
                trimmedprID = prID.TrimEnd(',', ' ');
            }
            thisAIModel.AIProdsToAdd = trimmedprID;

            return View("ProductAI/PAIEdit", thisAIModel);
        }
Пример #4
0
        public ActionResult PAI_Edit(AIModel updatedAIModel)
        {
            ACTIVE_INGREDIENT thisAI = updatedAIModel.AI;

            string Products2Add = updatedAIModel.AIProdsToAdd;
            string Products2Remove = updatedAIModel.ProductIDsToRemove;

            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest();

            //see if any products have been related or any removed from relationship
            //if prodsToRemove != null -> expire those
            if (!string.IsNullOrWhiteSpace(Products2Remove))
            {
                //parse
                string[] RemovePAI = Regex.Split(Products2Remove, ",");
                foreach (string p in RemovePAI)
                {
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        if (thisAI != null)
                        {
                            //send request to expire it
                            request = new RestRequest(Method.POST);
                            request.Resource = "/Products/{entityID}/RemoveProductFromAI?activeIngredientID={aiEntityID}";
                            request.AddParameter("entityID", Convert.ToDecimal(p), ParameterType.UrlSegment);
                            request.AddParameter("aiEntityID", Convert.ToDecimal(thisAI.ACTIVE_INGREDIENT_ID), ParameterType.UrlSegment);
                            request.AddHeader("X-HTTP-Method-Override", "DELETE");
                            request.AddHeader("Content-Type", "application/xml");
                            serviceCaller.Execute<PRODUCT>(request);
                        }
                    }
                }
            }
            // if prodsToAdd != null -> post those (there's a check to see if they already exist)
            if (!string.IsNullOrWhiteSpace(Products2Add))
            {
                //parse
                string[] AddPAI = Regex.Split(Products2Add, ",").ToArray();
                foreach (string a in AddPAI)
                {
                    if (!string.IsNullOrWhiteSpace(a))
                    {
                        if (thisAI != null)
                        {
                            request = new RestRequest(Method.POST);
                            request.Resource = "/Products/{entityID}/AddProductToAI";
                            request.AddParameter("entityID", Convert.ToDecimal(a), ParameterType.UrlSegment);
                            request.RequestFormat = DataFormat.Xml;
                            request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                            request.AddBody(thisAI);
                            serviceCaller.Execute<PRODUCT_ACTIVE_INGREDIENT>(request);
                        }
                    }
                }
            }

            return RedirectToAction("../Parts/Index");
        }
Пример #5
0
        //edit page
        public ActionResult AIEdit(int id)
        {
            //get the logged in user's role
            ViewData["Role"] = GetLoggedInMember();
            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;

            //get this AI based on it's ID

            ACTIVE_INGREDIENT thisAI = GetAnAI(id);

            //get all the AI classes for dropdown
            var request = new RestRequest();
            request.Resource = "/AIClasses?publishedDate={date}";
            request.RootElement = "ArrayOfAI_CLASS";
            List<AI_CLASS> AIClassList = serviceCaller.Execute<List<AI_CLASS>>(request);
            ViewData["AIClassList"] = AIClassList;

            //get the AI's AI_Classes
            request = new RestRequest();
            request.Resource = "/ActiveIngredients/{activeIngredientID}/AIClass?publishedDate={date}";
            request.RootElement = "ArrayOfAI_CLASS";
            request.AddParameter("activeIngredientID", thisAI.ACTIVE_INGREDIENT_ID, ParameterType.UrlSegment);
            List<AI_CLASS> AIClasses = serviceCaller.Execute<List<AI_CLASS>>(request);

            //Populate model for view
            AIModel thisAIModel = new AIModel();

            //the AI
            thisAIModel.AI = thisAI;

            if (AIClasses != null)
            {
                ViewData["AIClasses"] = AIClasses.OrderBy(a => a.AI_CLASS_NAME).ToList();
                //the AIClass IDs for hidden input to maintain
                string aicID = string.Empty;
                string trimmedAicID = string.Empty;
                if (AIClasses.Count >= 1)
                {//store each entityID (so the correct version can be gotten)
                    foreach (AI_CLASS aic in AIClasses)
                    {
                        aicID += aic.ID + ",";
                    }
                    trimmedAicID = aicID.TrimEnd(',', ' ');
                }
                thisAIModel.AIClassesToAdd = trimmedAicID;
            }

            //get the Products linked to this AI by ID
            serviceCaller = BLTServiceCaller.Instance;
            request = new RestRequest();
            request.Resource = "/ActiveIngredients/{activeIngredientID}/Product?publishedDate={date}";
            request.RootElement = "ArrayOfPRODUCT";
            request.AddParameter("activeIngredientID", thisAI.ACTIVE_INGREDIENT_ID, ParameterType.UrlSegment);
            List<PRODUCT> AIProducts = serviceCaller.Execute<List<PRODUCT>>(request);
            ViewData["AIProducts"] = AIProducts;

            return View("AI/AIEdit", thisAIModel);
        }