Esempio n. 1
0
        public ActionResult UserProfile(ProfilUyztkownikaVM model)
        {
            // Check model state
            if (!ModelState.IsValid)
            {
                return(View("UserProfile", model));
            }

            // Check if passwords match if need be
            if (!string.IsNullOrWhiteSpace(model.Password))
            {
                if (!model.Password.Equals(model.ConfirmPassword))
                {
                    ModelState.AddModelError("", "Hasła się nie zgadzają");
                    return(View("UserProfile", model));
                }
            }

            using (Db db = new Db())
            {
                // Get username
                string username = User.Identity.Name;

                // Make sure username is unique
                if (db.Uzytkownik.Where(x => x.Id != model.Id).Any(x => x.Username == username))
                {
                    ModelState.AddModelError("", "Username " + model.Username + " juz istnieje.");
                    model.Username = "";
                    return(View("UserProfile", model));
                }

                // Edit DTO
                UzytkownikDTO dto = db.Uzytkownik.Find(model.Id);

                dto.Imie         = model.Imie;
                dto.Nazwisko     = model.Nazwisko;
                dto.EmailAddress = model.EmailAddress;
                dto.Username     = model.Username;

                if (!string.IsNullOrWhiteSpace(model.Password))
                {
                    dto.Password = model.Password;
                }

                // Save
                db.SaveChanges();
            }

            // Set TempData message
            TempData["SM"] = "Edytowales wlasnie swoj profil!";

            // Redirect
            return(Redirect("~/konto/user-profile"));
        }
Esempio n. 2
0
        public ActionResult UserProfile()
        {
            //get username
            string username = User.Identity.Name;
            //Deklaruj models
            ProfilUyztkownikaVM model;

            using (Db db = new Db())
            {
                // get user

                UzytkownikDTO dto = db.Uzytkownik.FirstOrDefault(x => x.Username == username);

                //build model
                model = new ProfilUyztkownikaVM(dto);
            }

            //Build

            // Return view z modelem
            return(View("UserProfile", model));
        }