Ejemplo n.º 1
0
        public new IActionResult User(Models.Account.RegisterViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(model);
                    var content   = new StringContent(serialize);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage          responseAddNewUser = Post("account/addnewuser", content);
                    Newtonsoft.Json.Linq.JObject resultAddNewUser   = Newtonsoft.Json.Linq.JObject.Parse(responseAddNewUser.Content.ReadAsStringAsync().Result);

                    if ((bool)resultAddNewUser["succeeded"])
                    {
                        return(RedirectToAction(nameof(AdministrationController.Users), "Administration"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, resultAddNewUser["errors"][0]["description"].ToString());
                        return(View(model));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "Please check if your database is ready/published." + ": " + ex.Message);
                return(View(model));
            }
            ViewBag.PageContentHeader = "New User";
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Register(Models.Account.RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new DatabaseContext())
            {
                if (db.Uzytkownik.Any(t => t.Login == model.Login))
                {
                    ModelState.AddModelError("", $"Użytkownik o nazwie \"{model.Login}\" istnieje już w bazie danych.");
                    return(View(model));
                }

                Uzytkownik user = new Uzytkownik();
                user.Login    = model.Login;
                user.Email    = model.Email;
                user.Imie     = model.Name;
                user.Nazwisko = model.Surname;
                user.Salt     = StringLibrary.RandomString(6);
                user.Haslo    = StringLibrary.CreateMD5(model.Password + StringLibrary.CreateMD5(user.Salt));

                user.DataUtworzenia  = DateTime.Now;
                user.DataModyfikacji = DateTime.Now;
                user.IDP             = 1;
                user.Rola            = 0;

                db.Uzytkownik.Add(user);
                db.SaveChanges();
            }
            return(RedirectToAction("Login", "User"));
        }
Ejemplo n.º 3
0
 public Client ToClientEntity(Models.Account.RegisterViewModel model, string userId)
 {
     return(new Client
     {
         InsuranceCompanyId = (model.InsuranceCompanyId == 0 ? null : model.InsuranceCompanyId),
         IsAproved = true,
         IsDeleted = false,
         PolicyNumber = model.PolicyNumber,
         UserId = userId
     });
 }
Ejemplo n.º 4
0
 public User ToUserEntity(Models.Account.RegisterViewModel model, string path)
 {
     return(new User
     {
         SS = "",
         Email = model.Email,
         UserName = model.Email,
         DateOfBirth = model.DateOfBirth,
         FirstName = model.FirstName,
         LastName = model.LastName,
         IsDeleted = false,
         NIF = model.NIF,
         PictureUrl = path
     });
 }