Ejemplo n.º 1
0
        // GET: Admin
        public ActionResult Index()
        {
            // The following shows a simple line replaces the detailed db connection (ADO.NET) by using EF (EntityFramework)
            using (NewsletterEntities db = new NewsletterEntities()) // use db oject to access database / NewsletterEntities from Model1.Context.cs for databasse connection / a best practice to use 'using' to cut off the db connection when done
            {
                //var signups = db.SignUps.Where (x => x.Removed == null).ToList(); // SignUps: property (see Model1.Context.cs) which represents all of records in the database
                // LINQ instead of lambda above to list only subscribed user
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                var signupVms = new List <SignupVm>(); // if it's obvious what the data type is, you don't list it twice, use var instead of List<SignupVm>
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms)); // ViewModels (Model maps to ViewModels)
            }
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //var signups = db.SignUps_.Where(x => x.Removed == null).ToList();

                var signups = (from c in db.SignUps_
                               where c.Removed == null
                               select c);
                var signupVms = new List <SignupVm>();


                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();

                    signupVm.Id           = signup.id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVm.MonthlyTotal = Convert.ToInt32(signup.MonthlyTotal);
                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
Ejemplo n.º 3
0
        // GET: Admin
        public ActionResult Index()
        {
            //1. Instantiate the newsletterEntities class (and it passed in the connection string)
            //It's best practice to wrap instantiated entity objects in using statements - so the db connection is closed when done
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //2. We can now use this db object to access the database
                //Create a var called "signups" that is equal to (or respresents) all the records in the database - SignUps table.

                //ways to filter list returned to view
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();


                //Then we create a new list of ViewModels
                //Then we Map our database object to a ViewModel so we don't pass private/personal info to the view
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 4
0
        // GET: Admin

        /* This method is the same as what used to be the Admin() method in the HomeController
         * - we moved it from HomeController to AdminController to avoid bloating the HomeController. */
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                // Create a variable signups that equals db.Signups which represents all the signups in that Db.
                // Now signups will only be those who have the Removed property equal to null.

                // Rather than doing queries against SQL, with EF we can do the queries right here. Lambda syntax.
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                // Another way to query that is closer to SQL. LINQ syntax.
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                // Create a new list of ViewModels
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    // Map the ViewModels, from the Model to the Vms.
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }
                // Pass that list to the View.
                return(View(signupVms));
            }
        }
Ejemplo n.º 5
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //Lambda syntax:
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                //LINQ language integrated query: write sql-ish in c#
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
Ejemplo n.º 6
0
        // GET: Admin
        public ActionResult Index()
        {
            //entityframework syntax
            using (NewsletterEntities db = new NewsletterEntities())
            {
                var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                // (linq) similar way to do ^that code (lambda)
                //var signups = (from c in db.SignUps
                //               where c.Removed == null
                //               select c).ToList();

                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 7
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities()) // this instantiation gives us access to the database
            {
                //this is the EntityFramework method

                // as the db grows we will make more specific calls to the database to narrow our list, but for now, we grab all records
                //var signups = db.SignUps;  // represents all the records in the database  This maps to Signups in Newsletter.Context.cs
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();  // using lambda expression to get the rows still subscribed

                // Here we use another way, LINQ (Language INtegrated Query), to get the rows that haven't been unsubscribed
                var signups = (from rows in db.SignUps
                               where rows.Removed == null
                               select rows).ToList();
                var signupVms = new List <SignupVm>();  // var is best practice if its obvious what the data type is
                //List<SignupVm> signupVms = new List<SignupVm>();

                // Map our database object to a view model ( so we don't pass personal info to the view) and easier maintenance
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms)); // pass the list or records to the view to be displayed
            }
        }
