public static bool Validate(IProductCreation data) { if (string.IsNullOrWhiteSpace(data.Name)) { throw new Exception("Your product needs a name"); } return(true); }
public Product(IProductCreation data) { Id = Guid.NewGuid().ToString(); Name = data.Name; Description = data.Description; Img = data.Img; IsPublic = data.IsPublic; CreatorId = data.CreatorId; CreatedTimestamp = DateTime.UtcNow; }
public IProduct CreateProduct(IProductCreation data) { try { ProductValidator.Validate(data); return(api.CreateProduct(data)); } catch (Exception) { throw; } }
public static bool Validate(IProductCreation data) { if (string.IsNullOrWhiteSpace(data.Name)) { throw new FormatException("[BAD NAME] Please provide a name for the product"); } if (data.Name == "Hello Kitty") { throw new Exception("No kitties please"); } return(true); }
/** * CREATE * READ * UPDATE * DESTROY */ internal IProduct Create(IProductCreation data) { var newProduct = new Product(data); var successful = _db.Execute(@" INSERT INTO products (id, name, description, img, ispublic, creatorid, createdtimestamp) VALUES (@Id, @Name, @Description, @Img, @IsPublic, @CreatorId, @CreatedTimestamp); ", newProduct); if (successful == 1) { return(newProduct); } return(null); }
/** * CREATE * READ * UPDATE * DESTROY */ public IProduct Create(IProductCreation data) { var newProduct = new Product { Id = Guid.NewGuid().ToString(), Name = data.Name, Description = data.Description, Img = data.Img, CreatorId = data.CreatorId, IsPublic = data.IsPublic, CreatedTimestamp = DateTimeOffset.Now }; var successful = _db.ExecuteAsync(@" INSERT INTO products (id, name, description, img, isPublic, creatorId, createdTimestamp) VALUES (@Id, @Name, @Description, @Img, @IsPublic, @CreatorId, @CreatedTimestamp); ", newProduct); if (successful.Result == 1) { return(newProduct); } return(null); }
public IProduct CreateProduct(IProductCreation data) { return(_productRepo.Create(data)); }