public void UpdateProductOption(ProductOptionEntity productOptionEntity) { if (productOptionEntity == null || productOptionEntity.Id == null) { throw new ArgumentException("Cannot be empty", "productOptionEntity"); } try { using (var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString)) { sqlConnection.Open(); try { using (var sqlCommand = sqlConnection.ToUpdateProductOptionSqlCommand(productOptionEntity)) { sqlCommand.ExecuteNonQuery(); } } catch (Exception ex) { throw new ProviderException("Unexpected exception in UpdateProductOption", ex); } } } catch (Exception ex) { throw new ProviderException("Unexpected exception in UpdateProductOption", ex); } }
public static ProductOptionEntity ToProductOption(this SqlDataReader value) { if (!value.HasRows) { return(null); } ProductOptionEntity entity; try { entity = new ProductOptionEntity { Id = (Guid)value["Id"], ProductId = (Guid)value["ProductId"], Name = (value["Name"] != DBNull.Value) ? value["Name"].ToString() : null, Description = (value["Description"] != DBNull.Value) ? value["Description"].ToString() : null }; } catch (Exception ex) { throw new ProviderException("Unexpected exception in ToProductOption", ex); } return(entity); }
public IHttpActionResult UpdateProductOption(ProductOptionEntity option) { var response = _service.UpdateProductOption(new UpdateProductOptionRequest { ProductOptionEntity = option }); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, response))); }
public void Setup() { productOption = new ProductOptionEntity { Id = Guid.Parse("8F2E9176-35EE-4F0A-AE55-333333333333"), ProductId = Guid.Parse("8F2E9176-35EE-4F0A-AE55-83023D2DB133"), Name = "Samsung Galaxy S7", Description = "Newest mobile product from Samsung." }; _repository = new SQLProductRepository(); _service = new ProductService(_repository); }
public void UpdateProductOption() { var firstProductOption = _productOptions.First(); firstProductOption.Name = "Phone Updated"; var updatedProduct = new ProductOptionEntity() { Name = firstProductOption.Name, Id = firstProductOption.Id }; _productService.UpdateProductOption(firstProductOption.Id, updatedProduct); Assert.That(firstProductOption.Name, Is.EqualTo("Phone updated")); // Product name changed }
public bool UpdateOption(Guid id, [FromBody] ProductOptionEntity productOptionEntity) { if (id != null) { var isSuccess = _productServices.UpdateProductOption(id, productOptionEntity); if (isSuccess) { return(true); } throw new ApiDataException(1002, "Unable to update product", HttpStatusCode.NotModified); } throw new ApiException() { ErrorCode = (int)HttpStatusCode.BadRequest, ErrorDescription = "Bad Request..." }; }
public HttpResponseMessage CreateOption(Guid productId, [FromBody] ProductOptionEntity productOptionEntity) { if (productOptionEntity != null) { var id = _productServices.AddProductOption(productOptionEntity, productId); if (id != null) { return(Request.CreateResponse(HttpStatusCode.OK, id)); } throw new ApiDataException(1001, "Unable to create new product", HttpStatusCode.InternalServerError); } throw new ApiException() { ErrorCode = (int)HttpStatusCode.BadRequest, ErrorDescription = "Bad Request..." }; }
/// <summary> /// adds a new product option to the specified product. /// </summary> /// <param name="productOptionEntity"></param> /// <param name="productId"></param> /// <returns></returns> public Guid AddProductOption(ProductOptionEntity productOptionEntity, Guid productId) { using (var scope = new TransactionScope()) { var productOption = new ProductOption { Id = Guid.NewGuid(), Name = productOptionEntity.Name, Description = productOptionEntity.Description, ProductId = productId }; _unitOfWork.ProductOptionRepository.Insert(productOption); _unitOfWork.Save(); scope.Complete(); return(productOption.Id); } }
public void AddProductOption() { var firstProduct = _products.First(); var newProductOption = new ProductOptionEntity() { Id = Guid.NewGuid(), Name = "iPhone X", Description = "New iPhoneX", }; var count = _productOptions.Count; _productService.AddProductOption(newProductOption, firstProduct.Id); var addedproductOption = new ProductOption() { Name = newProductOption.Name, Id = newProductOption.Id }; Assert.That(_productOptions.Count, Is.GreaterThan(count)); }
/// <summary> /// updates the specified product option. /// </summary> /// <param name="productOptionId"></param> /// <param name="productOptionEntity"></param> /// <returns></returns> public bool UpdateProductOption(Guid productOptionId, ProductOptionEntity productOptionEntity) { var success = false; if (productOptionEntity != null) { using (var scope = new TransactionScope()) { var productOption = _unitOfWork.ProductOptionRepository.GetByID(productOptionId); if (productOption != null) { productOption.Name = productOptionEntity.Name; productOption.Description = productOptionEntity.Description; _unitOfWork.ProductOptionRepository.Update(productOption); _unitOfWork.Save(); scope.Complete(); success = true; } } } return(success); }
public void Update(ProductOptionEntity option) { Execute("dbo.SPUpdateProductOption", new { productOptionId = option.ProductOptionId, description = option.Description, qty = option.Qty, net = option.Detail.Net, productDetailFlags = (int?)option.Detail.Flags }); }
public static SqlCommand ToInsertProductOptionSqlCommand(this SqlConnection sqlConnection, ProductOptionEntity productOptionEntity) { var sqlCommand = new SqlCommand { CommandText = "[dbo].[psp_InsertProductOption]", CommandType = CommandType.StoredProcedure, Connection = sqlConnection }; sqlCommand.Parameters.Add( new SqlParameter("@Id", SqlDbType.UniqueIdentifier) { Value = (productOptionEntity.Id != null || productOptionEntity.Id != Guid.Empty) ? productOptionEntity.Id as object : DBNull.Value as object }); sqlCommand.Parameters.Add( new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier) { Value = (productOptionEntity.ProductId != null || productOptionEntity.ProductId != Guid.Empty) ? productOptionEntity.ProductId as object : DBNull.Value as object }); sqlCommand.Parameters.Add( new SqlParameter("@Name", SqlDbType.VarChar) { Value = (!string.IsNullOrEmpty(productOptionEntity.Name)) ? productOptionEntity.Name as object : DBNull.Value as object }); sqlCommand.Parameters.Add( new SqlParameter("@Description", SqlDbType.VarChar) { Value = (!string.IsNullOrEmpty(productOptionEntity.Description)) ? productOptionEntity.Description as object : DBNull.Value as object }); return(sqlCommand); }