예제 #1
0
파일: Program.cs 프로젝트: jmibarrad/Sales
        static void Main(string[] args)
        {
            string connectionString = ConnectionStrings.Get();

            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(connectionString));

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            dd.Drop();
            Console.WriteLine("Database dropped.");
            Thread.Sleep(1000);

            dd.Create();
            Console.WriteLine("Database created.");

            ISession session = sessionFactory.OpenSession();

            using (ITransaction tx = session.BeginTransaction())
            {
                dd.Seed(new List <IDataSeeder>
                {
                    new AccountSeeder(session),
                });
                tx.Commit();
            }
            session.Close();
            sessionFactory.Close();
            Console.WriteLine("Seed data added.");
            Thread.Sleep(2000);
        }
예제 #2
0
 public static bool Login(string email, string password)
 {
     try
     {
         using (var session = SessionFactoryBuilder.OpenSession())
         {
             var accountObj = session.QueryOver <Customer>().Where(x => x.Email == email).List();
             if (accountObj != null && accountObj.Count > 0)
             {
                 if (accountObj[0].Password == password) //hash tutulacak
                 {
                     return(true);                       //json formatında dönülecek
                 }
             }
             return(false);
             //json formatında dönülecek
         }
     }
     catch (Exception ex)
     {
         //log atılacak.
         //json formatında dönülecek
         return(false);
     }
 }
예제 #3
0
 public static int CreateCoupon(string email) //yeni yelik oluşturulurken bu metod çağrılır.
 {
     try
     {
         int discount = 0;
         using (var session = SessionFactoryBuilder.OpenSession())
         {
             var customerList = session.QueryOver <Customer>().Where(x => x.Email == email).List();
             if (customerList.Count == 0)
             {
                 Coupon couponObj = new Coupon();
                 couponObj.CustomerId = customerList[0].Id;
                 couponObj.Discount   = 5; //%5 hesabı yapılabilir.
                 session.Save(couponObj);
                 session.Clear();
             }
             return(discount);//json formatında başarılı sonuç dönülecek.
         }
     }
     catch (Exception ex)
     {
         //rollback yapılacak.
         //log atılacak.
         return(0); //json formatında hata dönülecek.
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.FromConnectionStringWithKey("CrudGesitonContenido.Local"));

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            dd.Drop();
            Console.WriteLine("Database dropped.");
            Thread.Sleep(1000);

            dd.Create();
            Console.WriteLine("Database created.");

            ISession session = sessionFactory.OpenSession();

            using (ITransaction tx = session.BeginTransaction())
            {
                dd.Seed(new List <IDataSeeder>
                {
                    new DepartamentoSeeder(session)
                });
                tx.Commit();
            }

            session.Close();
            sessionFactory.Close();
            Console.WriteLine("Seed data added.");
            Thread.Sleep(2000);
        }
예제 #5
0
        public static List <BookingModel> SaveBooking(BookingModel bookingData = null)
        {
            var dbBooking = new Booking();

            dbBooking.Id           = bookingData.Id;
            dbBooking.Name         = bookingData.Name;
            dbBooking.CreationDate = DateTime.Now;
            dbBooking.UpdatedDate  = DateTime.Now;
            //dbBooking.BookingParts = new List<BookingPart>();

            bookingData.BookingParts.ForEach(bpt =>
            {
                dbBooking.Add(new BookingPart
                {
                    Id           = bpt.Id,
                    CreationDate = DateTime.Now,
                    CreationTime = DateTime.Now,
                    Status       = 2,
                    Description  = bpt.Description,
                    Title        = bpt.Title,
                    UpdatedDate  = DateTime.Now,
                });
            });

            using (var session = SessionFactoryBuilder.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(dbBooking);
                    transaction.Commit();
                }
            }

            return(GetBookings());
        }
