Example #1
0
        public bool RegisterPoedinec(RegisterModel poedinecModel)
        {
            try
            {
                Poedinci poedinec = new Poedinci
                {
                    Ime = poedinecModel.Ime,
                    Prezime = poedinecModel.Prezime,
                    KorisnickoIme = poedinecModel.KorisnickoIme,
                    Lozinka = poedinecModel.Password,
                    Mail = poedinecModel.Email,
                    Telefon = poedinecModel.Telefon
                };

                _db.Poedinci.Add(poedinec);
                _db.SaveChanges();
            }
            catch(Exception ex)
            {
                return false;
            }
            return true;
        }
Example #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    var isVerified = _qPoedinec.VerifyPoedinecRegistration(model);
                    if (isVerified)
                        _qPoedinec.RegisterPoedinec(model);

                    return RedirectToAction("Login", "Account");
                }
                catch (ExistingEmailException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch (ExistingUsernameException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Профилот не е успешно креиран.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #3
0
        public bool VerifyPoedinecRegistration(RegisterModel poedinecModel)
        {
            var poedinec = _db.Poedinci.FirstOrDefault(x => x.KorisnickoIme == poedinecModel.KorisnickoIme || x.Mail == poedinecModel.Email);

            if(poedinec != null)
            {
                if (poedinec.KorisnickoIme == poedinecModel.KorisnickoIme)
                    throw new ExistingUsernameException("Корисничкото име веќе постои");

                if (poedinec.Mail == poedinecModel.Email)
                    throw new ExistingEmailException("Е-Маил адресата веќе постои");

                return false;
            }

            return true;
        }