// query API server and return response in object format
        private async Task <string> QuerySmsServer(IEnumerable <KeyValuePair <string, string> > data, string optional_headers = null)
        {
            try
            {
                client             = new HttpClient();
                client.BaseAddress = new Uri(Url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var content = new FormUrlEncodedContent(
                    data
                    );

                var    result        = client.PostAsync(Url, content).Result;
                string resultContent = result.Content.ReadAsStringAsync().Result;
                return(resultContent);
            }
            catch (Exception e)
            {
                ExceptionLogging.LogException(e);
                client = new HttpClient();
                return("Failure");
            }
        }
示例#2
0
        public static void SaveExternalWebsite(ExternalWebsite website)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                try
                {
                    if (website.Url.StartsWith("http://") || website.Url.StartsWith("https://"))
                    {
                    }
                    else
                    {
                        website.Url = website.Url.Insert(0, "http://");
                    }

                    website.Department      = int.Parse(website.SelectedDepartment);
                    db.Entry(website).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ExceptionLogging.LogException(e);
                }
            }
        }
示例#3
0
        public static FreeMarketResult SaveDepartmentImage(int departmentNumber, PictureSize size, HttpPostedFileBase image)
        {
            if (image != null && departmentNumber != 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    DepartmentPicture picture = new DepartmentPicture();

                    Department department = db.Departments.Find(departmentNumber);

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

                    picture = db.DepartmentPictures
                              .Where(c => c.DepartmentNumber == departmentNumber && c.Dimensions == size.ToString())
                              .FirstOrDefault();

                    try
                    {
                        // No picture exists for this dimension/product
                        if (picture == null)
                        {
                            picture            = new DepartmentPicture();
                            picture.Picture    = new byte[image.ContentLength];
                            picture.Annotation = department.DepartmentName;
                            picture.Dimensions = size.ToString();
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType  = image.ContentType;
                            picture.DepartmentNumber = departmentNumber;

                            db.DepartmentPictures.Add(picture);
                            db.SaveChanges();

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                        else
                        {
                            picture.Annotation = department.DepartmentName;
                            picture.Picture    = new byte[image.ContentLength];
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType = image.ContentType;

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

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogging.LogException(e);
                        return(FreeMarketResult.Failure);
                    }
                }
            }

            return(FreeMarketResult.Failure);
        }
示例#4
0
        public void CreateMessage1()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                string PAYGATE_ID        = Parameters.PaymentGatewayID.ToString();
                string REFERENCE         = Reference;
                string AMOUNT            = string.Format("{0:0}", Amount);
                string CURRENCY          = "ZAR";
                string RETURN_URL        = Parameters.Return_Url;
                string TRANSACTION_DATE  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string LOCALE            = "en";
                string COUNTRY           = "ZAF";
                string EMAIL             = CustomerEmail;
                string PAY_METHOD        = null;
                string PAY_METHOD_DETAIL = null;
                string NOTIFY_URL        = Parameters.Notify_Url;
                string USER1             = null;
                string USER2             = null;
                string USER3             = null;
                string VAULT_ID          = null;

                string KEY = Parameters.Key;

                string hash = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}",
                                            PAYGATE_ID, REFERENCE, AMOUNT, CURRENCY, RETURN_URL, TRANSACTION_DATE, LOCALE, COUNTRY, EMAIL, PAY_METHOD, PAY_METHOD_DETAIL, NOTIFY_URL, USER1, USER2, USER3, VAULT_ID, 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,
                    Notify_Url       = NOTIFY_URL
                };

                try
                {
                    db.PaymentGatewayMessages.Add(message);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ExceptionLogging.LogException(e);
                }

                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>("CHECKSUM", checkSum)
                };
            }
        }
