/// <summary> /// Initializes a new instance of the <see cref="ProductDTO"/> class. /// </summary> /// <param name="prod">The base.</param> public ProductDTO(Product prod) { this.ID = prod.ID; this.Description = prod.Description; this.Lead = prod.Lead; this.Tagline = prod.Lead; this.Title = prod.Title; this.ScreenShot = new List<byte[]>(); }
private static void AddProduct() { var client = new RestClient("http://*****:*****@"wnet\mhingley"; itemToAdd.Tagline = "Approved software store"; var request = new RestRequest("PostProduct", Method.POST); request.RequestFormat = DataFormat.Json; request.AddObject(itemToAdd); IRestResponse response = client.Execute(request); Console.WriteLine("Posting to AddProduct"); Console.WriteLine("response="); Console.WriteLine(response.Content); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != product.ID) { return BadRequest(); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = product.ID }, product); }
public ProductDTO PostProduct(Product itemToAdd) { try { if (itemToAdd.Screenshots != null && itemToAdd.Screenshots.Count == 0) { itemToAdd.Screenshots = null; } var AddedProduct = db.Products.Add(itemToAdd); db.SaveChanges(); return new ProductDTO(AddedProduct); } catch (DbEntityValidationException ex) { string BigError = ""; foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { BigError = BigError + string.Format("Property: {0} Error: {1}...", validationError.PropertyName, validationError.ErrorMessage); } } throw new Exception("Cannot add a product." + BigError, ex); } }
public bool DeleteProduct(Product productToDelete) { return true; }