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();
        }
Пример #2
0
 public void SaveChoosedCategory(ChoosedCategory choosedCategory)
 {
     if (choosedCategory.chosenCategoryID == 0)
     {
         _db.ChoosedCategories.Add(choosedCategory);
     }
     else
     {
         var dbEntry = _db.ChoosedCategories.Find(choosedCategory.chosenCategoryID);
         if (dbEntry != null)
         {
             dbEntry.productCategoryID = choosedCategory.productCategoryID;
             dbEntry.userID = choosedCategory.userID;
         }
     }
     _db.SaveChanges();
 }
Пример #3
0
        public ActionResult EditChoosedCategory(ChoosedCategory choosedCategory)
        {
            if (ModelState.IsValid)
            {
                repository.SaveChoosedCategory(choosedCategory);
                TempData["message"] = string.Format("Обрану категорію {0} було збережено!", choosedCategory.chosenCategoryID);

                return RedirectToAction("ChoosedCategoriesList");
            }
            else
            {
                return View(choosedCategory);
            }
        }