コード例 #1
0
        public IEnumerable <PartManufacturer> GetAll()
        {
            var result = new List <PartManufacturer>();

            using (_connection)
            {
                _connection.Open();

                string sql =
                    "select * from part_manufacturer";
                SqlCommand cmd = new SqlCommand(sql, _connection);
                cmd.CommandType = CommandType.Text;
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    PartManufacturer partManufacturer = new PartManufacturer()
                    {
                        Id     = (long)reader["id"],
                        Name   = (string)reader["name"],
                        Active = (bool)reader["active"]
                    };
                    result.Add(partManufacturer);
                }
            }
            return(result.AsEnumerable());
        }
コード例 #2
0
        public PartManufacturer Create(string name)
        {
            using (_connection)
            {
                _connection.Open();

                string sql =
                    "insert into part_manufacturer (name) values (@name)";
                SqlCommand cmd = new SqlCommand(sql, _connection);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();

                sql = "select * from part_manufacturer where name = @name";
                cmd = new SqlCommand(sql, _connection);
                cmd.Parameters.AddWithValue("@name", name);
                var reader = cmd.ExecuteReader();


                if (reader.Read())
                {
                    PartManufacturer partManufacturer = new PartManufacturer()
                    {
                        Id     = (long)reader["id"],
                        Name   = (string)reader["name"],
                        Active = (bool)reader["active"]
                    };
                    return(partManufacturer);
                }

                throw new Exception("Manufacturer with this name is already registered");
            }
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            PartManufacturer partManufacturer = db.PartManufacturers.Find(id);

            db.PartManufacturers.Remove(partManufacturer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,Code,CodeEsteem,CodeEsteemAlt")] PartManufacturer partManufacturer)
 {
     if (ModelState.IsValid)
     {
         partManufacturer.UpdatedDate     = DateTime.Now;
         db.Entry(partManufacturer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(partManufacturer));
 }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,Name,Code,CodeEsteem,CodeEsteemAlt")] PartManufacturer partManufacturer)
        {
            partManufacturer.CreatedDate = DateTime.Now;
            if (ModelState.IsValid)
            {
                db.PartManufacturers.Add(partManufacturer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(partManufacturer));
        }
コード例 #6
0
        // GET: PartManufacturers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartManufacturer partManufacturer = db.PartManufacturers.Find(id);

            if (partManufacturer == null)
            {
                return(HttpNotFound());
            }
            return(View(partManufacturer));
        }