public void CancelOrder(string userId)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                OrderHeader order = db.OrderHeaders.Find(Order.OrderNumber);

                if (order == null)
                {
                    return;
                }

                order.OrderStatus     = "Cancelled";
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                foreach (OrderDetail temp in Body.OrderDetails)
                {
                    temp.OrderItemStatus = "Cancelled";
                    db.Entry(temp).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Initialize(userId);
        }
        public static void SaveActivatedProducts(Custodian custodian)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                foreach (Product product in custodian.ActivatedProducts.Products)
                {
                    if (product.CustodianActivated)
                    {
                        ProductCustodian productCustodian = db.ProductCustodians
                                                            .Where(c => c.ProductNumber == product.ProductNumber &&
                                                                   c.SupplierNumber == product.SupplierNumber &&
                                                                   c.CustodianNumber == custodian.CustodianNumber)
                                                            .FirstOrDefault();
                        if (productCustodian == null)
                        {
                            productCustodian = new ProductCustodian
                            {
                                AmountLastIncreasedBySupplier = null,
                                CustodianName               = custodian.CustodianName,
                                CustodianNumber             = custodian.CustodianNumber,
                                DateLastIncreasedBySupplier = null,
                                ProductNumber               = product.ProductNumber,
                                SupplierNumber              = product.SupplierNumber,
                                QuantityOnHand              = 0,
                                StockReservedForOrders      = 0,
                                Active = true
                            };

                            db.ProductCustodians.Add(productCustodian);
                            db.SaveChanges();
                        }
                        else
                        {
                            productCustodian.Active          = true;
                            db.Entry(productCustodian).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    else if (!product.CustodianActivated)
                    {
                        ProductCustodian productCustodian = db.ProductCustodians
                                                            .Where(c => c.ProductNumber == product.ProductNumber &&
                                                                   c.SupplierNumber == product.SupplierNumber &&
                                                                   c.CustodianNumber == custodian.CustodianNumber)
                                                            .FirstOrDefault();
                        if (productCustodian == null)
                        {
                        }
                        else
                        {
                            productCustodian.Active          = false;
                            db.Entry(productCustodian).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }
        }
        public void Compare()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                // Get a list of items which are on both the Session and database
                List <OrderDetail> existingItems = Body.OrderDetails.FindAll(c => c.ItemNumber != 0);

                if (existingItems != null && existingItems.Count > 0)
                {
                    foreach (OrderDetail temp in existingItems)
                    {
                        OrderDetail tempDb = db.OrderDetails.Find(temp.ItemNumber);

                        if (tempDb != null)
                        {
                            if (!temp.Equals(tempDb))
                            {
                                // If the item has changed update it
                                tempDb.Quantity       = temp.Quantity;
                                tempDb.OrderItemValue = temp.OrderItemValue;

                                db.Entry(tempDb).State = EntityState.Modified;
                                db.SaveChanges();

                                AuditUser.LogAudit(7, string.Format("Order number: {0}", Order.OrderNumber));
                            }
                        }
                    }
                }

                // Get a list of items that are on the Session variable but not in the database
                List <OrderDetail> newItems = Body.OrderDetails.FindAll(c => c.ItemNumber == 0);

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (OrderDetail tempB in newItems)
                    {
                        tempB.OrderNumber = Order.OrderNumber;

                        ReserveStock(tempB.ProductNumber, tempB.SupplierNumber, (int)tempB.CustodianNumber, tempB.Quantity, tempB.SizeType);

                        db.OrderDetails.Add(tempB);
                    }

                    db.SaveChanges();

                    AuditUser.LogAudit(7, string.Format("Order number: {0}", Order.OrderNumber));
                }

                // Ensure the latest prices are used
                UpdatePrices();
            }
        }
        public static FreeMarketResult AddAddress(string userId, string addressName, string addressLine1, string addressLine2,
                                                  string addressLine3, string addressLine4, string addressSuburb, string addressCity, string addressPostalCode)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                CustomerAddress address = new CustomerAddress()
                {
                    CustomerNumber    = userId,
                    AddressName       = addressName,
                    AddressLine1      = addressLine1,
                    AddressLine2      = addressLine2,
                    AddressLine3      = addressLine3,
                    AddressLine4      = addressLine4,
                    AddressCity       = addressCity,
                    AddressPostalCode = addressPostalCode,
                    AddressSuburb     = addressSuburb
                };

                db.CustomerAddresses.Add(address);
                db.SaveChanges();

                AuditUser.LogAudit(5, string.Format("Address name: {0}", addressName), userId);
            }

            return(FreeMarketResult.Success);
        }
        private FreeMarketResult RemoveItemFromDatabase(int itemNumber, string userId = null)
        {
            FreeMarketResult result = FreeMarketResult.NoResult;

            if (itemNumber != 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    OrderDetail item = db.OrderDetails.Find(itemNumber);

                    if (item != null)
                    {
                        FreeStock(item.ProductNumber, item.SupplierNumber, (int)item.CustodianNumber, item.Quantity, item.SizeType);

                        db.OrderDetails.Remove(item);
                        db.SaveChanges();

                        AuditUser.LogAudit(8, string.Format("Order number: {0}", Order.OrderNumber), userId);

                        result = FreeMarketResult.Success;
                    }
                    else
                    {
                        result = FreeMarketResult.Failure;
                    }
                }
            }
            else
            {
                result = FreeMarketResult.Success;
            }

            return(result);
        }
        public void Save(string userId = null)
        {
            if (Order.OrderNumber == 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    db.OrderHeaders.Add(Order);
                    db.SaveChanges();
                }
            }

            // Compare the Session cart to the database cart and resolve differences
            Compare();

            // Re-initialize the Body
            Body = CartBody.GetDetailsForShoppingCart(Order.OrderNumber);

            // Keep the total order value in sync
            UpdateTotal();

            // Save the Order total
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Entry(Order).State = EntityState.Modified;
                db.SaveChanges();
            }

            AuditUser.LogAudit(6, string.Format("Order number: {0}", Order.OrderNumber), userId);
        }
