Exemple #1
0
        public List <VMake> GetMakes()
        {
            List <VMake> _vMakes = new List <VMake>();

            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["CarDealership"].ConnectionString;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "GetMakes";

                conn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        VMake currentRow = new VMake();


                        currentRow.Make    = dr["Make"].ToString();
                        currentRow.MakeId  = (int)dr["MakeId"];
                        currentRow.AddedBy = dr["AddedBy"].ToString();
                        //  currentRow.DateAdded = (DateTime)dr["DateAdded"];
                        _vMakes.Add(currentRow);
                    }
                }
            }
            return(_vMakes);
        }
Exemple #2
0
        public async Task <bool> AddItemAsync(VMake newMake)
        {
            _db.Makes.Add(newMake);
            var saveResult = await _db.SaveChangesAsync();

            return(saveResult == 1);
        }
Exemple #3
0
        public async Task <IActionResult> Upsert(VMake newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            var scs = await _db.AddItemAsync(newItem);

            if (!scs)
            {
                return(BadRequest("Item was not added"));
            }
            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public int CheckSum()
        {
            int ret = 0;

            ret += VMake.CalCheckSum();
            ret += VModel.CalCheckSum();
            ret += VYear.CalCheckSum();
            ret += VType.ToDescription().CalCheckSum();
            ret += VVIN.CalCheckSum();
            ret += VRegion.CalCheckSum();
            ret += VLocation.CalCheckSum();
            ret += VStatus.ToString().CalCheckSum();

            return(ret);
        }
Exemple #5
0
        public void AddMake(VMake make)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["CarDealership"].ConnectionString;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "AddMake";

                cmd.Parameters.AddWithValue("@Make", make.Make);
                cmd.Parameters.AddWithValue("@AddedBy", make.AddedBy);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
 public ActionResult CreateMake(VMake make)
 {
     make.AddedBy = System.Web.HttpContext.Current.User.Identity.GetUserName().ToString();
     _carRepository.AddMake(make);
     return(RedirectToAction("Makes", "Admin"));
 }