Esempio n. 1
0
        public static void InitializeDropDowns(CashOrderViewModel model)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                model.Custodians = db.Custodians.Select
                                       (c => new SelectListItem
                {
                    Text  = c.CustodianName,
                    Value = c.CustodianNumber.ToString()
                }).ToList();

                foreach (Product product in model.Products.Products)
                {
                    string normalPrice  = string.Format("{0:C}", product.PricePerUnit);
                    string specialPrice = string.Format("{0:C}", product.SpecialPricePerUnit);

                    product.Prices = new List <SelectListItem>();

                    product.Prices.Add(new SelectListItem
                    {
                        Text  = normalPrice,
                        Value = product.PricePerUnit.ToString()
                    });

                    product.Prices.Add(new SelectListItem
                    {
                        Text     = specialPrice,
                        Value    = product.SpecialPricePerUnit.ToString(),
                        Selected = true
                    });
                }
            }
        }
        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);
        }
Esempio n. 3
0
 public static List <SiteConfiguration> GetSiteConfig()
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         return(db.SiteConfigurations.OrderBy(c => c.Key).ToList());
     }
 }
Esempio n. 4
0
        private void CalculateNumberOfItems(DateTime date)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                NumberOrdersSingleItem  = 0;
                NumberOrdersTwoToFive   = 0;
                NumberOrdersGreaterFive = 0;

                List <GetNumberOfItemsStatistic_Result> result = db.GetNumberOfItemsStatistic().ToList();

                foreach (GetNumberOfItemsStatistic_Result res in result)
                {
                    if (res.OrderDatePlaced.HasValue &&
                        res.OrderDatePlaced.Value.Year == date.Year &&
                        res.OrderDatePlaced.Value.Month == date.Month)
                    {
                        if (res.SumItems == 1)
                        {
                            NumberOrdersSingleItem++;
                        }
                        else if (res.SumItems > 1 && res.SumItems <= 5)
                        {
                            NumberOrdersTwoToFive++;
                        }
                        else
                        {
                            NumberOrdersGreaterFive++;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public static ProductCollectionPaged SetAllProductDataDistinctFilter(int pageNumber, int pageSize, List <GetAllProductsDistinctFilter_Result> allProducts)
        {
            ProductCollectionPaged collection = new ProductCollectionPaged();
            List <Product>         temp       = new List <Product>();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (allProducts != null && allProducts.Count > 0)
                {
                    foreach (GetAllProductsDistinctFilter_Result product in allProducts)
                    {
                        Product prodTemp = Product.GetShallowProduct((int)product.ProductNumber, (int)product.SupplierNumber);
                        prodTemp.MinPrice = product.minPrice;
                        prodTemp.MaxPrice = product.maxPrice;

                        if (prodTemp != null)
                        {
                            temp.Add(prodTemp);
                        }
                    }
                }

                collection.Products = (PagedList <Product>)temp.ToPagedList(pageNumber, pageSize);

                return(collection);
            }
        }
Esempio n. 6
0
        public static void SetDepartmentData(List <Department> departments)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                foreach (Department department in departments)
                {
                    int imageNumber = db.DepartmentPictures
                                      .Where(c => c.DepartmentNumber == department.DepartmentNumber && c.Dimensions == PictureSize.Medium.ToString())
                                      .Select(c => c.PictureNumber)
                                      .FirstOrDefault();

                    int imageNumberSecondary = db.DepartmentPictures
                                               .Where(c => c.DepartmentNumber == department.DepartmentNumber && c.Dimensions == PictureSize.Large.ToString())
                                               .Select(c => c.PictureNumber)
                                               .FirstOrDefault();

                    department.MainImageNumber      = imageNumber;
                    department.SecondaryImageNumber = imageNumberSecondary;

                    department.ItemsInDepartment = db.Products
                                                   .Where(c => c.DepartmentNumber == department.DepartmentNumber)
                                                   .Count();
                }
            }
        }
        public static CustomerAddress GetCustomerAddress(string userId, string addressName)
        {
            CustomerAddress address = new CustomerAddress();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (!string.IsNullOrEmpty(addressName))
                {
                    address = db.CustomerAddresses.Where(c => c.CustomerNumber == userId && c.AddressName == addressName)
                              .FirstOrDefault();
                }
                else
                {
                    address = db.CustomerAddresses.Where(c => c.CustomerNumber == userId)
                              .FirstOrDefault();
                }
            }

            if (address == null)
            {
                address = new CustomerAddress();
            }

            return(address);
        }