예제 #6
0
        public static List <Product> GetProductList()
        {
            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    var productList = session.Query <Product>().ToList();
                    if (productList != null && productList.Count > 0)
                    {
                        foreach (Product productItem in productList.ToList())
                        {
                            if (productItem.Stock == 0)
                            {
                                productList.Remove(productItem);
                            }
                        }
                    }

                    return(productList); //json formatında dönülecek
                }
            }
            catch (Exception ex)
            {
                //log atılacak.
                return(null); //json formatında dönülecek
            }
        }
        public static bool CreateOrder(int customerId, int addressId)
        {
            decimal totalPrice = 0;

            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    var cartList = session.QueryOver <Cart>().Where(x => x.CustomerId == customerId && x.Status == 1).List();
                    foreach (var cartItem in cartList)
                    {
                        Order orderObj = new Order();
                        orderObj.CustomerId = customerId;
                        orderObj.ProductId  = cartItem.ProductId;
                        orderObj.UnitPrice  = cartItem.UnitPrice;
                        if (cartItem.Quantity > 1)
                        {
                            orderObj.TotalPrice = cartItem.Quantity * cartItem.UnitPrice;
                        }
                        else
                        {
                            orderObj.TotalPrice = cartItem.UnitPrice;
                        }
                        orderObj.Status         = 1;//sipariş tamamlandı.
                        orderObj.AddressId      = addressId;
                        orderObj.InsertDatetime = System.DateTime.Now;
                        session.Save(orderObj);
                        session.Clear();
                        cartItem.Status = 0;
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            session.Clear();
                            session.SaveOrUpdate(cartItem);
                            transaction.Commit();
                        }
                        totalPrice += orderObj.UnitPrice;
                    }

                    var couponList = session.QueryOver <Coupon>().Where(x => x.CustomerId == customerId && x.Status == 1).List();
                    if (couponList.Count > 0)
                    {
                        totalPrice = totalPrice - (totalPrice * couponList[0].Discount / 100); //CartDetail tablosu yapılarak toplam fiyattan düşülebilir.
                    }
                }
                return(true); //json formatında dönülecek
            }
            catch (Exception ex)
            {
                //rollback yapılacak.
                //log atılacak.
                //json formatında dönülecek
                return(false);
            }
        }
예제 #8
0
        public void Database_schema_should_be_updated_if_requested()
        {
            var nhibernateProperties = SQLiteConfiguration.Standard
                                       .UsingFile(Path.GetTempFileName())
                                       .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName)
                                       .ToProperties();

            var sessionFactory = new SessionFactoryBuilder(typeof(TestSaga).Assembly.GetTypes())
                                 .Build(nhibernateProperties, true);

            using (var session = sessionFactory.OpenSession())
            {
                session.CreateCriteria(typeof(TestSaga)).List <TestSaga>();
            }
        }
