Exemplo n.º 1
0
        public ActionResult Registration(UserModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                Core.Data.User userEntity = new Core.Data.User
                {

                    Email = model.Email,
                    AddedDate = DateTime.UtcNow,

                    UserProfile = new UserProfile
                    {
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        AddedDate = DateTime.UtcNow
                    },

                    Roles = userService.GetRoles().Where(t => t.Name == "user").ToList()
                };

                userEntity.SetPassword(model.PasswordHash);
                userService.InsertUser(userEntity);

                FormsAuthentication.SetAuthCookie(userEntity.Email, true);

                if ((userEntity.ID > 0) && (returnUrl != string.Empty))
                {
                        return Redirect(returnUrl);
                }

                return RedirectToRoute("home");
            }

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult CreateOrEditUser(UserModel model)
        {
            var user= new Core.Data.User();
            SyncRoles(model.Roles, user.Roles);

            if (!ModelState.IsValid)
                return View(model);

            if (model.ID == 0)
            {
                if (userService.GetUsers().Any(t => t.Email == model.Email))
                    ModelState.AddModelError("Email", "Email დაკავებულია");

                if (!ModelState.IsValid)
                    return View(model);

                    user.Email = model.Email;
                    user.AddedDate = DateTime.UtcNow;
                    //Roles = model.Roles.ToList();
                    user.UserProfile = new UserProfile
                    {
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        AddedDate = DateTime.UtcNow,
                        FbLink = model.FbLink,
                        Avattar = model.Avattar,
                        NickName = model.Nickname

                    };

                user.SetPassword(model.PasswordHash);
                userService.InsertUser(user);
                if (user.ID > 0)
                {
                    return RedirectToAction("index");
                }
            }

            else
            {
                Core.Data.User userEntity = userService.GetUser(model.ID);
                userEntity.Email = model.Email;
                userEntity.SetPassword(model.PasswordHash);
                SyncRoles(model.Roles,userEntity.Roles);
                userEntity.FullName = model.FirstName + model.LastName;

                userEntity.UserProfile.FirstName = model.FirstName;
                userEntity.UserProfile.LastName = model.LastName;
                userEntity.UserName = model.Nickname;
                userEntity.Avattar = model.Avattar;
                userEntity.Address = model.Address;
                userEntity.FbLink = model.FbLink;
                userEntity.PhoneNumbers = model.PhoneNumbers;
                userEntity.UserProfile.userId = model.ID;
                userService.UpdateUser(userEntity);
                if (userEntity.ID > 0)
                {
                    return RedirectToAction("index");
                }

            }
            return View(model);
        }