Example #1
0
        public User GetUser(string email)
        {
            User user = null;
            try
            {
               
                IMongoCollection<User> mongoCollection = _database.GetCollection<User>(USERS_COLLECTION_NAME);
                BsonDocument searchBsonDocument =new BsonDocument("Email",email);
                

                if (mongoCollection != null)
                {


                    Task<User> firstOrDefaultAsync = mongoCollection.Find(searchBsonDocument).Project<User>(Builders<User>.Projection.Exclude(item=>item._id))
                        .FirstOrDefaultAsync();

                    user =new User();
                    user.Name = firstOrDefaultAsync.Result.Name;
                    user.Email = firstOrDefaultAsync.Result.Email;
                }
            }
            catch (Exception exception)
            {
                //catch the exception
            }

            return user;
        }
Example #2
0
 public void InsertUser(User user)
 {
     try
     {
         IMongoCollection<User> mongoCollection = _database.GetCollection<User>(USERS_COLLECTION_NAME);
         mongoCollection.InsertOneAsync(user);
     }
     catch (Exception exception)
     {
        //catch the exception while insert user into database
     }
     
 }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();

            // XXX WORK HERE
            // create a new user and insert it into the database

            var user = new User
            {
                Email = model.Email,
                Name = model.Name
            };
            await blogContext.Users.InsertOneAsync(user);

            return RedirectToAction("Index", "Home");
        }
Example #4
0
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // create a new user and insert it into the database
            User NewUser = new User(model.Name, model.Email);
            IMongoCollection<User> usersCollection = getCollection();
            await usersCollection.InsertOneAsync(NewUser);

            return RedirectToAction("Index", "Home");
        }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();

            //Create user model for insert operation
            User user = new User();
            user.Email = model.Email;
            user.Name = model.Name;

            blogContext.InsertUser(user);

            
            return RedirectToAction("Index", "Home");
        }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // create a new user and insert it into the database

            //var existingResult = await blogContext.Users.Find(
            //    new ExpressionFilterDefinition<User>(d => d.Email == model.Email)).ToListAsync();
            //if (existingResult.Count > 0)
            //{
            //    ModelState.AddModelError("Email", "User with this email already exists!");
            //    return View(model);
            //}

            var newUser = new User
            {
                Email = model.Email,
                Name = model.Name
            };
            await blogContext.Users.InsertOneAsync(newUser);
            //var identity = new ClaimsIdentity(new[]
            //    {
            //        new Claim(ClaimTypes.Name, newUser.Name),
            //        new Claim(ClaimTypes.Email, newUser.Email)
            //    },
            //    "ApplicationCookie");

            //var context = Request.GetOwinContext();
            //var authManager = context.Authentication;

            //authManager.SignIn(identity);
            return RedirectToAction("Index", "Home");
        }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            var user = new User
            {
                Name = model.Name,
                Email = model.Email
            };

            await blogContext.Users.InsertOneAsync(user);
            return RedirectToAction("Index", "Home");
        }