Esempio n. 8
0
        public static ProductCollectionPaged SetProductDataDistinct(int pageNumber, int pageSize, List <GetAllProductsByDepartmentDistinct_Result> allProducts)
        {
            ProductCollectionPaged collection = new ProductCollectionPaged();
            List <Product>         temp       = new List <Product>();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (allProducts != null && allProducts.Count > 0)
                {
                    foreach (GetAllProductsByDepartmentDistinct_Result product in allProducts)
                    {
                        Product prodTemp = Product.GetShallowProduct(product.ProductNumber, product.SupplierNumber);
                        prodTemp.MinPrice = product.minPrice;
                        prodTemp.MaxPrice = product.maxPrice;

                        PopularProduct pp = db.PopularProducts.Where(c => c.ProductNumber == prodTemp.ProductNumber &&
                                                                     c.SupplierNumber == prodTemp.SupplierNumber).FirstOrDefault();

                        if (pp != null)
                        {
                            prodTemp.NumberSold = pp.NumberSold ?? 0;
                        }

                        if (prodTemp != null)
                        {
                            temp.Add(prodTemp);
                        }
                    }
                }

                collection.Products = (PagedList <Product>)temp.ToPagedList(pageNumber, pageSize);

                return(collection);
            }
        }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
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);
                }
            }
        }
        public static List <CashCustomer> GetCustomers(string customerCriteria)
        {
            List <CashCustomer> customers = new List <CashCustomer>();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                customers = db.FilterCashCustomers(customerCriteria)
                            .Select(c => new CashCustomer
                {
                    DeliveryAddress = c.DeliveryAddress,
                    Email           = c.Email,
                    Id          = (int)c.Id,
                    Name        = c.Name,
                    PhoneNumber = c.PhoneNumber
                })
                            .ToList();
            }

            if (customers == null)
            {
                return(new List <CashCustomer>());
            }

            return(customers);
        }
        public static List <PriceHistory> GetAllHistories()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                List <PriceHistory> result = db.GetPriceHistories()
                                             .Select(c => new PriceHistory
                {
                    Date           = c.Date,
                    Description    = c.Description,
                    NewPrice       = c.NewPrice,
                    PriceID        = c.PriceID,
                    OldPrice       = c.OldPrice,
                    SupplierName   = c.SupplierName,
                    SupplierNumber = c.SupplierNumber,
                    ProductNumber  = c.ProductNumber,
                    Type           = c.Type
                }).ToList();

                if (result == null)
                {
                    result = new List <PriceHistory>();
                }

                return(result);
            }
        }
Esempio n. 13
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();
            }
        }
