public static ComputerPartDetail ToCompuerPartDetail(ComputerPartDetailDTO dto) { return(new ComputerPartDetail { Id = dto.Id, Description = dto.Description, Condition = dto.Condition, Location = dto.Location, PartType = dto.PartType, Price = dto.Price, Remarks = dto.Remarks }); }
public void InitializeFields(int id) { IComputerPartsService computerPartsService = new ComputerPartsService(); // read part detail from db ComputerPartDetailDTO partDetail = computerPartsService.GetDetailsById(id); // update dialog Description = partDetail.Description; Condition = partDetail.Condition; PartType = partDetail.PartType; Price = partDetail.Price; Location = partDetail.Location; Remarks = partDetail.Remarks; }
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(); } } }
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); }