Пример #1
0
        public ActionResult Update(Guid id)
        {
            Dealer          d    = ds.GetByID(id);
            DealerAddressVM davm = new DealerAddressVM();

            if (d.AddressID != null)
            {
                Address adr = adrs.GetByID(d.AddressID);
                davm.AddressID  = adr.ID;
                davm.Street     = adr.Street;
                davm.PostalCode = adr.PostalCode;
                davm.CityID     = adr.CityID;
                davm.CityName   = adr.City.CityName;

                if (adr.City != null && adr.City.Country != null)
                {
                    davm.CountryID   = adr.City.CountryID;
                    davm.CountryName = adr.City.Country.CountryName;
                }
            }

            davm.DealerID  = id;
            davm.Name      = d.Name;
            davm.MainPhone = d.MainPhone;
            davm.AddressID = d.AddressID;

            ViewBag.CityID    = new SelectList(cits.GetAll(), "ID", "CityName", davm.CityID);
            ViewBag.CountryID = new SelectList(cnts.GetAll(), "ID", "CountryName", davm.CountryID);

            return(View(davm));
        }
Пример #2
0
        public ActionResult Update(DealerAddressVM item)
        {
            Dealer toUpdate = ds.GetByID(item.DealerID);

            toUpdate.Name      = item.Name;
            toUpdate.MainPhone = item.MainPhone;
            toUpdate.AddressID = item.AddressID;

            Address a = adrs.GetByID(item.AddressID);

            a.Street     = item.Street;
            a.PostalCode = item.PostalCode;
            a.CityID     = item.CityID;

            City c = cits.GetByID(item.CityID);

            if (c.Country == null)
            {
                c.CountryID = item.CountryID;
                cits.Update(c);
            }

            adrs.Update(a);
            ds.Update(toUpdate);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Insert(DealerAddressVM item)
        {
            ViewBag.CityID    = new SelectList(cits.GetActive(), "ID", "CityName", item.CityID);
            ViewBag.CountryID = new SelectList(cnts.GetActive(), "ID", "CountryName", item.CountryID);

            if (ModelState.IsValid)
            {
                Dealer d = new Dealer();
                d.Name      = item.Name;
                d.MainPhone = item.MainPhone;

                Address a = new Address();
                a.Street     = item.Street;
                a.PostalCode = item.PostalCode;
                a.CityID     = item.CityID;

                City c = cits.GetByID(item.CityID);
                if (c.Country == null)
                {
                    c.CountryID = item.CountryID;
                    cits.Update(c);
                }

                adrs.Add(a);
                d.AddressID = a.ID;

                bool sonuc = ds.Add(d);
                if (sonuc)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.Message = "Invalid format.";
            }

            return(View());
        }