public ActionResult Registry(RegistryUser registryUser) { if (ModelState.IsValid && registryUser.Login != null && registryUser.Name != null && registryUser.Password != null && registryUser.Surname != null && registryUser.Login != "" && registryUser.Name != "" && registryUser.Password != "" && registryUser.Surname != "") { using (var db = new DbContext()) { int existsUser = db.Users.Where(u => u.Login.ToLower() == registryUser.Login.ToLower()).Count(); if (existsUser == 0) { User user = Converters.RegistryUserToUserConverter(registryUser); user.LanguageID = 1; user.DateSign = DateTime.Now; user.DateBorn = null; user.UserTreeSharingStatusID = 1; //defaultowy status drzewa - dostępny tylko dla mnie ResourceManager.LoggedUser = user; db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("MyTree", "Home")); } else { ViewBag.Error = ResourceManager.getElementTextInLanguage(102, 1);; return(View(registryUser)); } } } ViewBag.Error = ResourceManager.getElementTextInLanguage(101, 1);; return(View(registryUser)); }
public static User RegistryUserToUserConverter(RegistryUser registryUser) { return(new User(registryUser.Login, registryUser.Password, registryUser.Name, registryUser.Surname)); }