Example #1
0
 public void Delete(int id)
 {
     using (var db = new ComputerPartsContext())
     {
         var computerParts = new ComputerParts {
             Id = id
         };
         db.ComputerParts.Attach(computerParts);
         db.ComputerParts.Remove(computerParts);
         db.SaveChanges();
     }
 }
Example #2
0
 public void Update(int id, ComputerPartDetailDTO detail)
 {
     using (var db = new ComputerPartsContext())
     {
         var partToEdit = db.ComputerParts.Where(a => a.Id == id).SingleOrDefault();
         if (partToEdit != null)
         {
             partToEdit.Description = detail.Description;
             partToEdit.Condition   = detail.Condition;
             partToEdit.PartType    = detail.PartType;
             partToEdit.Location    = detail.Location;
             partToEdit.Price       = detail.Price;
             partToEdit.Remarks     = detail.Remarks;
             db.SaveChanges();
         }
     }
 }
Example #3
0
        public int Append(ComputerPartDetailDTO computerPart)
        {
            int id = -1;

            using (var db = new ComputerPartsContext())
            {
                ComputerParts computerParts = new ComputerParts
                {
                    Description = computerPart.Description,
                    Condition   = computerPart.Condition,
                    PartType    = computerPart.PartType,
                    Location    = computerPart.Location,
                    Price       = computerPart.Price,
                    Remarks     = computerPart.Remarks
                };
                db.ComputerParts.Add(computerParts);
                db.SaveChanges();
                id = computerParts.Id;
            }
            return(id);
        }