Ejemplo n.º 7
0
        public static async void LogExceptionAsync(Exception e)
        {
            var currentUserName = HttpContext.Current.User.Identity.GetUserId() ?? "Anonymous";

            ExceptionLogging ex = new ExceptionLogging()
            {
                DateTime   = System.DateTime.Now,
                Identity   = currentUserName,
                Message    = e.Message,
                StackTrace = e.StackTrace
            };

            try
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    db.ExceptionLoggings.Add(ex);
                    db.SaveChanges();
                }
            }
            catch
            {
                // Could not log error
                ex.ExceptionNumber = 999;
            }
            finally
            {
                if ((ConfigurationManager.AppSettings["notifyDeveloperOfExceptions"]) == "true")
                {
                    await NotifyDeveloperAsync(ex);
                }
            }
        }
Ejemplo n.º 8
0
        public static void LogException(Exception e)
        {
            var currentUserName = HttpContext.Current.User.Identity.GetUserId() ?? "Anonymous";

            ExceptionLogging ex = new ExceptionLogging()
            {
                DateTime   = System.DateTime.Now,
                Identity   = currentUserName,
                Message    = e.Message,
                StackTrace = e.StackTrace
            };

            try
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    db.ExceptionLoggings.Add(ex);
                    db.SaveChanges();
                }
            }
            catch
            {
                // Could not log error
                ex.ExceptionNumber = 999999;
            }
            finally
            {
                System.Diagnostics.Debug.Write(string.Format("Exception swallowed by Filter: {0}", ex));

                if ((ConfigurationManager.AppSettings["notifyDeveloperOfExceptions"]) == "true")
                {
                    NotifyDeveloper(ex);
                }
            }
        }