Esempio n. 14
0
        public static List <ExternalWebsite> GetAllWebsites()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                List <ExternalWebsite> allWebsites = db.ExternalWebsites.ToList();

                if (allWebsites != null && allWebsites.Count > 0)
                {
                    foreach (ExternalWebsite website in allWebsites)
                    {
                        int imageNumber = db.ExternalWebsitePictures
                                          .Where(c => c.WebsiteNumber == website.LinkId && c.Dimensions == PictureSize.Medium.ToString())
                                          .Select(c => c.PictureNumber)
                                          .FirstOrDefault();

                        int imageNumberSecondary = db.ExternalWebsitePictures
                                                   .Where(c => c.WebsiteNumber == website.LinkId && c.Dimensions == PictureSize.Medium.ToString())
                                                   .Select(c => c.PictureNumber)
                                                   .FirstOrDefault();

                        website.MainImageNumber       = imageNumber;
                        website.AdditionalImageNumber = imageNumberSecondary;
                    }

                    return(allWebsites);
                }
                else
                {
                    return(new List <ExternalWebsite>());
                }
            }
        }
        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);
        }
        public void InitializeActivatedProducts()
        {
            ActivatedProducts = new ProductCollection();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                ProductCollection products = new ProductCollection();
                products = ProductCollection.GetAllProducts();

                if (products == null)
                {
                    return;
                }

                foreach (Product item in products.Products)
                {
                    if (db.ProductCustodians.Any(c => c.ProductNumber == item.ProductNumber &&
                                                 c.SupplierNumber == item.SupplierNumber &&
                                                 c.CustodianNumber == CustodianNumber &&
                                                 c.Active == true))
                    {
                        item.CustodianActivated = true;
                        ActivatedProducts.Products.Add(item);
                    }

                    else
                    {
                        item.CustodianActivated = false;
                        ActivatedProducts.Products.Add(item);
                    }
                }
            }
        }
        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);
        }
Esempio n. 18
0
        public static ProductCollection SetAllProductDataDistinct(List <GetAllProductsDistinct_Result> allProducts)
        {
            ProductCollection collection = new ProductCollection();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (allProducts != null && allProducts.Count > 0)
                {
                    foreach (GetAllProductsDistinct_Result product in allProducts)
                    {
                        Product prodTemp = Product.GetShallowProduct(product.ProductNumber, product.SupplierNumber);
                        prodTemp.MinPrice = product.minPrice;
                        prodTemp.MaxPrice = product.maxPrice;

                        PopularProduct pp = db.PopularProducts.Where(c => c.ProductNumber == prodTemp.ProductNumber &&
                                                                     c.SupplierNumber == prodTemp.SupplierNumber).FirstOrDefault();

                        if (pp != null)
                        {
                            prodTemp.NumberSold = pp.NumberSold ?? 0;
                        }

                        if (prodTemp != null)
                        {
                            collection.Products.Add(prodTemp);
                        }
                    }
                }

                return(collection);
            }
        }
        public FreeMarketObject RemoveItem(int itemNumber, int productNumber, int supplierNumber, int sizeType, string userId = null)
        {
            // If the item is in the database
            FreeMarketResult resultDatabase = RemoveItemFromDatabase(itemNumber, userId);

            // Remove the item from the Session as well
            FreeMarketResult resultSession = RemoveItemFromSession(productNumber, supplierNumber, sizeType);

            if (resultDatabase == FreeMarketResult.Success && resultSession == FreeMarketResult.Success)
            {
                Product product = new Product();

                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    product = db.Products.Find(itemNumber);
                }

                // Keep the OrderTotal in sync
                UpdateTotal();

                return(new FreeMarketObject {
                    Result = FreeMarketResult.Success, Argument = product
                });
            }
            else
            {
                UpdateTotal();

                return(new FreeMarketObject {
                    Result = FreeMarketResult.Failure, Argument = null
                });
            }
        }
Esempio n. 20
0
        public static Department GetDepartment(int Id)
        {
            Department model = new Department();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                model = db.Departments.Find(Id);

                model.MainImageNumber = db.DepartmentPictures
                                        .Where(c => c.DepartmentNumber == model.DepartmentNumber && c.Dimensions == PictureSize.Medium.ToString())
                                        .Select(c => c.PictureNumber)
                                        .FirstOrDefault();

                model.SecondaryImageNumber = db.DepartmentPictures
                                             .Where(c => c.DepartmentNumber == model.DepartmentNumber && c.Dimensions == PictureSize.Large.ToString())
                                             .Select(c => c.PictureNumber)
                                             .FirstOrDefault();

                model.ItemsInDepartment = db.Products
                                          .Where(c => c.DepartmentNumber == model.DepartmentNumber)
                                          .Count();
            }

            if (model == null)
            {
                model = new Department();
            }

            return(model);
        }
        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);
        }
