Ejemplo n.º 1
0
        public ActionResult Edit(FormCollection cartelamodel)
        {
            if (ModelState.IsValid)
            {
                cartela s;
                long id = long.Parse(cartelamodel["id"]);
                string tipcartela = cartelamodel["tipcartela"];
                long parentEchip = long.Parse(cartelamodel["parentE"]);
                if (id == -1)
                {
                    s = new cartela();
                    s.tipID = (from tc in db.tip_cartela where tc.denumire == tipcartela select tc.id).FirstOrDefault();
                    s.echipamentID = parentEchip;
                    db.AddTocartelas(s);
                    db.SaveChanges();

                    switch (tipcartela)
                    {
                        case "ESU":
                        case "ASU":
                        case "IPLU":
                        case "NIU":
                        case "AAU2":
                        case "ELU32":
                        case "Management alimentare":
                            {
                                atribut a = new atribut();
                                a.val_string = cartelamodel["bpos"];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                cartela_atribute ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["ip"];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["mask"];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "MASK" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["gateway"];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "GATEWAY" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();
                                break;
                            }
                        default:
                            {
                                atribut a = new atribut();
                                a.val_string = cartelamodel["bpos"];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                cartela_atribute ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();
                                break;
                            }
                    }

                    db.SaveChanges();

                }
                else
                {
                    s = db.cartelas.Where(o => o.id == id).FirstOrDefault();
                    int i = 0;
                    foreach (var key in cartelamodel.Keys)
                    {
                        if (key.ToString() != "val_nou" && key.ToString() != "tip_nou" && key.ToString() != "tipcartela" && key.ToString() != "denumire" && key.ToString() != "parentE" && key.ToString() != "ip" && key.ToString() != "id" && key.ToString() != "mask" && key.ToString() != "gateway" && key.ToString() != "bpos" && !key.ToString().EndsWith(":"))
                        {
                            string idechip_idatr = key.ToString();
                            long idechip = long.Parse(idechip_idatr.Split('_')[0]);
                            long idatr = long.Parse(idechip_idatr.Split('_')[1]);

                            atribut a = db.atributs.Where(o => o.id == idatr).FirstOrDefault();

                            string valoare = cartelamodel[i];
                            switch (cartelamodel[key.ToString() + ":"])
                            {
                                case "S": a.val_string = cartelamodel[key.ToString()];
                                    break;
                                case "I": a.val_int = int.Parse(cartelamodel[key.ToString()]);
                                    break;
                                case "N": a.val_nr = decimal.Parse(cartelamodel[key.ToString()]);
                                    break;
                                case "CSV": a.val_csv = cartelamodel[key.ToString()];
                                    break;
                                default: a.val_string = cartelamodel[key.ToString()].ToString();
                                    break;
                            }
                            db.SaveChanges();
                        }
                        else if (key.ToString() == "mask" || key.ToString() == "ip" || key.ToString() == "bpos" || key.ToString() == "gateway" )
                        {
                            atribut a = new atribut();
                            string tip_nou = key.ToString().ToUpper();// cartelamodel[key.ToString()];
                            var taid = (from ta in db.tip_atribut where ta.denumire == tip_nou select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            switch (taid.tip_valoare)
                            {
                                case "S":
                                    a.val_string = cartelamodel[key.ToString()];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                case "I":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    a.val_int = int.Parse(cartelamodel[key.ToString()].ToString());
                                    a.val_nr = null;
                                    break;
                                case "N":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = decimal.Parse(cartelamodel[key.ToString()].ToString());
                                    break;
                                case "CSV":
                                    a.val_string = null;
                                    a.val_csv = cartelamodel[key.ToString()];
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                default:
                                    a.val_string = cartelamodel[key.ToString()];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                            }

                            cartela_atribute ea = new cartela_atribute();
                            ea.atributID = a.id;
                            ea.cartelaID = id;

                            db.AddToatributs(a);
                            db.AddTocartela_atribute(ea);
                            db.SaveChanges();
                        }
                        else if (key.ToString() == "tip_nou")
                        {
                            atribut a = new atribut();
                            string tip_nou = cartelamodel["tip_nou"];
                            var taid = (from ta in db.tip_atribut where ta.denumire == tip_nou select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            switch (taid.tip_valoare)
                            {
                                case "S":
                                    a.val_string = cartelamodel["val_nou"];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                case "I":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    a.val_int = int.Parse(cartelamodel["val_nou"].ToString());
                                    a.val_nr = null;
                                    break;
                                case "N":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = decimal.Parse(cartelamodel["val_nou"].ToString());
                                    break;
                                case "CSV":
                                    a.val_string = null;
                                    a.val_csv = cartelamodel["val_nou"];
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                default:
                                    a.val_string = cartelamodel["val_nou"];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                            }

                            cartela_atribute ea = new cartela_atribute();
                            ea.atributID = a.id;
                            ea.cartelaID = id;

                            db.AddToatributs(a);
                            db.AddTocartela_atribute(ea);
                            db.SaveChanges();
                        }
                    }
                }

                string namejudet = (from j in db.judetes join s1 in db.sites on j.id equals s1.judetID
                                    join e in db.echipaments on s1.id equals e.siteID
                                    join c in db.cartelas on e.id equals c.echipamentID
                                    where c.id == s.id select j.denumire).FirstOrDefault();

                return RedirectToAction("Index", "Judete", new { name = namejudet, id = s.id.ToString() + "_cartela" });
            }
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 2
0
        public ActionResult Salvare(FormCollection cartelamodel)
        {
            string userName = HttpContext.User.Identity.Name;
            int userID = int.Parse((from c in db.contacts where c.username == userName select c.id).FirstOrDefault().ToString());

            long echipamentID = long.Parse(cartelamodel["id"].ToString());
            if (ModelState.IsValid)
            {
                int randuri = int.Parse(cartelamodel["randuri"].ToString());
                for (int i = 3; i <= randuri; i++)
                {
                    string id = cartelamodel["id_"+i.ToString()];
                    long idcartela = long.Parse(id);
                    if (idcartela == -1)
                    {
                        string tipcartela = cartelamodel["tip_cartela_"+i.ToString()];
                        cartela s = new cartela();
                        s.tipID = (from tc in db.tip_cartela where tc.denumire == tipcartela select tc.id).FirstOrDefault();
                        s.echipamentID = long.Parse(cartelamodel["id"].ToString());
                        s.createDate = DateTime.Now;
                        s.editDate = null;
                        s.editContactID = null;
                        s.createcontactID = userID;
                        s.disabled = 0;
                        db.AddTocartelas(s);
                        db.SaveChanges();

                         switch (tipcartela)
                    {
                        case "ESU":
                        case "ASU":
                        case "IPLU":
                        case "NIU":
                        case "AAU2":
                        case "ELU32":
                        case "Management alimentare":
                            {
                                atribut a = new atribut();
                                a.val_string = cartelamodel["bpos_"+i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                cartela_atribute ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);
                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["ip_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["mask_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "MASK" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["gateway_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "GATEWAY" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["switch_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Port switch" select ta.id).FirstOrDefault();
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                if (tipcartela == "IPLU")// || tipcartela == "ELU32")
                                {
                                    a = new atribut();
                                    a.val_string = cartelamodel["utilizare_" + i.ToString()];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Utilizare" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea = new cartela_atribute();
                                    ea.cartelaID = s.id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddTocartela_atribute(ea);

                                    db.SaveChanges();
                                }
                                break;
                            }
                        case "TLU76":
                            {
                                atribut a = new atribut();
                                a.val_string = cartelamodel["bpos_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                cartela_atribute ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["remote_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Remote" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = "/" + cartelamodel["vernou"+i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "VersiuneC" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = cartelamodel["nrruta_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();
                                break;
                            }
                        default:
                            {
                                atribut a = new atribut();
                                a.val_string = cartelamodel["bpos_" + i.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                cartela_atribute ea = new cartela_atribute();
                                ea.cartelaID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddTocartela_atribute(ea);

                                db.SaveChanges();
                                break;
                            }
                    }

                         db.SaveChanges();

                    }
                    else
                    {

                        foreach (var key in cartelamodel.Keys)
                        {
                            if (!key.ToString().StartsWith("utilizare") && !key.ToString().StartsWith("remote") && !key.ToString().StartsWith("ver") && !key.ToString().StartsWith("versiune") && !key.ToString().StartsWith("switch_") && !key.ToString().StartsWith("gateway_") && !key.ToString().StartsWith("mask_") && !key.ToString().StartsWith("ip_") && !key.ToString().StartsWith("bpos_") && !key.ToString().StartsWith("id_") && !key.ToString().StartsWith("nrruta_") && !key.ToString().StartsWith("tip_") && key.ToString() != "val_nou" && key.ToString() != "randuri" && key.ToString() != "tip_nou" && key.ToString() != "tipcartela" && key.ToString() != "denumire" && key.ToString() != "parentE" && key.ToString() != "ip" && key.ToString() != "id" && key.ToString() != "mask" && key.ToString() != "gateway" && key.ToString() != "bpos" && !key.ToString().EndsWith(":")) //&& !key.ToString().StartsWith("1")
                            {

                                string idechip_idatr = key.ToString();
                                long idechip = long.Parse(idechip_idatr.Split('_')[0]);
                                long idatr = long.Parse(idechip_idatr.Split('_')[1]);
                                if (idechip == idcartela)
                                {
                                    atribut a = db.atributs.Where(o => o.id == idatr).FirstOrDefault();
                                    string den_tip_atr = (from ta in db.tip_atribut where ta.id == a.tipID select ta.tip_valoare).FirstOrDefault();
                                    //string valoare = cartelamodel[i];
                                    switch (den_tip_atr)
                                    {
                                        case "S": a.val_string =  cartelamodel[key.ToString()];
                                            break;
                                        case "I": a.val_int = int.Parse(cartelamodel[key.ToString()]);
                                            break;
                                        case "N": a.val_nr = decimal.Parse(cartelamodel[key.ToString()]);
                                            break;
                                        case "CSV": a.val_csv = cartelamodel[key.ToString()];
                                            break;
                                        default: a.val_string = cartelamodel[key.ToString()].ToString();
                                            break;
                                    }
                                    a.editDate = DateTime.Now;
                                    a.editContactID = userID;
                                    db.SaveChanges();
                                }
                            }
                            else if (key.ToString().StartsWith("ver") && !key.ToString().StartsWith("versiune") && !key.ToString().StartsWith("vernou"))
                            {
                                string nr = key.ToString().Substring(3);
                                string idechip_idatr = cartelamodel["versiune"+nr].ToString();
                                long idechip = long.Parse(idechip_idatr.Split('_')[0]);
                                long idatr = long.Parse(idechip_idatr.Split('_')[1]);
                                if (idechip == idcartela)
                                {
                                    atribut a = db.atributs.Where(o => o.id == idatr).FirstOrDefault();
                                    string den_tip_atr = (from ta in db.tip_atribut where ta.id == a.tipID select ta.tip_valoare).FirstOrDefault();
                                    string atr = (from ta in db.tip_atribut where ta.id == a.tipID select ta.denumire).FirstOrDefault();
                                    a.val_string = atr == "VersiuneC" ? "/" + cartelamodel[key.ToString()] : cartelamodel[key.ToString()];
                                    a.editContactID = userID;
                                    a.editDate = DateTime.Now;
                                    db.SaveChanges();
                                }
                            }
                            else if (key.ToString().StartsWith("tip_") && !key.ToString().StartsWith("tip_cartela"))
                            {
                                int tipnr = int.Parse(key.ToString().Split('_')[1]);
                                if (int.Parse(cartelamodel["id_" + tipnr.ToString()].ToString()) == idcartela)
                                {
                                    cartela s = (from c in db.cartelas where c.id == idcartela select c).FirstOrDefault();
                                    string tipcartela = cartelamodel[key.ToString()];
                                    s.tipID = (from tc in db.tip_cartela where tc.denumire == tipcartela select tc.id).FirstOrDefault();
                                    s.editContactID = userID;
                                    s.editDate = DateTime.Now;
                                    db.SaveChanges();
                                }
                            }
                            /*else
                                if (key.ToString().StartsWith("bpos_"))
                                {

                                    int row = int.Parse(key.ToString().Split('_')[1]);
                                    atribut a = new atribut();
                                    a.val_string = cartelamodel["bpos_" + row];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                    db.AddToatributs(a);

                                    cartela_atribute ea = new cartela_atribute();
                                    ea.cartelaID = idcartela;
                                    ea.atributID = a.id;
                                    db.AddTocartela_atribute(ea);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = cartelamodel["ip_" + row];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP" select ta.id).FirstOrDefault();
                                    db.AddToatributs(a);

                                    ea = new cartela_atribute();
                                    ea.cartelaID = idcartela;
                                    ea.atributID = a.id;
                                    db.AddTocartela_atribute(ea);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = cartelamodel["mask_" + row];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "MASK" select ta.id).FirstOrDefault();
                                    db.AddToatributs(a);

                                    ea = new cartela_atribute();
                                    ea.cartelaID = idcartela;
                                    ea.atributID = a.id;
                                    db.AddTocartela_atribute(ea);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = cartelamodel["gateway_" + row];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "GATEWAY" select ta.id).FirstOrDefault();
                                    db.AddToatributs(a);

                                    ea = new cartela_atribute();
                                    ea.cartelaID = idcartela;
                                    ea.atributID = a.id;
                                    db.AddTocartela_atribute(ea);

                                    db.SaveChanges();
                                }
                             * */
                        }
                    }
                }
            }
            string namejudet = (from j in db.judetes
                                join s1 in db.sites on j.id equals s1.judetID
                                join e in db.echipaments on s1.id equals e.siteID
                                where e.id == echipamentID
                                select j.denumire).FirstOrDefault();
            return RedirectToAction("Index", "Judete", new { name = namejudet, id = echipamentID.ToString() + "_cartele" });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the atributs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToatributs(atribut atribut)
 {
     base.AddObject("atributs", atribut);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a new atribut object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="tipID">Initial value of the tipID property.</param>
 public static atribut Createatribut(global::System.Int64 id, global::System.Int64 tipID)
 {
     atribut atribut = new atribut();
     atribut.id = id;
     atribut.tipID = tipID;
     return atribut;
 }
Ejemplo n.º 5
0
        public ActionResult Edit(FormCollection echipmodel)
        {
            int userID = int.Parse((from c in db.contacts where c.username == User.Identity.Name select c.id).FirstOrDefault().ToString());
            if (ModelState.IsValid)
            {
                echipament s;
                long id = long.Parse(echipmodel["id"]);
                string tipechip = echipmodel["numeechip"];
                if (id == -1)
                {
                    if (tipechip == "PABX")
                    {
                        s = new echipament();
                        s.denumire = echipmodel["denumire"].ToString();

                        int val_int;
                        long val_long;
                        int x = 0;
                        if(int.TryParse(echipmodel["tipechipament"].ToString(), out x) == true)
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString());
                        else
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString().Split('_')[0]);

                        s.siteID = long.Parse(echipmodel["siteID"].ToString()); /// ???
                        s.createDate = DateTime.Now;
                        s.editDate = null;
                        s.editcontactID = null;
                        s.createContactID = userID;
                        s.disabled = 0;
                        db.AddToechipaments(s);

                        atribut a = new atribut();
                        a.val_string = null;
                        a.val_csv = null;
                        if( int.TryParse(echipmodel["tip_val"] , out val_int))
                            a.val_int = int.Parse(echipmodel["tip_val"]) ;
                        else
                            a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Tip" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        echipament_atribute ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = null;
                        a.val_csv = null;
                        if (int.TryParse(echipmodel["ver_val"], out val_int))
                            a.val_int = int.Parse(echipmodel["ver_val"]);
                        else
                            a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Versiune" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);
                        db.SaveChanges();

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();
                        ////
                        a = new atribut();
                        a.val_string = echipmodel["ip_val"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();
                        ///
                        int idtip = int.Parse(echipmodel["tip_val"].ToString());
                        string tip_den = ( from a1 in db.atributs join ea1 in db.echipament_atribute on a1.id equals ea1.atributID join
                                            e1 in db.echipaments on ea1.echipamentID equals e1.id join at1 in db.tip_atribut on a1.tipID equals at1.id
                                            join et1 in db.echipament_tip on  a1.val_int equals et1.id
                                           where at1.denumire == "Tip" && et1.id == idtip
                                            select et1.denumire).FirstOrDefault();

                        a = new atribut();
                        a.val_string = (tip_den == "MD" || tip_den == "MX-ONE") ? echipmodel["licenta1"].ToString() + echipmodel["licenta2"].ToString() : echipmodel["licenta1"].ToString();
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Licenta" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);
                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();
                        ////
                        string contract = echipmodel["contract"].ToString();
                        if(echipmodel["contract"].ToString()=="Altul")
                            contract = echipmodel["contract-text"].ToString();

                        a = new atribut();
                        a.val_string = contract;
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Contract" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);
                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();
                        ///

                        a = new atribut();
                        a.val_string = null;
                        a.val_csv = echipmodel["ab_total_dela"].ToString() + "," + echipmodel["ab_total_panala"].ToString();
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Abonati total" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();

                        foreach(var k1 in echipmodel.Keys)
                        {
                            if (k1.ToString().StartsWith("abonati_dela") && !k1.ToString().EndsWith(":"))
                            {
                                string nraux = k1.ToString().Substring(12);
                                a = new atribut();
                                a.val_string = null;
                                a.val_csv = echipmodel[k1.ToString()].ToString() + "," + echipmodel["abonati_panala"+nraux].ToString();
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Abonati" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new echipament_atribute();
                                ea.echipamentID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddToechipament_atribute(ea);
                                db.SaveChanges();
                            }
                        }

                        a = new atribut();
                        a.val_string = echipmodel["nrruta"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["tipconexiune"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Tip Conexiune" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                       // if (echipmodel["tipconexiune"] == "ISDN-PUBLIC" || echipmodel["tipconexiune"] == "ISDN-QSIG")
                        {
                            a = new atribut();
                            a.val_string = echipmodel["destinatie"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Destinatie" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);

                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = echipmodel["pozitie"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Poz. echip." select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);

                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = echipmodel["tiptransport"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Tip echip." select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);

                            db.SaveChanges();
                        }
                        if (echipmodel["tipconexiune"] == "ISDN-PUBLIC" || echipmodel["tipconexiune"] == "ISDN-QSIG")
                        {

                            cartela s1 = new cartela();
                            s1.tipID = (from tc in db.tip_cartela where tc.denumire == "TLU76" select tc.id).FirstOrDefault();
                            s1.echipamentID = s.id;
                            s1.createDate = DateTime.Now;
                            s1.editDate = null;
                            s1.editContactID = null;
                            s1.createcontactID = userID;
                            s1.disabled = 0;
                            db.AddTocartelas(s1);
                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = echipmodel["pozitie"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            cartela_atribute ea1 = new cartela_atribute();
                            ea1.cartelaID = s1.id;
                            ea1.atributID = a.id;
                            ea1.createDate = DateTime.Now;
                            ea1.editDate = null;
                            ea1.editContactID = null;
                            ea1.createContactID = userID;
                            ea1.disabled = 0;
                            db.AddTocartela_atribute(ea1);

                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = echipmodel["destinatie"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Remote" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea1 = new cartela_atribute();
                            ea1.cartelaID = s1.id;
                            ea1.atributID = a.id;
                            ea1.createDate = DateTime.Now;
                            ea1.editDate = null;
                            ea1.editContactID = null;
                            ea1.createContactID = userID;
                            ea1.disabled = 0;
                            db.AddTocartela_atribute(ea1);

                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = "/1";
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "VersiuneC" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea1 = new cartela_atribute();
                            ea1.cartelaID = s1.id;
                            ea1.atributID = a.id;
                            ea1.createDate = DateTime.Now;
                            ea1.editDate = null;
                            ea1.editContactID = null;
                            ea1.createContactID = userID;
                            ea1.disabled = 0;
                            db.AddTocartela_atribute(ea1);

                            db.SaveChanges();

                            a = new atribut();
                            a.val_string = echipmodel["nrruta"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea1 = new cartela_atribute();
                            ea1.cartelaID = s1.id;
                            ea1.atributID = a.id;
                            ea1.createDate = DateTime.Now;
                            ea1.editDate = null;
                            ea1.editContactID = null;
                            ea1.createContactID = userID;
                            ea1.disabled = 0;
                            db.AddTocartela_atribute(ea1);

                            db.SaveChanges();
                        }

                        foreach (string key in echipmodel.Keys)
                        {
                            if (key.StartsWith("nrrutanou") && !key.EndsWith(":"))
                            {
                                a = new atribut();
                                a.val_string = echipmodel[key];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new echipament_atribute();
                                ea.echipamentID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddToechipament_atribute(ea);
                                db.SaveChanges();
                            }
                            else if (key.StartsWith("tipcnou") && !key.EndsWith(":"))
                            {
                                a = new atribut();
                                a.val_string = echipmodel[key];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Tip Conexiune" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new echipament_atribute();
                                ea.echipamentID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddToechipament_atribute(ea);

                                db.SaveChanges();

                                if (echipmodel[key] == "ISDN-PUBLIC" || echipmodel[key] == "ISDN-QSIG")
                                {
                                    string nraux = key.ToString().Substring(7);
                                    cartela s1 = new cartela();
                                    s1.tipID = (from tc in db.tip_cartela where tc.denumire == "TLU76" select tc.id).FirstOrDefault();
                                    s1.echipamentID = s.id;
                                    s1.createDate = DateTime.Now;
                                    s1.editDate = null;
                                    s1.editContactID = null;
                                    s1.createcontactID = userID;
                                    s1.disabled = 0;
                                    db.AddTocartelas(s1);
                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = echipmodel["pozitienou" + nraux];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    cartela_atribute ea1 = new cartela_atribute();
                                    ea1.cartelaID = s1.id;
                                    ea1.atributID = a.id;
                                    ea1.createDate = DateTime.Now;
                                    ea1.editDate = null;
                                    ea1.editContactID = null;
                                    ea1.createContactID = userID;
                                    ea1.disabled = 0;
                                    db.AddTocartela_atribute(ea1);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = echipmodel["destinatienou" + nraux];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Remote" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea1 = new cartela_atribute();
                                    ea1.cartelaID = s1.id;
                                    ea1.atributID = a.id;
                                    ea1.createDate = DateTime.Now;
                                    ea1.editDate = null;
                                    ea1.editContactID = null;
                                    ea1.createContactID = userID;
                                    ea1.disabled = 0;
                                    db.AddTocartela_atribute(ea1);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = "/1";
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "VersiuneC" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea1 = new cartela_atribute();
                                    ea1.cartelaID = s1.id;
                                    ea1.atributID = a.id;
                                    ea1.createDate = DateTime.Now;
                                    ea1.editDate = null;
                                    ea1.editContactID = null;
                                    ea1.createContactID = userID;
                                    ea1.disabled = 0;
                                    db.AddTocartela_atribute(ea1);

                                    db.SaveChanges();

                                    a = new atribut();
                                    a.val_string = echipmodel["nrrutanou" + nraux];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea1 = new cartela_atribute();
                                    ea1.cartelaID = s1.id;
                                    ea1.atributID = a.id;
                                    ea1.createDate = DateTime.Now;
                                    ea1.editDate = null;
                                    ea1.editContactID = null;
                                    ea1.createContactID = userID;
                                    ea1.disabled = 0;
                                    db.AddTocartela_atribute(ea1);

                                    db.SaveChanges();
                                }
                            }
                            else if (key.StartsWith("destinatienou") && !key.EndsWith(":"))
                            {
                                //string nraux = key.ToString().Substring(13);
                              //  if (echipmodel["tipcnou" + nraux] == "ISDN-PUBLIC" || echipmodel["tipcnou" + nraux] == "ISDN-QSIG")
                                {
                                    a = new atribut();
                                    a.val_string = echipmodel[key];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Destinatie" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea = new echipament_atribute();
                                    ea.echipamentID = s.id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddToechipament_atribute(ea);

                                    db.SaveChanges();
                                }
                            }
                            else if (key.StartsWith("pozitienou") && !key.EndsWith(":"))
                            {
                                //string nraux = key.ToString().Substring(10);
                              //  if (echipmodel["tipcnou" + nraux] == "ISDN-PUBLIC" || echipmodel["tipcnou" + nraux] == "ISDN-QSIG")
                                {
                                    a = new atribut();
                                    a.val_string = echipmodel[key];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Poz. echip." select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea = new echipament_atribute();
                                    ea.echipamentID = s.id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddToechipament_atribute(ea);

                                    db.SaveChanges();
                                }
                            }
                            else if (key.StartsWith("tiptransportnou") && !key.EndsWith(":"))
                            {
                               // string nraux = key.ToString().Substring(15);
                               // if (echipmodel["tipcnou" + nraux] == "ISDN-PUBLIC" || echipmodel["tipcnou" + nraux] == "ISDN-QSIG")
                                {
                                    a = new atribut();
                                    a.val_string = echipmodel[key];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Tip echip." select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea = new echipament_atribute();
                                    ea.echipamentID = s.id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddToechipament_atribute(ea);

                                    db.SaveChanges();
                                }
                            }
                        }

                        if (echipmodel["lim"] == "limmain")
                        {
                            a = new atribut();
                            a.val_string = "1";
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "LIM MAIN" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }
                        else
                        {
                            a = new atribut();
                            a.val_string = echipmodel["limdist-text"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "LIM DISTANT" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);

                            db.SaveChanges();
                        }

                    }
                    else if (tipechip == "MSED")
                    {
                        s = new echipament();
                        s.denumire = echipmodel["denumire"].ToString();

                        int x = 0;
                        if (int.TryParse(echipmodel["tipechipament"].ToString(), out x) == true)
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString());
                        else
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString().Split('_')[0]);

                        s.siteID = long.Parse(echipmodel["siteID"].ToString()); /// ???
                        s.createDate = DateTime.Now;
                        s.editDate = null;
                        s.editcontactID = null;
                        s.editcontactID = userID;
                        s.disabled = 0;
                        db.AddToechipaments(s);

                        atribut a = new atribut();
                        a.val_string = echipmodel["locatieremote"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "Locatie remote" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        echipament_atribute ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["ipces"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP CES" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["ipmanagement"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP Management" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["ipcesremote"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP CES Remote" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["ipmanagementremote"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP Management Remote" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["mask"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "MASK" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["gateway"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "GATEWAY" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);

                        db.SaveChanges();

                    }
                    else if (tipechip == "MC" || tipechip == "Concentrator" || tipechip == "Router" || tipechip == "Switch" || tipechip == "Endpoint")
                    {
                        s = new echipament();
                        s.denumire = echipmodel["denumire"].ToString();

                        int x = 0;
                        if (int.TryParse(echipmodel["tipechipament"].ToString(), out x) == true)
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString());
                        else
                            s.tipID = int.Parse(echipmodel["tipechipament"].ToString().Split('_')[0]);

                        s.siteID = long.Parse(echipmodel["siteID"].ToString()); /// ???
                        s.createDate = DateTime.Now;
                        s.editDate = null;
                        s.editcontactID = null;
                        s.createContactID = userID;
                        s.disabled = 0;
                        db.AddToechipaments(s);

                        atribut a = new atribut();
                        a.val_string = echipmodel["IP"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "IP" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        echipament_atribute ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["MASK"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "MASK" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();

                        a = new atribut();
                        a.val_string = echipmodel["GATEWAY"];
                        a.val_csv = null;
                        a.val_int = null;
                        a.val_nr = null;
                        a.tipID = (from ta in db.tip_atribut where ta.denumire == "GATEWAY" select ta.id).FirstOrDefault();
                        a.createDate = DateTime.Now;
                        a.editDate = null;
                        a.editContactID = null;
                        a.createContactID = userID;
                        a.disabled = 0;
                        db.AddToatributs(a);

                        ea = new echipament_atribute();
                        ea.echipamentID = s.id;
                        ea.atributID = a.id;
                        ea.createDate = DateTime.Now;
                        ea.editDate = null;
                        ea.editContactID = null;
                        ea.createContactID = userID;
                        ea.disabled = 0;
                        db.AddToechipament_atribute(ea);
                        db.SaveChanges();

                        if (tipechip == "Switch")
                        {
                            foreach (var key in echipmodel.Keys)
                            {
                                if (key.ToString().StartsWith("port"))
                                {
                                    a = new atribut();
                                    a.val_string = echipmodel[key.ToString()];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Port" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    ea = new echipament_atribute();
                                    ea.echipamentID = s.id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddToechipament_atribute(ea);
                                    db.SaveChanges();
                                }
                            }
                        }

                        if (tipechip == "MC")
                        {
                            a = new atribut();
                            a.val_string = echipmodel["ENDPOINT"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "ENDPOINT" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            ea = new echipament_atribute();
                            ea.echipamentID = s.id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }

                        if (tipechip == "Concentrator")
                        {
                            for (int k = 1; k <= 10; k++)
                            {
                                a = new atribut();
                                a.val_string = echipmodel["port" + k.ToString()];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Port" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea = new echipament_atribute();
                                ea.echipamentID = s.id;
                                ea.atributID = a.id;
                                ea.createDate = DateTime.Now;
                                ea.editDate = null;
                                ea.editContactID = null;
                                ea.createContactID = userID;
                                ea.disabled = 0;
                                db.AddToechipament_atribute(ea);
                                db.SaveChanges();
                            }
                        }

                    }
                    else
                        s = new echipament();

                    db.SaveChanges();
                }
                else//exista deja
                {
                    s = db.echipaments.Where(o => o.id == id).FirstOrDefault();
                    int i = 0;
                    foreach (var key in echipmodel.Keys)
                    {
                        if (!key.ToString().StartsWith("abonati") && key.ToString() != "lim" && !key.ToString().StartsWith("port") && !key.ToString().StartsWith("nrrutanou") && !key.ToString().StartsWith("pozitienou") && !key.ToString().StartsWith("tiptransportnou") && !key.ToString().StartsWith("tipcnou") && !key.ToString().StartsWith("destinatienou") && !key.ToString().EndsWith("-text") && key.ToString() != "tipcnou" && key.ToString() != "destinatienou" && key.ToString() != "nrrutanou" && key.ToString() != "destinatie" && key.ToString() != "tipconexiune" && key.ToString() != "nrruta" && key.ToString() != "siteID" && key.ToString() != "ipces" && key.ToString() != "licenta" && key.ToString() != "locatieremote" && key.ToString() != "ipmanagement" && key.ToString() != "ipcesremote" && key.ToString() != "ipmanagementremote" && key.ToString() != "mask" && key.ToString() != "gateway" && key.ToString() != "numeechip" && key.ToString() != "ab_analogici_dela" && key.ToString() != "ab_digitali_dela" && key.ToString() != "ab_IP_dela" && key.ToString() != "ab_DECT_dela" && key.ToString() != "ab_total_dela" && key.ToString() != "ab_analogici_panala" && key.ToString() != "ab_digitali_panala" && key.ToString() != "ab_IP_panala" && key.ToString() != "ab_DECT_panala" && key.ToString() != "ab_total_panala" && key.ToString() != "tip_nou" && key.ToString() != "denumire" && key.ToString() != "tip_val" && key.ToString() != "val_nou" && key.ToString() != "id" && !key.ToString().EndsWith(":"))
                        {
                            string idechip_idatr = key.ToString();
                            int nr_split = idechip_idatr.Split('_').Count();
                            long idechip = 0;
                            long idatr = 0;

                                idechip = long.Parse(idechip_idatr.Split('_')[0]);
                                idatr = long.Parse(idechip_idatr.Split('_')[1]);

                            atribut a = db.atributs.Where(o=> o.id == idatr).FirstOrDefault();

                            string valoare = echipmodel[i];

                            string tip = "";
                            try
                            {
                                tip = (from a1 in db.atributs
                                       join at1 in db.tip_atribut on a1.tipID equals at1.id
                                       where a1.id == a.id
                                       select at1.denumire).FirstOrDefault();
                            }
                            catch
                            {
                                // plan de numerotatie

                                idatr = long.Parse(idatr.ToString().Substring(0, idatr.ToString().Length - 1));
                                a = db.atributs.Where(o => o.id == idatr).FirstOrDefault();
                                tip = (from a1 in db.atributs
                                       join at1 in db.tip_atribut on a1.tipID equals at1.id
                                       where a1.id == a.id
                                       select at1.denumire).FirstOrDefault();
                            }

                            string den_centrala = "";
                            if (tip == "Licenta")
                            {
                                den_centrala = (from e in db.echipaments
                                  join ea in db.echipament_atribute on e.id equals ea.echipamentID
                                  join a1 in db.atributs on ea.atributID equals a1.id
                                  join ta in db.tip_atribut on a1.tipID equals ta.id
                                  join et in db.echipament_tip on a1.val_int equals et.id
                                  where ta.denumire == "Tip" && e.id == idechip
                                  select et.denumire).FirstOrDefault();
                            }

                            int val_int;
                            decimal val_long;
                            string cheie = echipmodel[key.ToString() + ":"];
                            if (tip.Contains("Abonati"))
                                cheie = echipmodel[key.ToString().Substring(0, key.ToString().Length - 1) + ":"];

                            switch (cheie)
                            {
                                case "S": a.val_string =
                                    (tip == "Licenta" && (den_centrala == "MD" || den_centrala == "MX-ONE") && key.ToString().EndsWith("licenta1")) ?
                                   echipmodel[key.ToString()] + echipmodel[key.ToString().Replace("licenta1", "licenta2")] :
                                   (key.ToString().EndsWith("licenta2") ? a.val_string :
                                   (tip == "Contract" && echipmodel[key.ToString()] == "Altul" ? echipmodel[key.ToString()+"-text"]  : echipmodel[key.ToString()]));
                                    ;
                                            break;
                                case "I": if (int.TryParse(echipmodel[key.ToString()], out val_int))
                                                a.val_int = int.Parse(echipmodel[key.ToString()]);
                                            else
                                                a.val_int = null;
                                            break;
                                case "N": if (decimal.TryParse(echipmodel[key.ToString()], out val_long))
                                                a.val_nr = decimal.Parse(echipmodel[key.ToString()]);
                                            else
                                                a.val_nr = null;
                                            break;
                                case "CSV": a.val_csv = (tip.Contains("Abonati") == true && key.ToString().EndsWith("1") ? echipmodel[key.ToString()] + "," + echipmodel[key.ToString().Substring(0,key.ToString().Length-1) + "2"] :
                                    (tip.Contains("Abonati") == true && key.ToString().EndsWith("2") ? a.val_csv : echipmodel[key.ToString()]));
                                            break;
                                default:    a.val_string = echipmodel[key.ToString()].ToString();
                                            break;

                            }
                            a.editDate = DateTime.Now;
                            a.editContactID = userID;
                            db.SaveChanges();
                        }
                        else if (key.ToString().StartsWith("abonati_dela") && !key.ToString().EndsWith(":"))
                        {
                                    string nraux = key.ToString().Substring(12);
                                    atribut a = new atribut();
                                    a.val_string = null;
                                    a.val_csv = echipmodel[key.ToString()].ToString() + "," + echipmodel["abonati_panala" + nraux].ToString();
                                    a.val_int = null;
                                    a.val_nr = null;
                                    a.tipID = (from ta in db.tip_atribut where ta.denumire == "Abonati" select ta.id).FirstOrDefault();
                                    a.createDate = DateTime.Now;
                                    a.editDate = null;
                                    a.editContactID = null;
                                    a.createContactID = userID;
                                    a.disabled = 0;
                                    db.AddToatributs(a);

                                    echipament_atribute ea = new echipament_atribute();
                                    ea.echipamentID = id;
                                    ea.atributID = a.id;
                                    ea.createDate = DateTime.Now;
                                    ea.editDate = null;
                                    ea.editContactID = null;
                                    ea.createContactID = userID;
                                    ea.disabled = 0;
                                    db.AddToechipament_atribute(ea);
                                    db.SaveChanges();
                        }
                        else if (key.ToString().StartsWith("port"))
                        {
                            atribut a = new atribut();
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.tipID = (from ta in db.tip_atribut where ta.denumire == "Port" select ta.id).FirstOrDefault();
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;
                            db.AddToatributs(a);

                            echipament_atribute ea = new echipament_atribute();
                            ea.echipamentID = id;
                            ea.atributID = a.id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }
                        else if (key.ToString() == "lim")
                        {
                            int val_int;
                            decimal val_long;
                            atribut a2 = (from a in db.atributs
                                          join ea in db.echipament_atribute on a.id equals ea.atributID
                                          join e in db.echipaments on ea.echipamentID equals e.id
                                          join ta in db.tip_atribut on a.tipID equals ta.id
                                          where e.id == id
                                          && ta.denumire == "LIM MAIN"
                                          select a).FirstOrDefault();
                            atribut a1 = (from a in db.atributs
                                          join ea in db.echipament_atribute on a.id equals ea.atributID
                                          join e in db.echipaments on ea.echipamentID equals e.id
                                          join ta in db.tip_atribut on a.tipID equals ta.id
                                          where e.id == id
                                          && ta.denumire == "LIM DISTANT"
                                          select a).FirstOrDefault();

                            if (echipmodel["lim"] == "limmain")
                            {
                                try
                                {
                                    if (a2 == null)
                                    {
                                        a2 = new atribut();
                                        a2.tipID = (from ta in db.tip_atribut where ta.denumire == "LIM MAIN" select ta.id).FirstOrDefault();
                                        a2.val_string = "1";
                                        a2.val_csv = null;
                                        a2.val_int = null;
                                        a2.val_nr = null;
                                        a2.createDate = DateTime.Now;
                                        a2.editDate = null;
                                        a2.editContactID = null;
                                        a2.createContactID = userID;
                                        a2.disabled = 0;

                                        echipament_atribute ea = new echipament_atribute();
                                        ea.atributID = a2.id;
                                        ea.echipamentID = id;
                                        ea.createDate = DateTime.Now;
                                        ea.editDate = null;
                                        ea.editContactID = null;
                                        ea.createContactID = userID;
                                        ea.disabled = 0;

                                        db.AddToatributs(a2);
                                        db.AddToechipament_atribute(ea);
                                    }
                                    else
                                    {
                                        a2.val_string = "1";
                                        a2.val_csv = null;
                                        a2.val_int = null;
                                        a2.val_nr = null;

                                        a2.editDate = DateTime.Now;
                                        a2.editContactID = userID;

                                    }
                                    db.SaveChanges();
                                }
                                catch { }

                                try
                                {
                                    if (a1 != null)
                                    {
                                        a1.val_string = null;
                                        a1.val_csv = null;
                                        a1.val_int = null;
                                        a1.val_nr = null;
                                        a1.editDate = DateTime.Now;
                                        a1.editContactID = userID;
                                        db.SaveChanges();

                                    }
                                }
                                catch { }

                            }
                            else
                            {
                                try
                                {
                                    if (a2 != null)
                                    {

                                        a2.val_string = "0";
                                        a2.val_csv = null;
                                        a2.val_int = null;
                                        a2.val_nr = null;

                                        a2.editDate = DateTime.Now;
                                        a2.editContactID = userID;
                                        db.SaveChanges();
                                    }
                                }
                                catch { }

                                try
                                {
                                    if (a1 == null)
                                    {
                                        a1 = new atribut();
                                        a1.tipID = (from ta in db.tip_atribut where ta.denumire == "LIM DISTANT" select ta.id).FirstOrDefault();

                                        a1.val_string = echipmodel["limdist-text"];
                                        a1.val_csv = null;
                                        a1.val_int = null;
                                        a1.val_nr = null;
                                        a1.createDate = DateTime.Now;
                                        a1.editDate = null;
                                        a1.editContactID = null;
                                        a1.createContactID = userID;
                                        a1.disabled = 0;

                                        echipament_atribute ea = new echipament_atribute();
                                        ea.atributID = a1.id;
                                        ea.echipamentID = id;
                                        ea.createDate = DateTime.Now;
                                        ea.editDate = null;
                                        ea.editContactID = null;
                                        ea.createContactID = userID;
                                        ea.disabled = 0;

                                        db.AddToatributs(a1);
                                        db.AddToechipament_atribute(ea);
                                    }
                                    else
                                    {
                                        a1.val_string = echipmodel["limdist-text"];
                                        a1.val_csv = null;
                                        a1.val_int = null;
                                        a1.val_nr = null;
                                        a1.editDate = DateTime.Now;
                                        a1.editContactID = userID;
                                    }

                                    db.SaveChanges();
                                }
                                catch { }
                            }
                        }
                        else if (key.ToString().StartsWith("nrrutanou") && !key.ToString().EndsWith(":"))
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                            //

                        }
                        else if (key.ToString().StartsWith("tipcnou") && !key.ToString().EndsWith(":"))
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Tip Conexiune" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();

                            if (echipmodel[key.ToString()] == "ISDN-PUBLIC" || echipmodel[key.ToString()] == "ISDN-QSIG")
                            {
                                string nraux = key.ToString().Substring(7);//, key.ToString().Length - 7);

                                cartela s1 = new cartela();
                                s1.tipID = (from tc in db.tip_cartela where tc.denumire == "TLU76" select tc.id).FirstOrDefault();
                                s1.echipamentID = id;
                                s1.createDate = DateTime.Now;
                                s1.editDate = null;
                                s1.editContactID = null;
                                s1.createcontactID = userID;
                                s1.disabled = 0;
                                db.AddTocartelas(s1);
                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = echipmodel["pozitienou" + nraux];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "BPOS" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                cartela_atribute ea1 = new cartela_atribute();
                                ea1.cartelaID = s1.id;
                                ea1.atributID = a.id;
                                ea1.createDate = DateTime.Now;
                                ea1.editDate = null;
                                ea1.editContactID = null;
                                ea1.createContactID = userID;
                                ea1.disabled = 0;
                                db.AddTocartela_atribute(ea1);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = echipmodel["destinatienou" + nraux];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Remote" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea1 = new cartela_atribute();
                                ea1.cartelaID = s1.id;
                                ea1.atributID = a.id;
                                ea1.createDate = DateTime.Now;
                                ea1.editDate = null;
                                ea1.editContactID = null;
                                ea1.createContactID = userID;
                                ea1.disabled = 0;
                                db.AddTocartela_atribute(ea1);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = "/1";
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "VersiuneC" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea1 = new cartela_atribute();
                                ea1.cartelaID = s1.id;
                                ea1.atributID = a.id;
                                ea1.createDate = DateTime.Now;
                                ea1.editDate = null;
                                ea1.editContactID = null;
                                ea1.createContactID = userID;
                                ea1.disabled = 0;
                                db.AddTocartela_atribute(ea1);

                                db.SaveChanges();

                                a = new atribut();
                                a.val_string = echipmodel["nrrutanou" + nraux];
                                a.val_csv = null;
                                a.val_int = null;
                                a.val_nr = null;
                                a.tipID = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select ta.id).FirstOrDefault();
                                a.createDate = DateTime.Now;
                                a.editDate = null;
                                a.editContactID = null;
                                a.createContactID = userID;
                                a.disabled = 0;
                                db.AddToatributs(a);

                                ea1 = new cartela_atribute();
                                ea1.cartelaID = s1.id;
                                ea1.atributID = a.id;
                                ea1.createDate = DateTime.Now;
                                ea1.editDate = null;
                                ea1.editContactID = null;
                                ea1.createContactID = userID;
                                ea1.disabled = 0;
                                db.AddTocartela_atribute(ea1);

                                db.SaveChanges();
                            }
                        }
                        else if (key.ToString().StartsWith("destinatienou") && !key.ToString().EndsWith(":"))
                        {
                            //
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Destinatie" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }
                        else if (key.ToString().StartsWith("pozitienou") && !key.ToString().EndsWith(":"))
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Poz. echip." select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                            //

                        }
                        else if (key.ToString().StartsWith("tiptransportnou") && !key.ToString().EndsWith(":"))
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Tip echip." select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel[key.ToString()];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                            //

                        }
                        else if (key.ToString() == "tip_nou" && echipmodel["tip_nou"].ToString() == "Conexiune")
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            var taid = (from ta in db.tip_atribut where ta.denumire == "Numar ruta" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel["nrrutanou"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                            //
                            a = new atribut();
                            taid = (from ta in db.tip_atribut where ta.denumire == "Tip Conexiune" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel["tipcnou"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();

                            //
                            a = new atribut();
                            taid = (from ta in db.tip_atribut where ta.denumire == "Destinatie" select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            a.val_string = echipmodel["destinatienou"];
                            a.val_csv = null;
                            a.val_int = null;
                            a.val_nr = null;
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }
                        else if (key.ToString() == "tip_nou" && echipmodel["val_nou"].ToString() != "")
                        {
                            int val_int;
                            decimal val_long;
                            atribut a = new atribut();
                            string tip_nou = echipmodel["tip_nou"];
                            var taid = (from ta in db.tip_atribut where ta.denumire == tip_nou select new { ta.id, ta.tip_valoare }).FirstOrDefault();
                            a.tipID = taid.id;
                            switch (taid.tip_valoare)
                            {
                                case "S":
                                    a.val_string = echipmodel["val_nou"];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                case "I":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    if (int.TryParse(echipmodel["val_nou"].ToString(), out val_int))
                                        a.val_int = int.Parse(echipmodel["val_nou"]);
                                    else
                                        a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                case "N":
                                    a.val_string = null;
                                    a.val_csv = null;
                                    a.val_int = null;
                                    if (decimal.TryParse(echipmodel["val_nou"].ToString(), out val_long))
                                        a.val_nr = decimal.Parse(echipmodel["val_nou"]);
                                    else
                                        a.val_nr = null;
                                    break;
                                case "CSV":
                                    a.val_string = null;
                                    a.val_csv = echipmodel["val_nou"];
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                                default:
                                    a.val_string = echipmodel["val_nou"];
                                    a.val_csv = null;
                                    a.val_int = null;
                                    a.val_nr = null;
                                    break;
                            }
                            a.createDate = DateTime.Now;
                            a.editDate = null;
                            a.editContactID = null;
                            a.createContactID = userID;
                            a.disabled = 0;

                            echipament_atribute ea = new echipament_atribute();
                            ea.atributID = a.id;
                            ea.echipamentID = id;
                            ea.createDate = DateTime.Now;
                            ea.editDate = null;
                            ea.editContactID = null;
                            ea.createContactID = userID;
                            ea.disabled = 0;

                            db.AddToatributs(a);
                            db.AddToechipament_atribute(ea);
                            db.SaveChanges();
                        }

                    }
                }
                var judet = (from j in db.judetes
                             join s1 in db.sites on j.id equals s1.judetID
                             join e in db.echipaments on s1.id equals e.siteID
                             where e.id == s.id
                             select new { j.id, j.denumire }).FirstOrDefault();

                return RedirectToAction("Index", "Judete", new { name = judet.denumire.ToString() , id = s.id.ToString() + "_echipament" });
            }
            else
            {
                return Json("Salvarea nu a fost efectuata!");
            }
        }