public Hardware Add(Hardware hardware) { // Save hardware Hardware hardwareSaved = repository.Add(hardware); //Create the empty ProductDetails as pre-defined List <Detail> details = repositoryDetail.GetAllDetails(); foreach (var detail in details) { if (detail.SelectProductTypes != null) { foreach (var selectProductType in detail.SelectProductTypes) { if (selectProductType == hardwareSaved.ProductTypeID) { ProductDetail productDetail = new ProductDetail(); productDetail.ProductID = hardwareSaved.ProductID; productDetail.DetailID = detail.DetailID; productDetail.Definition1 = ""; productDetail.Definition2 = ""; repositoryProductDetail.Add(productDetail); } } } } return(hardwareSaved); }
public HttpResponseMessage AddHardware(Hardware hardware) { try { _hardwareRepository.Add(hardware); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created); return(response); } catch (Exception) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.InternalServerError); return(response); } }
/// <summary> /// The Save /// </summary> /// <param name="entity">The entity<see cref="Hardware"/></param> /// <returns>The <see cref="ServiceResult"/></returns> public ServiceResult Save(Hardware entity) { try { if (entity.Identifier == 0) { _repository.Add(entity); } else { _repository.Update(entity); } return(new ServiceResult(true)); } catch (Exception ex) { return(new ServiceResult(false) { Error = ex.ToString() }); } }