Ejemplo n.º 9
0
        public static void CreateNewExternalWebsite(ExternalWebsite website)
        {
            try
            {
                website.DateAdded  = DateTime.Now;
                website.Department = int.Parse(website.SelectedDepartment);
                if (website.Url.StartsWith("http://") || website.Url.StartsWith("https://"))
                {
                }
                else
                {
                    website.Url = website.Url.Insert(0, "http://");
                }
            }
            catch
            {
                return;
            }

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.ExternalWebsites.Add(website);
                db.SaveChanges();
            }
        }
        public static FreeMarketResult UpdateAddress(string userId, string addressName, string addressLine1, string addressLine2,
                                                     string addressLine3, string addressLine4, string addressSuburb, string addressCity, string addressPostalCode)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                CustomerAddress address = db.CustomerAddresses
                                          .Where(c => c.CustomerNumber == userId && c.AddressName == addressName)
                                          .FirstOrDefault();

                if (address == null)
                {
                    return(FreeMarketResult.Failure);
                }

                address.AddressLine1      = addressLine1;
                address.AddressLine2      = addressLine2;
                address.AddressLine3      = addressLine3;
                address.AddressLine4      = addressLine4;
                address.AddressCity       = addressCity;
                address.AddressPostalCode = addressPostalCode;
                address.AddressSuburb     = addressSuburb;

                db.Entry(address).State = EntityState.Modified;
                db.SaveChanges();

                AuditUser.LogAudit(5, string.Format("Address name: {0}", addressName), userId);
            }

            return(FreeMarketResult.Success);
        }
 public static void SaveCourier(Courier courier)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(courier).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public static void SaveSupplier(Supplier supplier)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 13
0
 public static void SaveModel(Department model)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 14
0
 public static void CreateNewDepartment(Department department)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Departments.Add(department);
         db.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public static void SaveModel(Support support)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(support).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public static void SaveCustomer(CashCustomer model)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(model).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
        public static void SaveCustodian(Custodian custodian)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Entry(custodian).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                SaveActivatedProducts(custodian);
            }
        }
        public static void CreateNewSupplier(Supplier supplier)
        {
            supplier.DateAdded = DateTime.Now;

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
            }
        }
Ejemplo n.º 19
0
        public static void CreateNewSpecial(Special special)
        {
            special.DateAdded = DateTime.Now;

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Specials.Add(special);
                db.SaveChanges();
            }
        }
Ejemplo n.º 20
0
        public void CreateTestMessage1()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                string PAYGATE_ID       = Parameters.PaymentGatewayID.ToString();
                string REFERENCE        = "PayGate Test";
                string AMOUNT           = "3299";
                string CURRENCY         = "ZAR";
                string RETURN_URL       = "https://www.paygate.co.za/thankyou";
                string TRANSACTION_DATE = "2016-03-10 10:49:16";
                string LOCALE           = "en";
                string COUNTRY          = "ZAF";
                string EMAIL            = "*****@*****.**";
                string NOTIFY_URL       = "https://www.paygate.co.za/notify";
                string USER1            = "SpecialKey";
                string KEY = "secret";

                string hash = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}",
                                            PAYGATE_ID, REFERENCE, AMOUNT, CURRENCY, RETURN_URL, TRANSACTION_DATE, LOCALE, COUNTRY, EMAIL, NOTIFY_URL, USER1, KEY);
                string checkSum = Extensions.CreateMD5(hash);

                PaymentGatewayMessage message = new PaymentGatewayMessage
                {
                    PayGate_ID       = Parameters.PaymentGatewayID,
                    Reference        = REFERENCE,
                    Amount           = (int)Amount,
                    Currency         = CURRENCY,
                    ReturnUrl        = RETURN_URL,
                    Transaction_Date = TRANSACTION_DATE,
                    Locale           = LOCALE,
                    Country          = COUNTRY,
                    Email            = EMAIL
                };

                db.PaymentGatewayMessages.Add(message);
                db.SaveChanges();

                Message1 = new[] {
                    new KeyValuePair <string, string>("PAYGATE_ID", PAYGATE_ID),
                    new KeyValuePair <string, string>("REFERENCE", REFERENCE),
                    new KeyValuePair <string, string>("AMOUNT", AMOUNT),
                    new KeyValuePair <string, string>("CURRENCY", CURRENCY),
                    new KeyValuePair <string, string>("RETURN_URL", RETURN_URL),
                    new KeyValuePair <string, string>("TRANSACTION_DATE", TRANSACTION_DATE),
                    new KeyValuePair <string, string>("LOCALE", LOCALE),
                    new KeyValuePair <string, string>("COUNTRY", COUNTRY),
                    new KeyValuePair <string, string>("EMAIL", EMAIL),
                    new KeyValuePair <string, string>("NOTIFY_URL", NOTIFY_URL),
                    new KeyValuePair <string, string>("USER1", USER1),
                    new KeyValuePair <string, string>("CHECKSUM", checkSum)
                };
            }
        }
