Пример #1
0
 public static bool Validate(IProductCreation data)
 {
     if (string.IsNullOrWhiteSpace(data.Name))
     {
         throw new Exception("Your product needs a name");
     }
     return(true);
 }
Пример #2
0
 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;
 }
Пример #3
0
 public IProduct CreateProduct(IProductCreation data)
 {
     try
     {
         ProductValidator.Validate(data);
         return(api.CreateProduct(data));
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        /**
         * 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);
        }
Пример #6
0
        /**
         * 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);
        }
Пример #7
0
 public IProduct CreateProduct(IProductCreation data)
 {
     return(_productRepo.Create(data));
 }