Ejemplo n.º 8
0
        public string SignUp(SignupVm form)
        {
            if (!ModelState.IsValid)
            {
                return(PostReturnVals.Failed);
            }

            var resp = RestUnitOfWork.UserSvc.Create(form);

            if (resp.User == null)
            {
                return(resp.Message);
            }

            if (resp.User != null)
            {
                CreateToken(resp.User);
                return(PostReturnVals.Success);
            }

            if (resp.Message == MemberManagerMessages.Error.USERNAME_EXISTS)
            {
                return(MemberManagerMessages.Error.USERNAME_EXISTS);
            }

            return(PostReturnVals.Failed);
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            using (InsuranceEntities5 db = new InsuranceEntities5())
            {
                var signups = (from c in db.Insurances
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id              = signup.Id;
                    signupVm.FirstName       = signup.FirstName;
                    signupVm.LastName        = signup.LastName;
                    signupVm.EmailAddress    = signup.EmailAddress;
                    signupVm.Age             = signup.Age;
                    signupVm.CarYear         = signup.CarYear;
                    signupVm.CarMake         = signup.CarMake;
                    signupVm.CarModel        = signup.CarModel;
                    signupVm.DUI             = signup.DUI;
                    signupVm.SpeedingTickets = signup.SpeedingTickets;
                    signupVm.Coverage        = signup.Coverage;
                    signupVm.Quote           = signup.Quote;

                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 10
0
        // GET: Admin
        public ActionResult Index()
        {
            //Accesses database using Entity Framework.
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //Using Lambda syntax we have eliminated "removed" branded columns from the display!
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                //Using Linq we have eliminated "removed branded columns from the display!
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();


                var SignupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {                // Best practice to map to a "view model" and not directly from the database. Especially to protect sensitive data now or in the future when that sensitive data set were to be added.
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    SignupVms.Add(signupVm);
                }
                return(View(SignupVms));
            }
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities1 db = new NewsletterEntities1())
            {
                //var signups = (from c in db.SignUps
                //               where c.Removed == null
                //               select c).ToList();
                var signups   = db.SignUps.Where(x => x.Removed == null).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }

            //string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, SocialSecurityNumber from SignUps";
            //List<NewsletterSignup> signups = new List<NewsletterSignup>();

            //using (SqlConnection connection = new SqlConnection(connectionString))
            //{
            //    SqlCommand command = new SqlCommand(queryString, connection);

            //    connection.Open();

            //    SqlDataReader reader = command.ExecuteReader();

            //    while (reader.Read())
            //    {
            //        var signup = new NewsletterSignup();
            //        signup.Id = Convert.ToInt32(reader["id"]);
            //        signup.FirstName = reader["FirstName"].ToString();
            //        signup.LastName = reader["LastName"].ToString();
            //        signup.EmailAddress = reader["EmailAddress"].ToString();
            //        signup.SocialSecurityNumber = reader["SocialSecurityNumber"].ToString();

            //        signups.Add(signup);
            //    }

            //}

            //var signupVms = new List<SignupVm>();
            //foreach (var signup in signups)
            //{
            //    var signupVm = new SignupVm();
            //    signupVm.FirstName = signup.FirstName;
            //    signupVm.LastName = signup.LastName;
            //    signupVm.EmailAddress = signup.EmailAddress;
            //    signupVms.Add(signupVm);

            //}

            //return View(signupVms);
        }
Ejemplo n.º 12
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //Way to filter Lambda syntax
                // var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                //Linq syntax
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 13
0
        public ActionResult Admin()
        {
            string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, SocialSecurityNumber from Signups";
            List <NewsLetterSignUp> signups = new List <NewsLetterSignUp>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);

                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    var signup = new NewsLetterSignUp();
                    signup.Id                   = Convert.ToInt32(reader["Id"]);
                    signup.FirstName            = reader["FirstName"].ToString();
                    signup.LastName             = reader["LastName"].ToString();
                    signup.EmailAdress          = reader["EmailAddress"].ToString();
                    signup.SocialSecurityNumber = reader["SocialSecurityNumber"].ToString();

                    signups.Add(signup);
                }
            }
            var signupVms = new List <SignupVm>();

            foreach (var signups)
            {
                var signupVm = new SignupVm();
                signupVm.FirstName = reader["FirstName"].ToString();
            }

            return(View(signupVms));
        }