Ejemplo n.º 21
0
        public static SiteConfiguration SaveConfig(SiteConfiguration config)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                SiteConfiguration oldConfig = db.SiteConfigurations.AsNoTracking()
                                              .Where(c => c.Key == config.Key)
                                              .FirstOrDefault();

                db.Entry(config).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(oldConfig);
            }
        }
        public static TimeFreightCourierFeeReference SaveModel(TimeFreightCourierFeeReference model)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                TimeFreightCourierFeeReference oldConfig = db.TimeFreightCourierFeeReferences.AsNoTracking()
                                                           .Where(c => c.DeliveryCostID == model.DeliveryCostID)
                                                           .FirstOrDefault();

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(oldConfig);
            }
        }
Ejemplo n.º 23
0
        public static void RefundOrder(int id)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                CashOrder order = db.CashOrders.Find(id);

                if (order != null)
                {
                    order.Status          = "Refunded";
                    db.Entry(order).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
        public static PostalFee SaveModel(PostalFee model)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                PostalFee oldFee = db.PostalFees.AsNoTracking()
                                   .Where(c => c.Id == model.Id)
                                   .FirstOrDefault();

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(oldFee);
            }
        }
Ejemplo n.º 25
0
        public static Special SaveModel(Special model)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                Special oldConfig = db.Specials.AsNoTracking()
                                    .Where(c => c.SpecialID == model.SpecialID)
                                    .FirstOrDefault();

                model.DateModified    = DateTime.Now;
                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(oldConfig);
            }
        }
Ejemplo n.º 26
0
        public static void RemoveStockFromCustodian(int orderId, int productNumber, int supplierNumber, int custodianNumber, int quantity)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                ProductCustodian custodian = db.ProductCustodians
                                             .Where(c => c.CustodianNumber == custodianNumber &&
                                                    c.ProductNumber == productNumber &&
                                                    c.SupplierNumber == supplierNumber)
                                             .FirstOrDefault();

                custodian.QuantityOnHand -= quantity;

                db.Entry(custodian).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
        public static void CreateCustodian(Custodian custodian)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                Custodian custodianDB = db.Custodians
                                        .Where(c => c.CustodianNumber == custodian.CustodianNumber)
                                        .FirstOrDefault();

                if (custodianDB == null)
                {
                    db.Custodians.Add(custodian);
                    db.SaveChanges();

                    SaveActivatedProducts(custodian);
                }
            }
        }
Ejemplo n.º 28
0
        public static void AddStock(int productNumber, int supplierNumber, int custodianNumber, int quantity)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                ProductCustodian custodian = db.ProductCustodians.Where(c => c.CustodianNumber == custodianNumber &&
                                                                        c.ProductNumber == productNumber &&
                                                                        c.SupplierNumber == supplierNumber)
                                             .FirstOrDefault();

                custodian.QuantityOnHand += quantity;
                custodian.DateLastIncreasedBySupplier   = DateTime.Now;
                custodian.AmountLastIncreasedBySupplier = quantity;

                db.Entry(custodian).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
        public static void SetOrderConfirmedFromNotify(int orderNumber)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                OrderHeader order = db.OrderHeaders.Find(orderNumber);

                if (order == null)
                {
                    return;
                }

                order.OrderStatus     = "Confirmed";
                order.OrderDatePlaced = DateTime.Now;
                order.PaymentReceived = true;
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                ReleaseAllStock(order.OrderNumber);
            }
        }
Ejemplo n.º 30
0
        public static void LogAudit(short action, string parameters, string userId = null)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                string user = userId ?? "Anonymous";

                if (ExceptionLogging.AuditLoggingEnabled())
                {
                    AuditUser audit = new AuditUser()
                    {
                        Identity   = user,
                        DateTime   = DateTime.Now,
                        Action     = action,
                        Parameters = parameters
                    };

                    db.AuditUsers.Add(audit);
                    db.SaveChanges();
                }
            }
        }