コード例 #1
0
 partial void DeletePrice(Price instance);
コード例 #2
0
 partial void UpdatePrice(Price instance);
コード例 #3
0
        public bool CreatePrice(string name, string image, string description, string path)
        {
            using (MasterDBDataContext db = new MasterDBDataContext())
            {
                Price price = new Price() {
                    Name = name,
                    Image = image,
                    Description = description,
                    Path = path
                };

                db.Price.InsertOnSubmit(price);

                try
                {
                    db.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR CreatePrice " + ex.Message);
                }

                return false;
            }
        }
コード例 #4
0
 partial void InsertPrice(Price instance);
コード例 #5
0
        public int CreateOrUpdatePrice(int id, string name, byte[] image, byte[] asset, string description)
        {
            using (MasterDBDataContext db = new MasterDBDataContext())
            {
                Price price = null;
                if (id == 0)
                {
                    price = new Price()
                    {
                        Name = name,
                        Image = "",
                        Path = "",
                        Description = description
                    };

                    db.Price.InsertOnSubmit(price);
                }
                else
                {
                    price = db.Price.SingleOrDefault(e => e.idPrice == id);

                    if (name != "")
                        price.Name = name;

                    if (description != "")
                        price.Description = description;
                }
                try
                {
                    if (image != null || asset != null)
                    {
                        if (id == 0)
                            db.SubmitChanges();

                        string path = IMAGE_PATH + "prices\\" + price.idPrice + "-" + price.Name;
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(IMAGE_PATH + "prices\\" + price.idPrice + "-" + price.Name);

                        if (image != null)
                        {
                            using (FileStream fs = new FileStream(path + "\\" + "cover", FileMode.OpenOrCreate, FileAccess.Write))
                            {
                                fs.Write(image, 0, image.Length);
                                price.Image = path + "\\" + "cover";
                            }
                        }

                        if (asset != null)
                        {
                            using (FileStream fs = new FileStream(path + "\\" + "asset", FileMode.OpenOrCreate, FileAccess.Write))
                            {
                                fs.Write(asset, 0, asset.Length);
                                price.Path = path + "\\" + "asset";
                            }
                        }
                    }

                    db.SubmitChanges();

                    return price.idPrice;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR CreateEvent " + ex.Message);
                    return -1;
                }
            }
        }