Ejemplo n.º 14
0
        public UserTb Join(SignupVm item)
        {
            var Join = new UserTb
            {
                Email    = item.Email,
                MiNember = item.Password,
                Name     = item.Fullname
            };

            return(Join);
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                // SignUps represents all the records in our SignUps table.  This one line of code, is
                // equivalent to the 15 or so lines of commented code below, i.e., query string, connection
                // and mappings from reader[].

                //var signups = db.SignUps.Where(x => x.Removed == null).ToList(); // using lambda expression
                // or using the linq query
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                var signupVms = new List <SignupVm>(); //  SignUp table ViewModel

                // map our db object to a viewmodel so that we don't pass private or personal
                // info (ssn) to the view
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
            //string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, SocialSecurityNumber FROM Signups";
            //List<Signup> signups = new List<Signup>();

            //using (SqlConnection connection = new SqlConnection(connectionString))
            //{
            //    SqlCommand command = new SqlCommand(queryString, connection);

            //    connection.Open();

            //    SqlDataReader reader = command.ExecuteReader();

            //    while (reader.Read())
            //    {
            //        var signup = new Signup();
            //        signup.Id = Convert.ToInt32(reader["Id"]);
            //        signup.FirstName = reader["FirstName"].ToString();
            //        signup.LastName = reader["LastName"].ToString();
            //        signup.EmailAddress = reader["EmailAddress"].ToString();
            //        signup.SocialSecurityNumber = reader["SocialSecurityNumber"].ToString();

            //        signups.Add(signup);
            //    }
            //}
        }
Ejemplo n.º 16
0
 public ActionResult Signup(SignupVm User)
 {
     if (ModelState.IsValid)
     {
         return(View(User));
     }
     if (this.Server.UserInsert(User.Email))
     {
         var xx = this.Server.Join(User);
         this.UserTb.Insert(xx);
         return(RedirectToAction("Login", "Lonig"));
     }
     ModelState.AddModelError("", "帳號重複");
     return(View(User));
 }
Ejemplo n.º 17
0
 public ActionResult SignUp(SignupVm m)
 {
     if (ModelState.IsValid)
     {
         if (m.Password.Equals(m.Confirm))
         {
             TaskService.insertuser(new User1 {
                 login = m.Username, password = m.Password
             });
         }
         ViewBag.message = "Added Successfully";
         return(RedirectToAction("Index"));
     }
     ViewBag.message = "Not Added";
     return(View());
 }
 public ActionResult Admin()
 {
     using (NewsletterEntities db = new NewsletterEntities())
     {
         var signups   = db.SignUps;
         var signupVms = new List <SignupVM>();
         foreach (var signup in signups)
         {
             var signupVm = new SignupVm();
             signupVm.FirstName  = signup.FirstName;
             signup.LastName     = signup.LastName;
             signup.EmailAddress = signup.EmailAddress;
             signupVms.Add(signupVm);
         }
         return(View(signupVms));
     }
 }
 public ActionResult Admin()
 {
     //Instantiated 'NewsletetrEntities' wraped in 'using statement' so the DB connection is closed upon completion.
     using (NewsletterEntities db = new NewsletterEntities())
     {
         var signups   = db.SignUps;
         var signupVms = new List <SignupVm>();
         foreach (var signup in signups)
         {
             var signupVm = new SignupVm();
             signupVm.FirstName    = signupVm.LastName;
             signupVm.LastName     = signupVm.FirstName;
             signupVm.EmailAddress = signupVm.EmailAddress;
             signupVms.Add(signupVm);
         }
         return(View(signupVms));
     }
 }
Ejemplo n.º 20
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                var signups   = db.SignUps.Where(x => x.Removed == null).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupvm = new SignupVm();
                    signupvm.Id           = signup.Id;
                    signupvm.FirstName    = signup.FirstName;
                    signupvm.LastName     = signup.LastName;
                    signupvm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupvm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 21
0
 // GET: Admin
 public ActionResult Index()
 {
     using (NewsletterEntities1 db = new NewsletterEntities1())
     {
         /*var signups = db.SignUps.Where(x=> x.Removed==null).ToList()*/;                 //representes all of the records in our database (a list) filtered by subscribed
         var signups   = (from c in db.SignUps where c.Removed == null select c).ToList(); //same function as before but using Linq
         var signupVMs = new List <SignupVm>();
         foreach (var signup in signups)
         {
             var signupVm = new SignupVm();
             signupVm.Id           = signup.Id;
             signupVm.FirstName    = signup.FirstName;
             signupVm.LastName     = signup.LastName;
             signupVm.EmailAddress = signup.EmailAddress;
             signupVMs.Add(signupVm);
         }
         return(View(signupVMs));
     }
 }
