예제 #1
0
파일: Components.cs 프로젝트: pecen/Reco3
        public ActionResult Edit(int id = 0)
        {
            AgentBase       ABase = new AgentBase();
            DatabaseContext dbx   = ABase.GetContext();
            Reco3Component  job   = dbx.Reco3Components.ToList().Find(x => x.ComponentId == id);

            if (job != null)
            {
                return(View(job));
            }

            return(View());
        }
예제 #2
0
 public ActionResult SaveGeneral(string ImprovementId, string Alias, string Introduction, string SourceComponentId)
 {
     try
     {
         AgentBase       ABase          = new AgentBase();
         DatabaseContext dbx            = ABase.GetContext();
         int             nImprovementId = -1;
         if (ImprovementId.Length > 0)
         {
             nImprovementId = Convert.ToInt32(ImprovementId);
         }
         if (nImprovementId == -1)
         {
             int            nSourceComponentId = Convert.ToInt32(SourceComponentId);
             Reco3Component reco3Component     = dbx.CloneComponent(nSourceComponentId);
             if (reco3Component != null)
             {
                 Reco3Improvement improvement = new Reco3Improvement();
                 improvement.Name           = Alias;
                 improvement.ValidFrom      = DateTime.Parse(Introduction);
                 improvement.Reco3Component = reco3Component;
                 improvement.ComponentId    = reco3Component.ComponentId;
                 dbx.Reco3Improvements.Add(improvement);
                 dbx.SaveChanges();
                 return(Json(new { success = true, message = "Improvement successfully saved." }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             Reco3Improvement improvement = dbx.Reco3Improvements.Include("Reco3Component").Where(x => x.ImprovementId == nImprovementId).FirstOrDefault();
             if (improvement != null)
             {
                 improvement.Name             = Alias;
                 improvement.ValidFrom        = DateTime.Parse(Introduction);
                 dbx.Entry(improvement).State = System.Data.Entity.EntityState.Modified;
                 dbx.SaveChanges();
                 return(Json(new { success = true, message = "Improvement successfully saved." }, JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet));
     }
     return(RedirectToAction("Index"));
 }
예제 #3
0
        public void Insert(ComponentDto data)
        {
            using (var ctx = DbContextManager <Reco3Xml2DbContext> .GetManager(_dbName)) {
                var item = new Reco3Component {
                    ComponentId         = data.ComponentId,
                    PDNumber            = data.PDNumber,
                    DownloadedTimestamp = data.DownloadedTimestamp,
                    Description         = data.Description,
                    PD_Status           = data.PDStatus,
                    Component_Type      = data.ComponentType,
                    XML               = data.Xml,
                    PD_Source         = data.PDSource,
                    SourceComponentId = data.SourceComponentId
                };

                ctx.DbContext.Components.Add(item);
                ctx.DbContext.SaveChanges();
                data.ComponentId = item.ComponentId;
            }
        }
예제 #4
0
파일: Experience.cs 프로젝트: pecen/Reco3
        public List <Reco3Component> Query()
        {
            ComponentResponse response = new ComponentResponse();

            if (_oauthClient == null)
            {
                _oauthClient = new OauthHelper()
                {
                    BaseUrl      = _strBaseUrl,      // "https://api.integration.prod.aws.scania.com/",
                    ClientId     = _strClientId,     // "Iy0BxcywUXU1GdcLHfVnj8e0vvca",
                    ClientSecret = _strClientSecret, // "GhlHbwLkFJrvtf5w64kk0m5syNka",
                    Scope        = _strScope         // "PDComponentInfo_Prod_Full"
                };
            }
            response = CallApiAsync(_strBaseUrl,
                                    _strClientId,
                                    _strClientSecret,
                                    _strScope,
                                    _strUrl,
                                    _oauthClient,
                                    _PDIdentifiers).GetAwaiter().GetResult();
            if (response != null)
            {
                List <Reco3Component> Reco3Components = new List <Reco3Component>();
                foreach (ComponentData ThreeDcomponent in response.ComponentData)
                {
                    Reco3Component reco3Component = new Reco3Component();
                    reco3Component.PDNumber = ThreeDcomponent.PDId.ToString();
                    reco3Component.XML      = Base64ToString(ThreeDcomponent.ComponentInfo);
                    reco3Component.SetComponentTypeFromXml();
                    reco3Component.SetComponentDescriptionFromXml();
                    reco3Component.PD_Status = Reco3_Enums.PDStatus.ctReleased;

                    Reco3Components.Add(reco3Component);
                }

                return(Reco3Components);
            }

            return(null);
        }
예제 #5
0
        public ActionResult SaveCondition(string improvementId, string conditionId, string pdCondition, string conditionPDComponentId, string conditionDate, string tagId, string tagValue)
        {
            try
            {
                AgentBase       ABase            = new AgentBase();
                DatabaseContext dbx              = ABase.GetContext();
                bool            bAddingCondition = true;
                int             nConditionId     = -1;
                if (conditionId.Length > 0)
                {
                    nConditionId = Convert.ToInt32(conditionId);
                }
                if (nConditionId != -1)
                {
                    bAddingCondition = false;
                }

                bool             bPdCondition            = Convert.ToBoolean(pdCondition);
                int              nconditionPDComponentId = -1;
                int              ntagId         = -1;
                int              nImprovementId = Convert.ToInt32(improvementId);
                Reco3Improvement improvement    = dbx.Reco3Improvements.Where(x => x.ImprovementId == nImprovementId).First();
                if (improvement == null)
                {
                    return(Json(new { success = false, message = "Failed to find the improvement for the condition." }, JsonRequestBehavior.AllowGet));
                }
                // Load the existing conditions
                dbx.Entry(improvement).Collection(p => p.Conditions).Load();

                if (bAddingCondition == true)
                {
                    Reco3Condition pCondition = new Reco3Condition();
                    pCondition.ValidFrom = DateTime.Parse(conditionDate);
                    if (bPdCondition == true)
                    {
                        nconditionPDComponentId   = Convert.ToInt32(conditionPDComponentId);
                        pCondition.Condition_Type = Reco3Condition.ConditionType.condtionalComponent;
                        Reco3Component conditionalComponent = dbx.Reco3Components.Where(x => x.ComponentId == nconditionPDComponentId).First();
                        pCondition.ConditionalReco3Component = conditionalComponent;
                    }
                    else
                    {
                        ntagId = Convert.ToInt32(tagId);
                        Reco3Tag tag = dbx.Reco3Tags.Where(x => x.Reco3TagId == ntagId).First();
                        pCondition.Condition_Type            = Reco3Condition.ConditionType.conditionalTag;
                        pCondition.ConditionalReco3Component = null;
                        pCondition.Reco3Tag      = tag;
                        pCondition.Reco3TagId    = tag.Reco3TagId;
                        pCondition.Reco3TagValue = tagValue;
                    }

                    improvement.Conditions.Add(pCondition);
                    dbx.SaveChanges();
                    return(Json(new { success = true, message = "Successfully added condition" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    Reco3Condition pCondition = improvement.Conditions.Where(x => x.Reco3ConditionId == nConditionId).First();
                    pCondition.ValidFrom = DateTime.Parse(conditionDate);
                    if (bPdCondition == true)
                    {
                        pCondition.Condition_Type = Reco3Condition.ConditionType.condtionalComponent;
                        nconditionPDComponentId   = Convert.ToInt32(conditionPDComponentId);
                        Reco3Component conditionalComponent = dbx.Reco3Components.Where(x => x.ComponentId == nconditionPDComponentId).First();
                        pCondition.ConditionalReco3Component = conditionalComponent;
                    }
                    else
                    {
                        ntagId = Convert.ToInt32(tagId);
                        Reco3Tag tag = dbx.Reco3Tags.Where(x => x.Reco3TagId == ntagId).First();
                        pCondition.Condition_Type            = Reco3Condition.ConditionType.conditionalTag;
                        pCondition.ConditionalReco3Component = null;
                        pCondition.Reco3Tag      = tag;
                        pCondition.Reco3TagId    = tag.Reco3TagId;
                        pCondition.Reco3TagValue = tagValue;
                    }
                    dbx.Entry(pCondition).State = System.Data.Entity.EntityState.Modified;
                    dbx.SaveChanges();
                    return(Json(new { success = true, message = "Successfully updated condition" }, JsonRequestBehavior.AllowGet));
                }
                //return Json(new { success = false, message = "Failed to find the improvement for the condition." }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet));
            }
            //return Json(new { success = false, message = "Fatal" }, JsonRequestBehavior.AllowGet);
        }