예제 #9
0
        private static void Main(string[] args)
        {
            try
            {
                string connectionString = ConnectionStrings.Get();

                MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                           ConnectionString(x => x.Is(connectionString));

                DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
                ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                                 .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

                dd.Drop();
                Console.WriteLine("Database dropped.");
                Thread.Sleep(1000);

                dd.Create();
                Console.WriteLine("Database created.");

                ISession session = sessionFactory.OpenSession();
                using (ITransaction tx = session.BeginTransaction())
                {
                    dd.Seed(new List <IDataSeeder>
                    {
                        new UserSeeder(session),
                        new ProjectEntitySeeder(session),
                        new UserTypeEntitySeeder(session),
                        new UserHistoryEntitySeeder(session)
                    });
                    tx.Commit();
                }
                session.Close();
                sessionFactory.Close();
                Console.WriteLine("Seed data added.");
                Thread.Sleep(2000);
            }
            catch (Exception ex)
            {
                String innerMessage = (ex.InnerException != null)
                              ? ex.InnerException.Message
                              : "";
                Console.WriteLine(ex.Message);
                Console.WriteLine(innerMessage);
                string n = Console.ReadLine();
            }
        }
 public static List <Cart> GetCartDetail(int customerId)
 {
     try
     {
         List <Cart> cartItems = new List <Cart>();
         using (var session = SessionFactoryBuilder.OpenSession())
         {
             cartItems = (List <Cart>)session.QueryOver <Cart>().Where(x => x.CustomerId == customerId && x.Status == 1).List();
         }
         return(cartItems); //json formatında dönülecek
     }
     catch (Exception ex)
     {
         //log atılacak.
         return(null); //json formatında dönülecek
     }
 }
        } //websitesinden sepete ekle yapıldığında sadece eklendi mesajı dönüyor ekleme işlemi yapılmıyor. Web sitesindeki product Id bilgilerinin gönderilmesi gerek.

        public static bool DeleteFromCart(int customerId, int productId)
        {
            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    var cartItems = session.QueryOver <Cart>().Where(x => x.CustomerId == customerId && x.ProductId == productId && x.Status == 1).List();
                    session.Delete(cartItems[0]);
                }
                return(true); //json formatında dönülecek
            }
            catch (Exception ex)
            {
                //rollback yapılacak.
                //log atılacak.
                return(false); //json formatında dönülecek
            }
        }
        public void Database_schema_should_be_updated_if_requested()
        {
            var nhibernateProperties = SQLiteConfiguration.UsingFile(Path.GetTempFileName());

            File.WriteAllText("sqlite.txt", "");

            foreach (var property in nhibernateProperties)
            {
                File.AppendAllText("sqlite.txt", String.Format("{{ \"{0}\", \"{1}\" }}\n", property.Key, property.Value));
            }

            var sessionFactory = new SessionFactoryBuilder(typeof(TestSaga).Assembly.GetTypes())
                                 .Build(nhibernateProperties, true);

            using (var session = sessionFactory.OpenSession())
            {
                session.CreateCriteria(typeof(TestSaga)).List <TestSaga>();
            }
        }
        public static bool AddToCart(int productId, string email)
        {
            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    int discount     = 0;
                    var productList  = session.QueryOver <Product>().Where(x => x.Id == productId).List();
                    var customerList = session.QueryOver <Customer>().Where(x => x.Email == email).List();

                    var cartList = session.QueryOver <Cart>().Where(x => x.CustomerId == customerList[0].Id && x.Status == 1).List();
                    if (productList != null && productList.Count > 0)
                    {
                        if (cartList != null && cartList.Count == 0)
                        {
                            CreateNewCart(session, productList[0], customerList[0].Id);
                        }
                        else
                        {
                            CreateOrUpdateCart(session, cartList[0], productList[0], productId, customerList[0].Id);
                        }

                        if (discount > 0)
                        {
                            cartList[0].TotalPrice = cartList[0].TotalPrice - (cartList[0].TotalPrice * discount / 100);
                            session.SaveOrUpdate(cartList[0]);
                            session.Clear();
                        }
                    }
                    return(true); //json formatında dönülecek
                }
            }
            catch (Exception ex)
            {
                //rollback yapılacak.
                //log atılacak.
                return(false); //json formatında dönülecek
            }
        } //websitesinden sepete ekle yapıldığında sadece eklendi mesajı dönüyor ekleme işlemi yapılmıyor. Web sitesindeki product Id bilgilerinin gönderilmesi gerek.
예제 #14
0
        static void Main(string[] args)
        {
            args = args.Select(x => x.ToLower()).ToArray();
            bool noArgs = !args.Any();

            ConnectionStringSettings connectionStringSettings = ConnectionStrings.Get();
            MsSqlConfiguration       databaseConfiguration    =
                MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(
                    x => x.Is(connectionStringSettings.ConnectionString))
                .Dialect <MsSqlAzureDialect>();

            CreateDatabaseIfNotExists(connectionStringSettings);

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration, new EntityInterceptor())
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            if (noArgs || args.Contains("drop"))
            {
                using (ISession sess = sessionFactory.OpenSession())
                {
                    using (IDbCommand cmd = sess.Connection.CreateCommand())
                    {
                        cmd.ExecuteSqlFile("dropForeignKeys.sql");
                        //cmd.ExecuteSqlFile("dropPrimaryKeys.sql");
                        cmd.ExecuteSqlFile("dropTables.sql");
                    }
                }
                dd.Drop();
                Console.WriteLine("");
                Console.WriteLine("Database dropped.");
            }

            if (noArgs || args.Contains("create"))
            {
                dd.Create();
                Console.WriteLine("");
                Console.WriteLine("Database created.");
            }
            else if (args.Contains("update"))
            {
                dd.Update();
                Console.WriteLine("");
                Console.WriteLine("Database updated.");
            }

            if (noArgs || args.Contains("seed"))
            {
                ISession session = sessionFactory.OpenSession();
                using (ITransaction tx = session.BeginTransaction())
                {
                    dd.Seed(new List <IDataSeeder>
                    {
                        //add data seeders here.
                        new UserSeeder(session)
                    });
                    tx.Commit();
                }
                session.Close();
                sessionFactory.Close();
                Console.WriteLine("");
                Console.WriteLine("Seed data added.");
            }

            Console.WriteLine("Done");
        }
