Ejemplo n.º 1
0
        public ActionResult TcEditTechnology(TCTechnology tcTechnology, int[] tagIds, int[] techDomainIds)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/TechCompany/EditTechnology.cshtml", tcTechnology));
            }

            if (tagIds == null || tagIds.Length < 3)
            {
                ViewBag.Message = "Required minimum 3 tags";
                return(TcEditTechnology(tcTechnology.TCid));
            }

            if (techDomainIds == null || techDomainIds.Length == 0 || techDomainIds.Length > 3)
            {
                ViewBag.Message = "Required minimum 1 tech domain and maximum of 3";
                return(TcEditTechnology(tcTechnology.TCid));
            }

            if (!string.IsNullOrWhiteSpace(tcTechnology.AdditionalTechTags))
            {
                var additionalTagList = tcTechnology.AdditionalTechTags.Split(',').Select(t => t.Trim()).ToList();
                tcTechnology.AdditionalTechTags = string.Join(",", additionalTagList);
            }

            _techCompanyService.UpdateTcTechnology(tcTechnology, tagIds, techDomainIds);

            return(RedirectToAction("TcEditTechnology"));
        }
Ejemplo n.º 2
0
        public void UpdateTcTechnology(TCTechnology tcTechnology, int[] tagIds, int[] techDomainIds)
        {
            using (var db = new InnosixEntities())
            {
                var tcTagIds = db.TechTagToTC.Where(t => t.TCid == tcTechnology.TCid);
                db.TechTagToTC.RemoveRange(tcTagIds);
                foreach (var tagId in tagIds)
                {
                    db.TechTagToTC.Add(new TechTagToTC {
                        TCid = tcTechnology.TCid, TechTagId = tagId
                    });
                }

                var tcTechDomains = db.TechDomainToTC.Where(t => t.TCid == tcTechnology.TCid);
                db.TechDomainToTC.RemoveRange(tcTechDomains);
                foreach (var techDomainId in techDomainIds)
                {
                    db.TechDomainToTC.Add(new TechDomainToTC {
                        TCid = tcTechnology.TCid, TechDomainId = techDomainId
                    });
                }

                db.TCGeneral.Find(tcTechnology.TCid).LastUpdated = DateTime.Now;

                var tcTechnologyExists = db.TCTechnology.Any(x => x.TCid == tcTechnology.TCid);
                if (tcTechnologyExists)
                {
                    db.Entry(tcTechnology).State = EntityState.Modified;
                }
                else
                {
                    db.TCTechnology.Add(tcTechnology);
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public ActionResult EditTechnology([Bind(Include = "TCid,AdditionalTechTags,Patents,OtherIpNotPatented,TechnologySectorId")] TCTechnology tCTechnology, int[] tagIds, int[] techDomainIds)
        {
            if (!ModelState.IsValid)
            {
                return(View(tCTechnology));
            }

            if (tagIds == null || tagIds.Length < 3)
            {
                ViewBag.Message = "Required minimum 3 tags";
                return(EditTechnology());
            }

            if (techDomainIds == null || techDomainIds.Length == 0 || techDomainIds.Length > 3)
            {
                ViewBag.Message = "Required minimum 1 tech domain and maximum of 3";
                return(EditTechnology());
            }

            if (!string.IsNullOrWhiteSpace(tCTechnology.AdditionalTechTags))
            {
                var additionalTagList = tCTechnology.AdditionalTechTags.Split(',').Select(t => t.Trim()).ToList();
                tCTechnology.AdditionalTechTags = string.Join(",", additionalTagList);
            }

            using (var db = new InnosixEntities())
            {
                var tcTagIds = db.TechTagToTC.Where(t => t.TCid == tCTechnology.TCid);
                db.TechTagToTC.RemoveRange(tcTagIds);
                foreach (var tagId in tagIds)
                {
                    db.TechTagToTC.Add(new TechTagToTC {
                        TCid = tCTechnology.TCid, TechTagId = tagId
                    });
                }

                var tcTechDomains = db.TechDomainToTC.Where(t => t.TCid == tCTechnology.TCid);
                db.TechDomainToTC.RemoveRange(tcTechDomains);
                foreach (var techDomainId in techDomainIds)
                {
                    db.TechDomainToTC.Add(new TechDomainToTC {
                        TCid = tCTechnology.TCid, TechDomainId = techDomainId
                    });
                }

                db.TCGeneral.Find(tCTechnology.TCid).LastUpdated = DateTime.Now;

                var tcTechnologyExists = db.TCTechnology.Any(x => x.TCid == tCTechnology.TCid);
                if (tcTechnologyExists)
                {
                    db.Entry(tCTechnology).State = EntityState.Modified;
                }
                else
                {
                    db.TCTechnology.Add(tCTechnology);
                }

                db.SaveChanges();
            }

            return(RedirectToAction("EditTechnology"));
        }