Ejemplo n.º 22
0
        public ActionResult Admin()
        {
            string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, Removed FROM SignUps";
            List <NewsletterSignUp> signups = new List <NewsletterSignUp>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);

                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    var signup = new NewsletterSignUp();
                    signup.Id           = Convert.ToInt32(reader["Id"]);
                    signup.FirstName    = reader["FirstName"].ToString();
                    signup.LastName     = reader["LastName"].ToString();
                    signup.EmailAddress = reader["EmailAddress"].ToString();
                    signup.Removed      = reader["Removed"].ToString(); // wwe don't want to return this

                    signups.Add(signup);
                }
            }

            var signupVms = new List <SignupVm>();  // best practice if its obvious what the data type is

            //List<SignupVm> signupVms = new List<SignupVm>();

            foreach (var signup in signups)
            {
                var signupVm = new SignupVm();
                signupVm.FirstName    = signup.FirstName;
                signupVm.LastName     = signup.LastName;
                signupVm.EmailAddress = signup.EmailAddress;
                signupVms.Add(signupVm);
            }

            return(View(signupVms));
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //NOTE: Below our, 'db' object has a property called 'SignUps' is a set of all of the records
                //      in our database stored as objects:
                //      'var signups = db.SignUps;'
                //NOTE: We don't want to list all records anymore. Now we want to be more specific see below.


                //NOTE: This line looks at the database set, 'SignUps' of 'SignUp' objects and only return those
                //      objects where  property 'Removed' is equal to null, then storing it to 'var signups'.
                //      This is done so we only render the records/objects that are still subscribed:
                //      'var signups = db.SignUps.Where(x => x.Removed == null).ToList();'

                //NOTE: on the line above we are using a lambda expression. And this is one of the advantages of
                //      using 'EntityFramework'. We can write query like logic on objects that are conveniently
                //      mapped to a database.
                //NOTE: Another way to accomplish the same resut as the lambda expression above is by using
                //      Linq - Language Integrated Query:
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                //NOTE: Using 'View Model' is considered best practice in order to map eveything that needs to get
                //      mapped in the database without having to map it to objects that will be shown in views.
                //      In our example, SSN is a perfect example of what is important to map, and what is important
                //      to not show that information to any user.
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
Ejemplo n.º 24
0
        //private ShoppingEntities1 db = new ShoppingEntities1();

        public ActionResult Index()
        {
            using (ShoppingEntities1 db = new ShoppingEntities1())
            {
                var signups = (from c in db.ShoppingLists
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id    = signup.Id;
                    signupVm.Item  = signup.Item;
                    signupVm.Store = signup.Store;
                    signupVm.Cost  = signup.Cost;

                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id = signup.Id; // pass to view model which is being passed to the view

                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Signup([FromBody] SignupVm signupVm)
        {
            //check if user already exists
            var existingUser = await _accountService.GetUser(signupVm.Email);

            if (existingUser != null)
            {
                return(new BadRequestObjectResult(AccountError.UserAlreadyExist));
            }

            //create passwordhash for storing in db
            var passwordHash = _passwordHasher.GenerateIdentityV3Hash(signupVm.Password);

            var user = _mapper.Map <User>(signupVm);

            user.PasswordHash = passwordHash;
            user.Type         = UserType.Doctor; // assuming only doctor will use this service to register

            var newUserId = await _accountService.AddUser(user);

            return(Ok(newUserId));
        }
Ejemplo n.º 27
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();         ****This is the Lamda syntax that works, but another way could be LINQ which is shown below, LINQ stands for Language Intergrated Query****
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Create new Rest users.
        /// </summary>
        /// <param name="user">Signup View Model</param>
        /// <returns>UserVm</returns>
        public (UserVm User, string Message) Create(SignupVm user)
        {
            if (string.IsNullOrWhiteSpace(user.DisplayName))
            {
                return(null, "Display name length must have atleast 1 character in it.");
            }

            if (user.Password != user.ConfirmPassword)
            {
                return(null, "Confirm password did not match.");
            }

            var resp = Post <UserVm>(API_MEMBER_BASE + "CreateMember/", new
            {
                username    = user.Username,
                password    = user.Password,
                email       = user.Username,
                displayname = user.DisplayName
            });

            return(resp.Response, resp.Message);
        }
Ejemplo n.º 29
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();                 //solution using lamda
                var signups = (from c in db.SignUps               //solution using linq
                               where c.Removed == null
                               select c).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)                 //displa
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
Ejemplo n.º 30
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                // var signups = db.signups.Where(x => x.Removed == null).ToList(); *filter - removing the ones that have unsubscribed*
                var signups = (from c in db.signups
                               where c.Removed == null
                               select c).ToList();
                var SignupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.Emailaddress = signup.EmailAddress;
                    SignupVms.Add(signupVm);
                }

                return(View(SignupVms));
            }
        }