예제 #15
0
        public static List <BookingModel> GetBookings(Booking book = null)
        {
            using (var session = SessionFactoryBuilder.OpenSession())
            {
                var bookings = session.Query <Booking>().ToList();

                var bookingsModel = new List <BookingModel>();
                bookings.ForEach(booking =>
                {
                    var tempModel = new BookingModel
                    {
                        Id           = booking.Id,
                        Name         = booking.Name,
                        CreationDate = booking.CreationDate,
                        UpdatedDate  = booking.UpdatedDate,
                    };
                    tempModel.BookingParts = new List <BookingPartModel>();
                    booking.BookingParts.ToList().ForEach(bpt =>
                    {
                        tempModel.BookingParts.Add(new BookingPartModel
                        {
                            Id           = bpt.Id,
                            Title        = bpt.Title,
                            Status       = bpt.Status.ToString(),
                            CreationDate = bpt.CreationDate,
                            Description  = bpt.Description,
                            UpdatedDate  = bpt.UpdatedDate,
                            CreationTime = bpt.CreationTime
                        });
                    });

                    bookingsModel.Add(tempModel);
                });

                return(bookingsModel);
            }

            //using (var session = SessionFactoryBuilder.OpenSession())
            //{
            //    using (ITransaction transaction = session.BeginTransaction())
            //    {
            //        session.Save(new BookingPart { });
            //        transaction.Commit();
            //    }
            //}

            //var sessionFactory = SessionFactoryBuilder.BuildSessionFactory(true, true);
            //using (var session = sessionFactory.OpenSession())
            //{
            //    // populate the database
            //    //using (var transaction = session.BeginTransaction())
            //    //{
            //    //    // create a couple of Persons
            //    //    var person1 = new Person
            //    //    {
            //    //        Name = "Rayen Trabelsi"
            //    //    };
            //    //    var person2 = new Person
            //    //    {
            //    //        Name = "Mohamed Trabelsi"
            //    //    };
            //    //    var person3 = new Person
            //    //    {
            //    //        Name = "Hamida Rebai"
            //    //    };
            //    //    //create tasks
            //    //    var task1 = new Task
            //    //    {
            //    //        Title = "Task 1",
            //    //        State = TaskState.Open,
            //    //        AssignedTo = person1
            //    //    };
            //    //    var task2 = new Task
            //    //    {
            //    //        Title = "Task 2",
            //    //        State = TaskState.Closed,
            //    //        AssignedTo = person2
            //    //    };
            //    //    var task3 = new Task
            //    //    {
            //    //        Title = "Task 3",
            //    //        State = TaskState.Closed,
            //    //        AssignedTo = person3
            //    //    };
            //    //    // save both stores, this saves everything else via cascading
            //    //    session.SaveOrUpdate(task1);
            //    //    session.SaveOrUpdate(task2);
            //    //    session.SaveOrUpdate(task3);
            //    //    transaction.Commit();
            //    //}
            //    using (var session2 = sessionFactory.OpenSession())
            //    {
            //        //retreive all tasks with person assigned to
            //        using (session2.BeginTransaction())
            //        {
            //            var bookingParts = session.CreateCriteria(typeof(Booking)).List<Booking>();
            //            return bookingParts.ToList();

            //        }
            //    }

            //}

            //return new List<Booking>();
        }