public ActionResult EditPredpriyatieSave(PredpriyatieModel Pred) { if (ModelState.IsValid) { int? idAdres = null; Predpriyatie Predpr = ugtu_db.Predpriyatie.Where(predpriyatie => predpriyatie.IDPredpriyatie == Pred.ID).First(); int adrCount = ugtu_db.AddressCZS.Where(id => id.id_address == Predpr.IDAddress).Count(); int? idAdresPr=Predpr.IDAddress; if (adrCount != 0 && Pred.IDGorod != 0) { AddressCZS adr = ugtu_db.AddressCZS.Where(id => id.id_address == Predpr.IDAddress).First(); adr.id_address = (int)Predpr.IDAddress; adr.id_gorod = (int)Pred.IDGorod; adr.addressName = Pred.Addres_ul; adr.index = Pred.index; //adr.dom = Pred.Addres_dom; //adr.korpus = Pred.Addres_korp; //adr.kv = Pred.Addres_kv; ugtu_db.SubmitChanges(); idAdres = (int)Predpr.IDAddress; } if (adrCount == 0 && Pred.IDGorod != 0) { AddressCZS adress = new AddressCZS() { id_gorod = (int)Pred.IDGorod, //dom = Pred.Addres_dom, //korpus = Pred.Addres_korp, addressName = Pred.Addres_ul, index=Pred.index //kv = Pred.Addres_kv }; ugtu_db.AddressCZS.InsertOnSubmit(adress); ugtu_db.SubmitChanges(); idAdres = (int)ugtu_db.AddressCZS.Select(m => m.id_address).Max(); } if (adrCount != 0 && Pred.IDGorod == 0) { Predpr.IDAddress = idAdres; ugtu_db.SubmitChanges(); AddressCZS adrdel = ugtu_db.AddressCZS.Where(m=>m.id_address==idAdresPr).First(); ugtu_db.AddressCZS.DeleteOnSubmit(adrdel); ugtu_db.SubmitChanges(); } Predpr.Name = Pred.NamePred; //Predpr.FIORuk = Pred.FIORuk; //Predpr.IDDolznostRuk = Pred.IDDolznostRuk; //Predpr.KontaktLico = Pred.KontactLico; //Predpr.IDDolznostKLico = Pred.IDDolznostKLico; //Predpr.Telefon = Pred.Telefon; //Predpr.Faks = Pred.Faks; //Predpr.Email = Pred.Email; //Predpr.IDFormaSob = Pred.IDFormaSob; Predpr.IDSfera = Pred.IDNameSfera; Predpr.IDShtat = Pred.IDShtat; //Predpr.KontaktTelefon = Pred.TelefonKL; //Predpr.KontaktFaks = Pred.FaksKL; //Predpr.KontaktEmail = Pred.EmailKL; Predpr.IDAddress = idAdres; //Predpr.IDDolznostKLicoTr = Pred.IDDolznostKLicoTr; //Predpr.KontaktLicoTr = Pred.FIOKLTr; //Predpr.KontaktEmailTr = Pred.EmailKLTr; //Predpr.KontaktFaksTr = Pred.FaksKLTr; //Predpr.KontaktTelefonTr = Pred.TelefonKLTr; Predpr.WebSite = Pred.site; ugtu_db.SubmitChanges(); return RedirectToAction("PredpriyatieInfo", new { id = Pred.ID }); } else { return RedirectToAction("PredpriyatieEdit", new { id = Pred.ID }); } }
public string AddPred(PredpriyatieModel Pred) { int? idAdres = null; if (ModelState.IsValid) { try { if (Pred.IDGorod != 0) { AddressCZS adress = new AddressCZS() { id_gorod = (int)Pred.IDGorod, //dom = Pred.Addres_dom, //korpus = Pred.Addres_korp, addressName = Pred.Addres_ul, index = Pred.index //kv = Pred.Addres_kv }; ugtu_db.AddressCZS.InsertOnSubmit(adress); ugtu_db.SubmitChanges(); idAdres = (int)ugtu_db.AddressCZS.Select(m => m.id_address).Max(); } Predpriyatie res = new Predpriyatie() { Name = Pred.NamePred, //FIORuk = Pred.FIORuk, //IDDolznostRuk = Pred.IDDolznostRuk, //KontaktLico = Pred.KontactLico, //IDDolznostKLico = Pred.IDDolznostKLico, //Telefon = Pred.Telefon, //Faks = Pred.Faks, //Email = Pred.Email, //KontaktTelefon = Pred.TelefonKL, //KontaktFaks = Pred.FaksKL, //KontaktEmail = Pred.EmailKL, IDSfera = Pred.IDNameSfera, IDShtat = Pred.IDShtat, IDAddress = idAdres, WebSite=Pred.site, //KontaktLicoTr = Pred.FIOKLTr, //IDDolznostKLicoTr = Pred.IDDolznostKLicoTr, //KontaktTelefonTr = Pred.TelefonKLTr, //KontaktFaksTr = Pred.FaksKLTr, //KontaktEmailTr = Pred.EmailKLTr }; ugtu_db.Predpriyatie.InsertOnSubmit(res); ugtu_db.SubmitChanges(); return ugtu_db.Predpriyatie.Where(m => m.Name == Pred.NamePred).Select(m => m.IDPredpriyatie).Single().ToString(); } catch (Exception) { return ("Данное предприятие уже существует"); } } else { return ("Ошибка. Длина поля больше 100 символов"); } }
public ActionResult AddPredpriyatieSave(PredpriyatieModel Pred) { try { int? idAdres = null; if (ModelState.IsValid) { if (Pred.IDGorod != 0) { AddressCZS adress = new AddressCZS() { id_gorod = (int)Pred.IDGorod, //dom=Pred.Addres_dom, //korpus=Pred.Addres_korp, addressName = Pred.Addres_ul, index = Pred.index //kv=Pred.Addres_kv }; ugtu_db.AddressCZS.InsertOnSubmit(adress); ugtu_db.SubmitChanges(); idAdres = (int)ugtu_db.AddressCZS.Select(m => m.id_address).Max(); } Predpriyatie res = new Predpriyatie() { Name = Pred.NamePred, //FIORuk = Pred.FIORuk, //IDDolznostRuk = Pred.IDDolznostRuk, //KontaktLico = Pred.KontactLico, //IDDolznostKLico = Pred.IDDolznostKLico, //Telefon = Pred.Telefon, //Faks = Pred.Faks, //Email = Pred.Email, //KontaktTelefon = Pred.TelefonKL, //KontaktFaks = Pred.FaksKL, //KontaktEmail = Pred.EmailKL, //IDFormaSob = Pred.IDFormaSob, IDSfera = Pred.IDNameSfera, IDShtat = Pred.IDShtat, IDAddress = idAdres, //IDDolznostKLicoTr = Pred.IDDolznostKLicoTr, //KontaktLicoTr = Pred.FIOKLTr, //KontaktEmailTr = Pred.EmailKLTr, //KontaktFaksTr = Pred.FaksKLTr, //KontaktTelefonTr = Pred.TelefonKLTr, WebSite=Pred.site }; ugtu_db.Predpriyatie.InsertOnSubmit(res); ugtu_db.SubmitChanges(); return RedirectToAction("PredpriyatieInfo", new { id = res.IDPredpriyatie }); } else { return RedirectToAction("AddPredpriyatie"); } }catch(Exception){ return View("Error"); } }
public string AddPred(PredpriyatieModel Pred) { int? idAdres = null; if (ModelState.IsValid) { try { if (Pred.IDGorod != 0) { AddressCZS adress = new AddressCZS() { id_gorod = (int)Pred.IDGorod, addressName = Pred.Addres_ul }; ugtu_db.AddressCZS.InsertOnSubmit(adress); ugtu_db.SubmitChanges(); idAdres = (int)ugtu_db.AddressCZS.Select(m => m.id_address).Max(); } Predpriyatie res = new Predpriyatie() { Name = Pred.NamePred, FIORuk = Pred.FIORuk, IDDolznostRuk = Pred.IDDolznostRuk, KontaktLico = Pred.KontactLico, DolznostKLico = Pred.DolznostKLico, Telefon = Pred.Telefon, Faks = Pred.Faks, Email = Pred.Email, KontaktTelefon = Pred.TelefonKL, KontaktFaks = Pred.FaksKL, KontaktEmail = Pred.EmailKL, //IDFormaSob = Pred.IDFormaSob, IDSfera = Pred.IDNameSfera, IDShtat = Pred.IDShtat, IDAddress = idAdres }; ugtu_db.Predpriyatie.InsertOnSubmit(res); ugtu_db.SubmitChanges(); return ugtu_db.Predpriyatie.Where(m => m.Name == Pred.NamePred).Select(m => m.IDPredpriyatie).First().ToString(); } catch (Exception) { return ("Данное предприятие уже существует"); } } else { return ("Ошибка. Длина поля больше 100 символов"); } }