/// <summary>
 /// Deprecated Method for adding a new object to the Adres EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAdres(Adres adres)
 {
     base.AddObject("Adres", adres);
 }
 /// <summary>
 /// Create a new Adres object.
 /// </summary>
 /// <param name="kod">Initial value of the Kod property.</param>
 /// <param name="nrKlienta">Initial value of the NrKlienta property.</param>
 /// <param name="ulica">Initial value of the Ulica property.</param>
 /// <param name="nrDomu">Initial value of the NrDomu property.</param>
 public static Adres CreateAdres(global::System.String kod, global::System.Decimal nrKlienta, global::System.String ulica, global::System.String nrDomu)
 {
     Adres adres = new Adres();
     adres.Kod = kod;
     adres.NrKlienta = nrKlienta;
     adres.Ulica = ulica;
     adres.NrDomu = nrDomu;
     return adres;
 }
        public ActionResult Register(string imie, string nazwisko, string nip, string tel, string userName, string email, string password, string confirmPassword,
            string city,string citycode, string street, string streetNo)
        {
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            Response.AppendHeader("X-XSS-Protection", "0");

            if (ValidateRegistration(userName, email, password, confirmPassword))
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //ustawienie go jako klienta
                    Roles.AddUserToRole(userName, "Klient");

                    string hash = BitConverter.ToString(SHA1Managed.Create().ComputeHash(Encoding.Default.GetBytes(password))).Replace("-", "");
                    Debug.WriteLine("Długość wynosi: " + hash.Length);

                    //tworzenie nowego klienta
                    Klinet kl = new Klinet();
                    kl.Imie = imie;
                    kl.Nazwisko = nazwisko;
                    kl.E_Mail = email;
                    kl.NIP = nip;
                    kl.Telefon = tel;
                    kl.Login = userName;
                    kl.Haslo = hash;
                    kl.Rola_w_systemie = "kl";
                    db.AddToKlinet(kl);
                    db.SaveChanges();

                    var nrk = (from p in db.Klinet
                               where p.NIP == nip
                               select p.NrKlienta
                               ).First();

                    //tworzenie adresu
                    Adres ad = new Adres();
                    ad.Kod = citycode;
                    ad.Miasto = city;
                    ad.NrDomu = streetNo;
                    ad.Ulica = street;
                    ad.NrKlienta = nrk;
                    db.AddToAdres(ad);
                    db.SaveChanges();

                    FormsAuth.SignIn(userName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View();
        }