コード例 #1
0
ファイル: RolesRepository.cs プロジェクト: Rebzilla/RebTrade
 public Role GetRoleByRoleName(string roleName)
 {
     using (TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities())
     {
         return(tm.Roles.SingleOrDefault(r => r.RoleName == roleName));
     }
 }
コード例 #2
0
 //register
 public void AddUser(User myNewUser)
 {
     using (TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities())
     {
         tm.Users.Add(myNewUser);
         tm.SaveChanges();
     }
 }
コード例 #3
0
 public void AddOrderDetails(OrderDetail od)
 {
     using (TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities())
     {
         tm.OrderDetails.Add(od);
         tm.SaveChanges();
     }
 }
コード例 #4
0
 public void AddOrder(Order o)
 {
     using (TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities())
     {
         tm.Orders.Add(o);
         tm.SaveChanges();
     }
 }
コード例 #5
0
ファイル: ConnectionClass.cs プロジェクト: Rebzilla/RebTrade
 public ConnectionClass()
 {
     Entity = new TradersMarketPlaceEntities();
 }
コード例 #6
0
        public void PlaceOrder(string username, Guid orderID, List <CartView> products)
        {
            OrdersRepository           or = new OrdersRepository();
            ProductsRepository         pr = new ProductsRepository();
            TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities();

            or.Entity = pr.Entity = tm;

            Order o = new Order();

            o.OrderID       = orderID;
            o.Username      = username;
            o.OrderDate     = DateTime.Now;
            o.OrderStatusID = 1; //Paid Status

            OrderDetail od;
            decimal     totalPrice = 0M;

            try
            {
                or.Entity.Database.Connection.Open();
                or.Transaction = pr.Transaction = or.Entity.Database.Connection.BeginTransaction();

                or.AddOrder(o);

                foreach (CartView p in products)
                {
                    od            = new OrderDetail();
                    od.OrderID    = orderID;
                    od.ProductID  = p.ProductID;
                    od.ProductQty = p.ProductQuantity;

                    totalPrice += (p.ProductPrice * p.ProductQuantity);

                    or.AddOrderDetails(od);
                    pr.DecreaseStock(p.ProductID, p.ProductQuantity);
                }

                foreach (Cart sc in pr.GetCartForUser(username))
                {
                    pr.RemoveShoppingCart(sc);
                }

                try
                {
                    //Send an email to the administrator to notify them about the commission
                    string      adminEmail = new UsersRepository().GetAdminEmail();
                    decimal     commission = 0.1M;
                    MailMessage mm         = new MailMessage();
                    mm.To.Add(adminEmail);
                    mm.From       = new MailAddress("*****@*****.**", "Trader's Marketplace");
                    mm.Subject    = "Order Commission";
                    mm.Body       = "Dear Admin, <br/><br/>An order with ID " + orderID + " has been placed.<br/>";
                    mm.Body      += "You have received 10% of the order total as a commission: &#8364;" + Math.Round(commission * (totalPrice), 2);
                    mm.Body      += "<br/><br/>Regards, <br/>Traders MarketPlace";
                    mm.IsBodyHtml = true;

                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl      = true;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Credentials    = new NetworkCredential("*****@*****.**", "fabfashadmin");
                    client.Send(mm);

                    or.Transaction.Commit();
                }
                catch (SmtpException e)
                {
                    or.Transaction.Rollback();
                }
            }
            catch (Exception ex)
            {
                or.Transaction.Rollback();
            }
            finally
            {
                or.Entity.Database.Connection.Close();
            }
        }