Example #1
0
        public ActionResult DeleteRohstoffConfirmed(Rohstoffe _name, string roh)
        {
            _name.Id = Convert.ToInt32(_name.Name);
            var       p   = from a in _db.Rohstoffes where a.Id == _name.Id select a;
            Rohstoffe asd = p.FirstOrDefault();//_db.Rohstoffes.FirstOrDefault(i => i.Id == _name.Id);

            if (asd != null)
            {
                //Alle Beziehungen mit dem Rohstoff löschen
                var li  = _db.Rohstoffs.Select(s => s).ToList();      //Finde alle Rohstoffe
                var end = _db.EndOfLifeDatas.Select(s => s).ToList(); //EndofLifeData
                var pri = _db.ProduktRohstoffUmweltindikators.Select(s => s).ToList();
                var iw  = _db.Umweltindikatorwerts.Select(s => s).ToList();
                //Rohstoff, EndOfLifeData , ProduktRohstoffIndikator löschen

                //Rohstoff löschen
                for (int i = 0; i < li.Count(); i++)
                {
                    if (li.ElementAt(i).Rohstoff_Id == asd.Id)
                    {
                        //Lösche EndOfLifeData
                        for (int j = 0; j < end.Count(); j++)
                        {
                            if (end.ElementAt(j).Rohstoff_Id == li.ElementAt(i).Rohstoff_Id)
                            {
                                //Lösche ProduktRohstoffIndikator
                                for (int z = 0; z < pri.Count(); z++)
                                {
                                    if (pri.ElementAt(z).Rohstoff_Id == end.ElementAt(j).Rohstoff_Id)
                                    {
                                        _db.ProduktRohstoffUmweltindikators.Remove(pri.ElementAt(z));
                                    }
                                }
                                _db.EndOfLifeDatas.Remove(end.ElementAt(j));
                            }
                        }
                        _db.Rohstoffs.Remove(li.ElementAt(i));
                    }
                }
                for (int i = 0; i < iw.Count(); i++)
                {
                    if (iw.ElementAt(i).Rohstoff_Id == asd.Id)
                    {
                        _db.Entry(iw.ElementAt(i)).State = EntityState.Modified;
                        iw.ElementAt(i).Rohstoff_Id      = null;
                    }
                }
                _db.Rohstoffes.Remove(asd);
            }

            _db.SaveChanges();
            return(RedirectToAction(roh));
        }
Example #2
0
        public ActionResult DeleteRohstoff(Rohstoffe _name, string roh)
        {
            if (_name == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RohstoffViewViewModel sd = new RohstoffViewViewModel();

            _name.Id      = Convert.ToInt32(_name.Name);
            sd._Rohstoffe = _db.Rohstoffes.FirstOrDefault(i => i.Id == _name.Id);
            sd._View      = roh;
            if (sd._Rohstoffe == null)
            {
                return(HttpNotFound());
            }
            return(View(sd));
        }