Exemplo n.º 1
0
 public void SaveUser(User user)
 {
     if (user.userID == 0)
     {
         _db.Users.Add(user);
     }
     else
     {
         var dbEntry = _db.Users.Find(user.userID);
         if (dbEntry != null)
         {
             dbEntry.password = user.password;
             dbEntry.userGroupID = user.userGroupID;
             dbEntry.companyName = user.companyName;
             dbEntry.juridicalAddress = user.juridicalAddress;
             dbEntry.address = user.address;
             dbEntry.contactPerson = user.contactPerson;
             dbEntry.post = user.post;
             dbEntry.phoneNumber = user.phoneNumber;
             dbEntry.email = user.email;
             dbEntry.merchantLicense = user.merchantLicense;
             dbEntry.tradeLicense = user.tradeLicense;
             dbEntry.approved = user.approved;
             dbEntry.passwordSalt = user.passwordSalt;
         }
     }
     _db.SaveChanges();
 }
        public string Register(User user, IEnumerable<string> selectedCities)
        {
            StringBuilder sb = new StringBuilder();
            if (selectedCities == null)
            {
                sb.Append("No cities are selected");
            }
            else
            {

                sb.Append(string.Join("", selectedCities));

                if (ModelState.IsValid)
                {
                    var crypto = new SimpleCrypto.PBKDF2();
                    var encrpass = crypto.Compute(user.password);
                    user.password = encrpass;
                    User user2 = null;
                    user2 = repository.Users.Where(u => u.email == user.email || u.password == user.password || u.companyName == user.companyName).FirstOrDefault();
                    if (user2 == null)
                    {
                        user.passwordSalt = crypto.Salt;
                        user.merchantLicense = false;
                        user.tradeLicense = false;
                        user.userGroupID = 3;
                        repository.SaveUser(user);
                        foreach (string item in selectedCities)
                        {
                            ChoosedCategory ck = new ChoosedCategory();
                            ck.userID = user.userID;
                            ck.productCategoryID = Convert.ToInt32(item);
                            repository.SaveChoosedCategory(ck);
                        }

                        ModelState.Clear();
                        ViewBag.Message = "Реєстрація прошла успішно!";

                    }
                    else
                    {
                        ModelState.AddModelError(" ", "Користувач уже існує!");
                        ViewBag.Message = "Користувач уже існує!";
                    }

                }
                else
                {
                    ViewBag.Message = "Перевірте поля!";

                }

            }
            RedirectToAction("Index");
            return sb.ToString();
        }
        public ActionResult Register(User user, Register reg)
        {
            string a = "";
            string b = "";
            if (ModelState.IsValid)
            {
                var crypto = new SimpleCrypto.PBKDF2();
                var encrpass = crypto.Compute(reg.password);
                user.password = encrpass;
                User user2 = null;
                user2 = repository.Users.Where(u => u.email == reg.email).FirstOrDefault();
                if (user2 == null)
                {
                    user.passwordSalt = crypto.Salt;
                    user.merchantLicense = false;
                    user.tradeLicense = false;
                    user.userGroupID = 1;
                    user.email = reg.email;
                    user.companyName = reg.companyName;
                    user.contactPerson = reg.contactPerson;
                    user.address = reg.address;
                    user.juridicalAddress = reg.juridicalAddress;
                    user.post = reg.post;
                    user.phoneNumber = reg.phoneNumber;
                    user.approved = false;
                    repository.SaveUser(user);
                    ModelState.Clear();
                    a = "Login";
                    b = "Account";
                    RedirectToAction(a, b);
                }
                else
                {
                    ViewBag.Message = "Користувач уже існує!";
                }

            }
            else
            {
                ViewBag.Message = "Невірні дані!";
            }
            return View(); ;
        }
Exemplo n.º 4
0
        public ActionResult EditUser(User user)
        {
            if (ModelState.IsValid)
            {
                repository.SaveUser(user);
                TempData["message"] = string.Format("Користувача {0} було збережено!", user.contactPerson);

                return RedirectToAction("UsersList");
            }
            else
            {
                return View(user);
            }
        }