<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity.JsonModel;
using Newtonsoft.Json.Linq;

namespace Entity.Helper
{
    public class ProductHelper : BaseEntityHelper
    {
        public ICollection<Product> GetAllProduct()
        {
            return db.Products.ToList<Product>();
        }

        public ICollection<Product> GetProductByCaterory(int categoryId)
        {
            return db.Products
                .Where(product => product.categoryID == categoryId)
                .ToList<Product>();
        }

        public bool CreateProduct(string name,int categoryID, Decimal unitPrice, Uri image)
        {
//            Product product = new Product
//            {
////                name = 
//            };
            throw new NotImplementedException();
        }
    }
}<commit_msg>Add update product<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity.JsonModel;
using Newtonsoft.Json.Linq;

namespace Entity.Helper
{
    public class ProductHelper : BaseEntityHelper
    {
        public ICollection<Product> GetAllProduct()
        {
            return db.Products.ToList();
        }

        public ICollection<Product> GetProductByCaterory(int categoryId)
        {
            return db.Products
                .Where(product => product.categoryID == categoryId)
                .ToList();
        }

        public Product CreateProduct(string name, int categoryId, Decimal unitPrice, Uri image)
        {
            try
            {
                Product product = new Product
                {
                    name = name,
                    categoryID = categoryId,
                    unitPrice = unitPrice,
                    image = Path.GetFileName(image.AbsoluteUri)
                };
                db.Products.Add(product);
                db.SaveChanges();
                return product;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public bool UpdateProduct(int id, string name, int? categoryId, decimal? unitPrice, Uri image)
        {
            try
            {
                int affectedRecord = 0;
                Product product = db.Products.Find(id);
                if (product != null)
                {
                    if (name != null)
                    {
                        product.name = name;
                    }
                    if (categoryId != null)
                    {
                        product.categoryID = categoryId;
                    }
                    if (unitPrice != null)
                    {
                        product.unitPrice = unitPrice.Value;
                    }
                    if (image != null)
                    {
                        product.image = Path.GetFileName(image.AbsoluteUri);
                    }

                    affectedRecord = db.SaveChanges();
                }
                return affectedRecord == 1;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool RemoveProduct(int id)
        {
            throw new NotImplementedException();
        }
        
        
    }
}
{'fraction_non_alphanumeric': 0.07902467685076381, 'fraction_numerical': 0.0005875440658049354, 'mean_word_length': 1.203883495145631, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6486515', 'n_tokens_mistral': 823, 'n_tokens_neox': 769, 'n_words': 180}