示例#5
0
        public static void CreateNewProduct(Product product)
        {
            try
            {
                product.DateAdded        = DateTime.Now;
                product.DateModified     = DateTime.Now;
                product.DepartmentNumber = int.Parse(product.SelectedDepartment);
            }
            catch
            {
                return;
            }

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Products.Add(product);
                db.SaveChanges();

                foreach (ProductSize item in product.SizeVariations)
                {
                    if (item.PricePerUnit > 0 && item.Activated == true)
                    {
                        ProductSupplier productSupplierDb = new ProductSupplier()
                        {
                            ProductNumber       = product.ProductNumber,
                            SupplierNumber      = int.Parse(product.SelectedSupplier),
                            PricePerUnit        = item.PricePerUnit,
                            SpecialPricePerUnit = 0,
                            RetailPricePerUnit  = 0,
                            SizeType            = item.SizeId
                        };

                        db.ProductSuppliers.Add(productSupplierDb);
                        db.SaveChanges();
                    }
                }

                Custodian custodian = db.Custodians.Find(product.SelectedCustodianNumber);

                if (custodian == null)
                {
                    return;
                }
                try
                {
                    foreach (ProductSize item in product.SizeVariations)
                    {
                        if (item.PricePerUnit > 0 && item.Activated == true)
                        {
                            ProductCustodian productCustodianDb = new ProductCustodian()
                            {
                                AmountLastIncreasedBySupplier = null,
                                CustodianNumber             = product.SelectedCustodianNumber,
                                DateLastIncreasedBySupplier = null,
                                ProductNumber          = product.ProductNumber,
                                SupplierNumber         = int.Parse(product.SelectedSupplier),
                                QuantityOnHand         = 0,
                                StockReservedForOrders = 0,
                                SizeType = item.SizeId
                            };

                            db.ProductCustodians.Add(productCustodianDb);
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception e)
                {
                    ExceptionLogging.LogException(e);
                }
            }
        }
示例#6
0
        public async void Initialize()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                DateTime minDate;
                if (db.OrderHeaders.FirstOrDefault() == null)
                {
                    minDate = DateTime.Now.AddYears(-1);
                }
                else
                {
                    minDate = (DateTime)db.OrderHeaders.Min(c => c.OrderDatePlaced);
                }

                DateTime maxDate = DateTime.Now;

                int i = minDate.Year;

                YearOptions = new List <SelectListItem>();

                YearOptions.Add(new SelectListItem
                {
                    Text  = "Since Inception",
                    Value = "0"
                });

                while (i <= maxDate.Year)
                {
                    YearOptions.Add(new SelectListItem
                    {
                        Text     = i.ToString(),
                        Value    = i.ToString(),
                        Selected = (i.ToString() == SelectedYear ? true : false)
                    });
                    i++;
                }

                RatingsInformation = new RatingsInfo();
                Customers          = new List <AspNetUser>();
                Customers          = db.AspNetUsers.ToList();
                AllOrders          = db.OrderHeaders.OrderByDescending(c => c.OrderNumber).ToList();
                Invoices           = db.OrderHeaders.Where(c => c.OrderStatus == "Invoiced").OrderByDescending(c => c.OrderNumber).ToList();
                ConfirmedOrders    = db.OrderHeaders.Where(c => c.OrderStatus == "Confirmed").OrderByDescending(c => c.OrderNumber).ToList();
                InTransitOrders    = db.OrderHeaders.Where(c => c.OrderStatus == "InTransit").OrderByDescending(c => c.OrderNumber).ToList();
                RefundPending      = db.OrderHeaders.Where(c => c.OrderStatus == "RefundPending").OrderByDescending(c => c.OrderNumber).ToList();
                RefundableOrders   = db.OrderHeaders.Where(c => c.OrderStatus == "Confirmed" || c.OrderStatus == "InTransit").ToList();

                TotalSales = SalesInformation.SalesDetails.Sum(c => c.Value);

                List <AuditUser> hits = new List <AuditUser>();
                hits = db.AuditUsers.Where(c => c.Action == 32).ToList();
                if (hits.Count > 0)
                {
                    WebsiteHits = hits.Count;
                }

                try
                {
                    SMSHelper helper = new SMSHelper();
                    SMSCredits = await helper.CheckCredits();
                }
                catch (Exception e)
                {
                    ExceptionLogging.LogException(e);
                }
            }
        }