Esempio n. 22
0
        public AspNetUserCustomer(string customerNumber, bool displayOnly)
        {
            User = new AspNetUser();
            CommunicationOptions = new List <SelectListItem>();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                User = db.AspNetUsers.Find(customerNumber);

                if (User == null)
                {
                    User = new AspNetUser();
                }

                CommunicationOptions = db.PreferredCommunicationMethods.Select
                                           (c => new SelectListItem
                {
                    Text  = c.CommunicationMethod,
                    Value = c.CommunicationMethod
                }).ToList();

                SelectedCommunicationOption = User.PreferredCommunicationMethod;
                DisplayOnly = displayOnly;
            }
        }
        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);
        }
Esempio n. 24
0
 public static SiteConfiguration GetSpecificSiteConfig(int id)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         return(db.SiteConfigurations.Find(id));
     }
 }
        public void Merge(string userId, CartBody tempBody)
        {
            if (Order.OrderStatus != "Locked")
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    // Compare the session body with the database
                    foreach (OrderDetail item in tempBody.OrderDetails)
                    {
                        OrderDetail existingItem = Body.OrderDetails
                                                   .Where(c => c.ProductNumber == item.ProductNumber &&
                                                          c.SupplierNumber == item.SupplierNumber && c.SizeType == item.SizeType)
                                                   .FirstOrDefault();

                        // If the item does not exist, add it
                        if (existingItem == null)
                        {
                            Body.OrderDetails.Add(item);
                        }
                        // Otherwise update the quantity only
                        else
                        {
                            Body.OrderDetails.Where(c => c.ProductNumber == item.ProductNumber &&
                                                    c.SupplierNumber == item.SupplierNumber && c.SizeType == item.SizeType)
                            .FirstOrDefault()
                            .Quantity += item.Quantity;
                        }
                    }
                }

                UpdateTotal();
            }
        }
Esempio n. 26
0
        public static CashOrderViewModel CreateNewOrder(int id = 0)
        {
            CashOrderViewModel model = new CashOrderViewModel();

            model.Order = new CashOrder();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (id != 0)
                {
                    CashCustomer customer = db.CashCustomers.Find(id);
                    if (customer != null)
                    {
                        model.Order.CashCustomerId          = customer.Id;
                        model.Order.CustomerDeliveryAddress = customer.DeliveryAddress;
                        model.Order.CustomerEmail           = customer.Email;
                        model.Order.CustomerName            = customer.Name;
                        model.Order.CustomerPhone           = customer.PhoneNumber;
                    }
                }

                model.Products = ProductCollection.GetAllProducts();

                model.Custodians = db.Custodians.Select
                                       (c => new SelectListItem
                {
                    Text  = c.CustodianName,
                    Value = c.CustodianNumber.ToString()
                }).ToList();
            }

            model.OrderDetails = new List <CashOrderDetail>();

            return(model);
        }
Esempio n. 27
0
        public static List <AuditUser> GetAudits(string filter)
        {
            List <AuditUser> audits = new List <AuditUser>();

            if (!string.IsNullOrEmpty(filter))
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    audits = db.FilterAuditUser(filter).Select(c => new AuditUser
                    {
                        Action            = (short)c.Action,
                        DateTime          = (DateTime)c.DateTime,
                        Identity          = c.Identity,
                        ActionNumber      = (long)c.ActionNumber,
                        Parameters        = c.Parameters,
                        ActionDescription = c.ActionDescription
                    })
                             .ToList();
                }
            }
            else
            {
                audits = new List <AuditUser>();
            }

            return(audits);
        }
Esempio n. 28
0
 public static List <WebsiteFunction> GetAllFunctions()
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         return(db.WebsiteFunctions.ToList());
     }
 }
 public static void SaveCourier(Courier courier)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(courier).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 30
0
 public static void SaveModel(Support support)
 {
     using (FreeMarketEntities db = new FreeMarketEntities())
     {
         db.Entry(support).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }