Esempio n. 1
0
        public void Insert_A_New_User()
        {
            var user = new User
            {
                Email = "*****@*****.**",
                Password = "******",
                PIN = "04.137.077/0007-27",
                ReceivePromotions = false,
                CallSpecialist = true,
                CompanyName = "Netbiis",
                Adress = new Adress
                {
                    City = "s. jose do rio preto",
                    Number = 1245,
                    State = "sp",
                    StreetName = "portal",
                    Suite = "abc",
                    Zipcode = "1234"
                },
                Contact = new Contact
                {
                    MainContact = "Talita",
                    Phone = "22 2222 2222",
                    Position = "s"
                }
            };

            var rows = _userRepository.Save(user);

            Assert.AreEqual(rows, 1);
        }
Esempio n. 2
0
        public int Save(User user)
        {
            var connectionString = _ctx.Database.Connection.ConnectionString;
            var numberOfRow = 0;

            using (var con = new SqlConnection(connectionString))
            {
                try
                {
                    con.Open();

                    var parameters = new[] {
                        new SqlParameter("@PIN", SqlDbType.Text) {
                            Value = user.PIN
                        },
                        new SqlParameter("@CompanyName", SqlDbType.Text){
                            Value = user.CompanyName
                        },
                        new SqlParameter("@Email", SqlDbType.Text){
                            Value = user.Email
                        },
                        new SqlParameter("@Password", SqlDbType.Text){
                            Value = user.Password
                        },
                        new SqlParameter("@ReceivePromotions", SqlDbType.Bit){
                            SqlValue = user.ReceivePromotions
                        },
                        new SqlParameter("@CallSpecialist", SqlDbType.Bit){
                            SqlValue = user.CallSpecialist
                        },
                        new SqlParameter("@Number", SqlDbType.Int){
                            SqlValue = user.Adress.Number
                        },
                        new SqlParameter("@StreetName", SqlDbType.Text){
                            Value = user.Adress.StreetName
                        },
                        new SqlParameter("@Suite", SqlDbType.Text){
                            Value = user.Adress.Suite
                        },
                        new SqlParameter("@City", SqlDbType.Text){
                            Value = user.Adress.City
                        },
                        new SqlParameter("@State", SqlDbType.Text){
                            Value = user.Adress.State
                        },
                        new SqlParameter("@Zipcode", SqlDbType.Text){
                            Value = user.Adress.Zipcode
                        },
                        new SqlParameter("@MainContact", SqlDbType.Text){
                            Value = user.Contact.MainContact
                        },
                        new SqlParameter("@Position", SqlDbType.Text){
                            Value = user.Contact.Position
                        },
                        new SqlParameter("@Phone", SqlDbType.Text){
                            Value = user.Contact.Phone
                        }
                    };

                    var command = new SqlCommand("InsertUser", con);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(parameters);

                    numberOfRow= command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    con.Close();
                }
            }

            return numberOfRow;
        }
Esempio n. 3
0
        public ActionResult Index(User user)
        {
            _userRepository.Save(user);

            return View();
        }