public int Post(Models.Event value)
        {
            try
            {
                Data.MstEvent NewEvent = new Data.MstEvent();

                SqlDateTime EventDate = new SqlDateTime(new DateTime(Convert.ToDateTime(value.EventDate).Year, +
                                                                     Convert.ToDateTime(value.EventDate).Month, +
                                                                     Convert.ToDateTime(value.EventDate).Day));


                NewEvent.EventDate        = EventDate.Value;
                NewEvent.EventDescription = value.EventDescription;
                NewEvent.Particulars      = value.Particulars;
                NewEvent.URL          = value.URL;
                NewEvent.VideoURL     = value.VideoURL;
                NewEvent.EventType    = value.EventType;
                NewEvent.IsRestricted = value.IsRestricted;
                NewEvent.IsArchived   = value.IsArchived;

                db.MstEvents.InsertOnSubmit(NewEvent);
                db.SubmitChanges();

                return(NewEvent.Id);
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 2
0
        public int Post(Models.News value)
        {
            try
            {
                Data.MstNew NewNews = new Data.MstNew();

                DateTime myDate = Convert.ToDateTime(value.NewsDate, new CultureInfo("en-US"));

                SqlDateTime NewsDate = new SqlDateTime(new DateTime(Convert.ToDateTime(myDate).Year, +
                                                                    Convert.ToDateTime(myDate).Month, +
                                                                    Convert.ToDateTime(myDate).Day));


                NewNews.NewsDate    = NewsDate.Value;
                NewNews.News        = value.NewsDescription;
                NewNews.Particulars = value.Particulars;

                db.MstNews.InsertOnSubmit(NewNews);
                db.SubmitChanges();

                return(NewNews.Id);
            }
            catch
            {
                return(0);
            }
        }
        public int Post(Models.ProductPackage value)
        {
            try
            {
                Data.MstProductPackage NewProductPackage = new Data.MstProductPackage();

                NewProductPackage.ProductPackage = value.ProductPackageDescription;
                NewProductPackage.SKU = value.SKU;
                NewProductPackage.Price = value.Price;
                NewProductPackage.ProductId = value.ProductId;
                NewProductPackage.IsAvailable = value.IsAvailable;
                NewProductPackage.WithCoupon = value.WithCoupon;
                NewProductPackage.WithSoftware = value.WithSoftware;
                NewProductPackage.IsReoccuring = value.IsReoccuring;
                NewProductPackage.Particulars = value.Particulars;
                NewProductPackage.PackageURL = value.PackageURL;
                NewProductPackage.ProductPackageGroup = value.ProductPackageGroup;

                db.MstProductPackages.InsertOnSubmit(NewProductPackage);
                db.SubmitChanges();

                return NewProductPackage.Id;
            }
            catch
            {
                return 0;
            }
        }
        public int Post(Models.UserFavorite value)
        {
            try
            {
                Data.TrnUserFavorite newUserFavorite = new Data.TrnUserFavorite();

                var  userId   = (from d in db.MstUsers where d.UserName.Equals(value.User) select d).FirstOrDefault().Id;
                bool isShared = false;

                DateTime    dt          = Convert.ToDateTime(value.EncodedDate);
                SqlDateTime EncodedDate = new SqlDateTime(new DateTime(dt.Year, dt.Month, dt.Day));

                newUserFavorite.UserId      = userId;
                newUserFavorite.Description = value.Description;
                newUserFavorite.IsShared    = isShared;
                newUserFavorite.EncodedDate = EncodedDate.Value;

                db.TrnUserFavorites.InsertOnSubmit(newUserFavorite);
                db.SubmitChanges();

                return(newUserFavorite.Id);
            }
            catch
            {
                return(0);
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false);

                    // Add or update MstUser table
                    Data.MagentaTradersDBDataContext db = new Data.MagentaTradersDBDataContext();

                    var Users = from d in db.MstUsers where d.UserName == model.UserName select d;

                    if (Users.Any())
                    {
                        var UpdatedUser = Users.FirstOrDefault();

                        UpdatedUser.AspNetUserId = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault().Id;

                        db.SubmitChanges();
                    }
                    else
                    {
                        Data.MstUser NewUser = new Data.MstUser();

                        NewUser.UserName     = model.UserName;
                        NewUser.FirstName    = "NA";
                        NewUser.LastName     = "NA";
                        NewUser.EmailAddress = "NA";
                        NewUser.PhoneNumber  = "NA";
                        NewUser.AspNetUserId = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault().Id;

                        db.MstUsers.InsertOnSubmit(NewUser);
                        db.SubmitChanges();
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 6
0
        public int Post(Models.Product value)
        {
            try
            {
                Data.MstProduct NewProduct = new Data.MstProduct();

                NewProduct.Product = value.ProductDescription;

                db.MstProducts.InsertOnSubmit(NewProduct);
                db.SubmitChanges();

                return(NewProduct.Id);
            }
            catch
            {
                return(0);
            }
        }
        public HttpResponseMessage GetUserFavoriteSymbolUpload(String Id, [FromUri] List <String> Symbols)
        {
            Id = Id.Replace(",", "");
            int userFavoritesId = Convert.ToInt32(Id);

            try
            {
                if (userFavoritesId > 0)
                {
                    for (int i = 0; i < Symbols.Count; i++)
                    {
                        Data.TrnUserFavoritesSymbol newUserFavoriteSymbol = new Data.TrnUserFavoritesSymbol();

                        var symbols = from d in db.MstSymbols where d.Symbol == Symbols[i].ToUpper() select d;

                        if (symbols.Any())
                        {
                            newUserFavoriteSymbol.UserFavoritesId = userFavoritesId;
                            newUserFavoriteSymbol.SymbolId        = symbols.First().Id;
                            newUserFavoriteSymbol.Symbol          = symbols.First().Symbol;
                            newUserFavoriteSymbol.Trend           = "SIDEWAYS";

                            //DateTime dt = new DateTime();
                            //SqlDateTime EncodedDate = new SqlDateTime(new DateTime(dt.Year, dt.Month, dt.Day));
                            //newUserFavoriteSymbol.EncodedDate = EncodedDate.Value;

                            db.TrnUserFavoritesSymbols.InsertOnSubmit(newUserFavoriteSymbol);
                            db.SubmitChanges();
                        }
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 8
0
        public int Post(Models.User value)
        {
            try
            {
                Data.MstUser NewUser = new Data.MstUser();

                NewUser.UserName     = value.UserName;
                NewUser.FirstName    = value.FirstName;
                NewUser.LastName     = value.LastName;
                NewUser.EmailAddress = value.EmailAddress;
                NewUser.PhoneNumber  = value.PhoneNumber;

                db.MstUsers.InsertOnSubmit(NewUser);
                db.SubmitChanges();

                return(NewUser.Id);
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 9
0
        public int Post(Models.Sales value)
        {
            try
            {
                Data.TrnSale NewSale = new Data.TrnSale();

                SqlDateTime SalesDate = new SqlDateTime(new DateTime(Convert.ToDateTime(value.SalesDate).Year, +
                                                                     Convert.ToDateTime(value.SalesDate).Month, +
                                                                     Convert.ToDateTime(value.SalesDate).Day));
                SqlDateTime RenewalDate = new SqlDateTime(new DateTime(Convert.ToDateTime(value.RenewalDate).Year, +
                                                                       Convert.ToDateTime(value.RenewalDate).Month, +
                                                                       Convert.ToDateTime(value.RenewalDate).Day));
                SqlDateTime ExpiryDate = new SqlDateTime(new DateTime(Convert.ToDateTime(value.ExpiryDate).Year, +
                                                                      Convert.ToDateTime(value.ExpiryDate).Month, +
                                                                      Convert.ToDateTime(value.ExpiryDate).Day));

                NewSale.ProductPackageId = value.ProductPackageId;
                NewSale.UserId           = value.UserId;
                NewSale.SalesNumber      = value.SalesNumber;
                NewSale.SalesDate        = SalesDate.Value;
                NewSale.RenewalDate      = RenewalDate.Value;
                NewSale.ExpiryDate       = ExpiryDate.Value;
                NewSale.Particulars      = value.Particulars;
                NewSale.Quantity         = value.Quantity;
                NewSale.Price            = value.Price;
                NewSale.Amount           = value.Amount;
                NewSale.IsActive         = value.IsActive;
                NewSale.IsRefunded       = value.IsRefunded;

                db.TrnSales.InsertOnSubmit(NewSale);
                db.SubmitChanges();

                return(NewSale.Id);
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 10
0
        public int AddUserRole(string Username, string Role, bool Change)
        {
            try
            {
                var id = (from m in db.MstUsers
                          join n in db.AspNetUsers on m.AspNetUserId equals n.Id
                          where m.UserName == Username
                          select new Models.User
                {
                    AspNetUserId = m.AspNetUserId
                }).ToList();

                var AspNetUserId = id[0].AspNetUserId;

                Data.AspNetUserRole NewRole = new Data.AspNetUserRole();

                NewRole.UserId = AspNetUserId;
                NewRole.RoleId = Role;

                if (Change)
                {
                    db.AspNetUserRoles.InsertOnSubmit(NewRole);
                }
                try
                {
                    db.SubmitChanges();
                    return(1);
                }
                catch
                {
                    return(0);
                }
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 11
0
        // Logs user tradier access
        private void logAccess(string log)
        {
            try
            {
                Data.SysAcessLog NewAccessLog = new Data.SysAcessLog();

                string currentUserName = User.Identity.Name;

                NewAccessLog.UserId      = (from d in db.MstUsers where d.UserName.Equals(currentUserName) select d).FirstOrDefault().Id;
                NewAccessLog.LogDateTime = DateTime.Now;
                NewAccessLog.Log         = log;

                db.SysAcessLogs.InsertOnSubmit(NewAccessLog);
                db.SubmitChanges();
            }
            catch { }
        }
        public long GetInformationForMarriottTampa2018(string name, string email, string phone)
        {
            try
            {
                Data.TmpWorkshop workshopInfo = new Data.TmpWorkshop();

                workshopInfo.Name        = name;
                workshopInfo.Email       = email;
                workshopInfo.Phone       = phone;
                workshopInfo.DateEncoded = DateTime.Today;
                workshopInfo.Workshop    = "Marriott Tampa 2018";

                db.TmpWorkshops.InsertOnSubmit(workshopInfo);
                db.SubmitChanges();

                return(workshopInfo.Id);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
        public int Post(Models.Sector Value)
        {
            try
            {
                Data.TrnSector NewSector = new Data.TrnSector();

                NewSector.Sector     = Value.SectorCode;
                NewSector.Definition = Value.SectorDefinition;

                db.TrnSectors.InsertOnSubmit(NewSector);
                db.SubmitChanges();

                return(NewSector.Id);
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 14
0
        public HttpResponseMessage GetDeleteUserFavorites(String FavoriteName)
        {
            List <Models.Favorite> favorites = new List <Models.Favorite>();
            string currentUserName           = User.Identity.Name;
            long   userId = 0;

            try
            {
                userId = (from d in db.MstUsers where d.UserName.Equals(currentUserName) select d).FirstOrDefault().Id;

                var data = db.TrnFavorites.Where(d => d.UserId == userId && d.Remarks.Equals(FavoriteName));
                foreach (Data.TrnFavorite d in data)
                {
                    db.TrnFavorites.DeleteOnSubmit(d);
                    db.SubmitChanges();
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 15
0
        // Add User Alert Symbols in the Database
        private void GetResultSymbols(long userAlertId)
        {
            bool symbolFilter;
            bool strategyFilter;
            bool macdFilter;
            bool magentaChannelFilter;
            bool seasonalityFilter;
            bool additionalFilter;

            if (userAlertId > 0)
            {
                var userAlerts = from d in db.TrnUserAlerts where d.Id == userAlertId select d;
                if (userAlerts.Any())
                {
                    // Filter symbols
                    List <Data.MstSymbol> symbolResults = new List <Data.MstSymbol>();
                    symbolFilter         = userAlerts.First().SymbolFilter;
                    strategyFilter       = userAlerts.First().StrategyFilter;
                    macdFilter           = userAlerts.First().MACDFilter;
                    magentaChannelFilter = userAlerts.First().MagentaChannelFilter;
                    seasonalityFilter    = userAlerts.First().SeasonalityFilter;
                    additionalFilter     = userAlerts.First().AdditionalFilter;

                    if (symbolFilter == true)
                    {
                        symbolResults = GetResultLevelSymbol(userAlertId);
                        if (strategyFilter == true)
                        {
                            symbolResults = GetResultLevelStrategy(userAlertId, symbolResults);
                        }
                        if (macdFilter == true)
                        {
                            symbolResults = GetResultLevelMACD(userAlertId, symbolResults);
                        }
                        if (magentaChannelFilter == true)
                        {
                            symbolResults = GetResultLevelMagentaChannel(userAlertId, symbolResults);
                        }
                        if (seasonalityFilter == true)
                        {
                            symbolResults = GetResultLevelSeasonality(userAlertId, symbolResults);
                        }
                        if (additionalFilter == true)
                        {
                            symbolResults = GetResultLevelAdditionalFilter(userAlertId, symbolResults);
                        }
                    }

                    // Delete existing data
                    var userAlertSymbols = from d in db.TrnUserAlertSymbols where d.UserAlertId == userAlertId select d;
                    if (userAlertSymbols.Any())
                    {
                        foreach (Data.TrnUserAlertSymbol s in userAlertSymbols)
                        {
                            db.TrnUserAlertSymbols.DeleteOnSubmit(s);
                            db.SubmitChanges();
                        }
                    }

                    // Add symbols
                    if (symbolResults.Any())
                    {
                        foreach (var s in symbolResults)
                        {
                            Data.TrnUserAlertSymbol newUserAlertSymbol = new Data.TrnUserAlertSymbol();

                            newUserAlertSymbol.UserAlertId = Convert.ToInt16(userAlertId);
                            newUserAlertSymbol.SymbolId    = s.Id;
                            newUserAlertSymbol.Symbol      = s.Symbol;
                            newUserAlertSymbol.Trend       = "";
                            newUserAlertSymbol.EncodedDate = userAlerts.First().EncodedDate;

                            db.TrnUserAlertSymbols.InsertOnSubmit(newUserAlertSymbol);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        // Add User Alert Symbols in the Database
        private void GetResultSymbols(long userAlertId)
        {
            string  strategy;
            string  exchange;
            decimal price;
            decimal volume;
            decimal growthDecayRate;
            string  growthDecayTime;
            int     noOfYears;
            decimal correlation30;

            if (userAlertId > 0)
            {
                var userAlerts = from d in db.TrnUserAlerts where d.Id == userAlertId select d;
                if (userAlerts.Any())
                {
                    strategy        = userAlerts.First().Strategy;
                    exchange        = userAlerts.First().Exchange;
                    price           = userAlerts.First().Price;
                    volume          = userAlerts.First().Volume;
                    growthDecayRate = userAlerts.First().GrowthDecayRate;
                    growthDecayTime = userAlerts.First().GrowthDecayTime;
                    noOfYears       = userAlerts.First().NoOfYears;
                    correlation30   = userAlerts.First().Correlation30;

                    var symbols = from d in db.MstSymbols where d.Exchange == "NA" select d;
                    if (strategy == "MED")
                    {
                        // Magenta Early Down
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.MACDGrowthDecayRate < 0) &&
                                  (d.EMAGrowthDecayRate < 0)
                                  select d;
                    }
                    else if (strategy == "MEU")
                    {
                        // Magenta Early Up
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.MACDGrowthDecayRate >= 0) &&
                                  (d.EMAGrowthDecayRate >= 0)
                                  select d;
                    }
                    else
                    {
                        // Customized
                        symbols = from d in db.MstSymbols
                                  where (exchange == "All" ? true : d.Exchange == exchange) &&
                                  (d.ClosePrice >= price) &&
                                  (d.Exchange == "FOREX" ? true : d.Volume >= volume) &&
                                  (d.NoOfYears >= noOfYears) &&
                                  (d.CorrelationCoefficient30 >= (correlation30 / 100)) &&
                                  (growthDecayTime == "C0" && growthDecayRate >= 0 ? ((d.GrowthDecayRate.Value == null ? 0 : d.GrowthDecayRate.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "C0" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRate.Value == null ? 0 : d.GrowthDecayRate.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W1" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW1.Value == null ? 0 : d.GrowthDecayRateW1.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W1" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW1.Value == null ? 0 : d.GrowthDecayRateW1.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W2" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW2.Value == null ? 0 : d.GrowthDecayRateW2.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W2" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW2.Value == null ? 0 : d.GrowthDecayRateW2.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "W3" && growthDecayRate >= 0 ? ((d.GrowthDecayRateW3.Value == null ? 0 : d.GrowthDecayRateW3.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "W3" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateW3.Value == null ? 0 : d.GrowthDecayRateW3.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M1" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM1.Value == null ? 0 : d.GrowthDecayRateM1.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M1" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM1.Value == null ? 0 : d.GrowthDecayRateM1.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M2" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM2.Value == null ? 0 : d.GrowthDecayRateM2.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M2" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM2.Value == null ? 0 : d.GrowthDecayRateM2.Value) ? true : false) : true) == true &&
                                  (growthDecayTime == "M3" && growthDecayRate >= 0 ? ((d.GrowthDecayRateM3.Value == null ? 0 : d.GrowthDecayRateM3.Value) >= growthDecayRate ? true : false) : true) == true &&
                                  (growthDecayTime == "M3" && growthDecayRate < 0 ? (growthDecayRate >= (d.GrowthDecayRateM3.Value == null ? 0 : d.GrowthDecayRateM3.Value) ? true : false) : true) == true
                                  select d;
                    }

                    // Delete existing data
                    var userAlertSymbols = from d in db.TrnUserAlertSymbols where d.UserAlertId == userAlertId select d;
                    if (userAlertSymbols.Any())
                    {
                        foreach (Data.TrnUserAlertSymbol s in userAlertSymbols)
                        {
                            db.TrnUserAlertSymbols.DeleteOnSubmit(s);
                            db.SubmitChanges();
                        }
                    }

                    if (symbols.Any())
                    {
                        // Add symbols
                        foreach (var s in symbols)
                        {
                            Data.TrnUserAlertSymbol newUserAlertSymbol = new Data.TrnUserAlertSymbol();

                            newUserAlertSymbol.UserAlertId = Convert.ToInt16(userAlertId);
                            newUserAlertSymbol.SymbolId    = s.Id;
                            newUserAlertSymbol.Symbol      = s.Symbol;
                            newUserAlertSymbol.Trend       = "";
                            newUserAlertSymbol.EncodedDate = userAlerts.First().EncodedDate;

                            db.TrnUserAlertSymbols.InsertOnSubmit(newUserAlertSymbol);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }
        public HttpResponseMessage GetZacksEarnings(string symbol)
        {
            try
            {
                WebRequest req = HttpWebRequest.Create("https://www.zacks.com/stock/research/" + symbol + "/earnings-announcements");
                req.Method = "GET";

                string source                = "";
                string parseSource           = "";
                string earningString         = "";
                bool   continueEarningString = false;
                long   i = 1;

                using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { source = reader.ReadToEnd(); }

                foreach (char c in source)
                {
                    if (i > 4)
                    {
                        if (parseSource == "[  [")
                        {
                            earningString         = parseSource;
                            continueEarningString = true;
                        }
                        else if (parseSource == "]  ]")
                        {
                            var array = JArray.Parse(earningString);
                            List <Models.StockEarning> earnings = new List <Models.StockEarning>();
                            var      symbols = from d in db.MstSymbols where d.Symbol == symbol select d;
                            DateTime maxDate = DateTime.MinValue;
                            DateTime minDate = DateTime.MinValue;
                            if (symbols.Any())
                            {
                                foreach (var a in array)
                                {
                                    DateTime earningDate    = Convert.ToDateTime(a[0].ToString());
                                    string   periodEnding   = a[1].ToString();
                                    Decimal  estimatedValue = a[2].ToString() == "--" ? Decimal.Parse("0") : Decimal.Parse(a[2].ToString().Replace("$", ""));
                                    Decimal  reportedValue  = a[3].ToString() == "--" ? Decimal.Parse("0") : Decimal.Parse(a[3].ToString().Replace("$", ""));
                                    string   earningTime    = a[5].ToString() == "--" ? "Before Open" : a[5].ToString();
                                    if (earningTime == "Before Open")
                                    {
                                        earningTime = "Before Market Open";
                                    }
                                    else
                                    {
                                        earningTime = "After Market Close";
                                    }

                                    Models.StockEarning e = new Models.StockEarning();
                                    e.SymbolId       = symbols.FirstOrDefault().Id;
                                    e.Symbol         = symbols.FirstOrDefault().Symbol;
                                    e.EarningDate    = a[0].ToString();
                                    e.EarningTime    = earningTime;
                                    e.PeriodEnding   = periodEnding;
                                    e.EstimatedValue = estimatedValue;
                                    e.ReportedValue  = reportedValue;
                                    earnings.Add(e);

                                    if (maxDate == DateTime.MinValue)
                                    {
                                        maxDate = earningDate;
                                    }
                                    else if (earningDate > maxDate)
                                    {
                                        maxDate = earningDate;
                                    }

                                    if (minDate == DateTime.MinValue)
                                    {
                                        minDate = earningDate;
                                    }
                                    else if (earningDate < minDate)
                                    {
                                        minDate = earningDate;
                                    }
                                }

                                if (earnings.Any())
                                {
                                    // Clean existing stock earning schedule records
                                    var stockEarnings = from d in db.TrnStockEarnings
                                                        where d.Symbol == symbols.FirstOrDefault().Symbol&&
                                                        (d.EarningDate >= minDate && d.EarningDate <= maxDate)
                                                        select d;
                                    if (stockEarnings.Any())
                                    {
                                        foreach (var se in stockEarnings)
                                        {
                                            se.Symbol = "XXX-" + se.Symbol;
                                            db.SubmitChanges();
                                        }
                                    }
                                    // Add new stock earning schedule records from Zacks
                                    foreach (Models.StockEarning e in earnings)
                                    {
                                        Data.TrnStockEarning newEarnings = new Data.TrnStockEarning();

                                        DateTime    dt          = Convert.ToDateTime(e.EarningDate);
                                        SqlDateTime earningDate = new SqlDateTime(new DateTime(dt.Year, dt.Month, dt.Day));

                                        newEarnings.Symbol         = e.Symbol;
                                        newEarnings.SymbolId       = e.SymbolId;
                                        newEarnings.EarningDate    = earningDate.Value;
                                        newEarnings.EarningTime    = e.EarningTime;
                                        newEarnings.PeriodEnding   = e.PeriodEnding;
                                        newEarnings.EstimatedValue = e.EstimatedValue;
                                        newEarnings.ReportedValue  = e.ReportedValue;

                                        db.TrnStockEarnings.InsertOnSubmit(newEarnings);
                                        db.SubmitChanges();
                                    }
                                }

                                return(Request.CreateResponse(HttpStatusCode.OK));
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound));
                            }
                        }
                        else
                        {
                            if (continueEarningString == true)
                            {
                                earningString = earningString + c;
                            }
                        }
                        parseSource = parseSource.Substring(1, 3) + c;
                    }
                    else
                    {
                        if (parseSource.Length == 4)
                        {
                            parseSource = parseSource.Substring(1, 3) + c;
                        }
                        else
                        {
                            parseSource = parseSource + c;
                        }
                    }
                    i++;
                }

                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 18
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (model.UserName == null)
            {
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                var    response  = HttpContext.Request.Form["g-recaptcha-response"] == null ? "" : HttpContext.Request.Form["g-recaptcha-response"];
                string secretKey = "6Lc5GBoTAAAAAOQFNfUBzRtzN_I-vmyJzGugEx65";
                var    client    = new System.Net.WebClient();
                var    verificationResultJson = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response));
                var    verificationResult     = JsonConvert.DeserializeObject <CaptchaVerificationResult>(verificationResultJson);

                if (!verificationResult.Success)
                {
                    ModelState.AddModelError("", "ERROR: Invalid recaptcha challenge.");
                }
                else
                {
                    if (result.Succeeded)
                    {
                        // Add or update MstUser table
                        try
                        {
                            await SignInAsync(user, isPersistent : false);

                            Data.MagentaTradersDBDataContext db = new Data.MagentaTradersDBDataContext();

                            var Users = from d in db.MstUsers where d.UserName == model.UserName select d;

                            if (Users.Any())
                            {
                                var UpdatedUser = Users.FirstOrDefault();

                                UpdatedUser.AspNetUserId = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault().Id;

                                db.SubmitChanges();
                            }
                            else
                            {
                                Data.MstUser NewUser = new Data.MstUser();

                                NewUser.UserName         = model.UserName;
                                NewUser.FirstName        = model.FirstName == null || model.FirstName.Length == 0 ? "NA" : model.FirstName;
                                NewUser.LastName         = model.LastName == null || model.LastName.Length == 0 ? "NA" : model.LastName;
                                NewUser.EmailAddress     = model.EmailAddress == null || model.EmailAddress.Length == 0 ? "NA" : model.EmailAddress;
                                NewUser.PhoneNumber      = model.PhoneNumber == null || model.PhoneNumber.Length == 0 ? "NA" : model.PhoneNumber;
                                NewUser.Address          = model.Address == null || model.Address.Length == 0 ? "" : model.Address;
                                NewUser.ReferralUserName = model.ReferralUserName == null || model.ReferralUserName.Length == 0 ? "" : model.ReferralUserName;
                                NewUser.AspNetUserId     = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault().Id;

                                DateTime    dateCreated    = DateTime.Now;
                                SqlDateTime dateCreatedSQL = new SqlDateTime(new DateTime(dateCreated.Year, +
                                                                                          dateCreated.Month, +
                                                                                          dateCreated.Day));
                                NewUser.DateCreated = dateCreatedSQL.Value;

                                db.MstUsers.InsertOnSubmit(NewUser);
                                db.SubmitChanges();

                                Data.AspNetUserRole NewRole1 = new Data.AspNetUserRole();

                                NewRole1.AspNetUser = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault();
                                NewRole1.AspNetRole = db.AspNetRoles.Where(d => d.Name == "Quest").FirstOrDefault();

                                db.AspNetUserRoles.InsertOnSubmit(NewRole1);
                                db.SubmitChanges();

                                Data.AspNetUserRole NewRole2 = new Data.AspNetUserRole();

                                NewRole2.AspNetUser = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault();
                                NewRole2.AspNetRole = db.AspNetRoles.Where(d => d.Name == "Chart").FirstOrDefault();

                                db.AspNetUserRoles.InsertOnSubmit(NewRole2);
                                db.SubmitChanges();

                                Data.AspNetUserRole NewRole3 = new Data.AspNetUserRole();

                                NewRole3.AspNetUser = db.AspNetUsers.Where(d => d.UserName == model.UserName).FirstOrDefault();
                                NewRole3.AspNetRole = db.AspNetRoles.Where(d => d.Name == "Web99").FirstOrDefault();

                                db.AspNetUserRoles.InsertOnSubmit(NewRole3);
                                db.SubmitChanges();
                            }
                            return(RedirectToAction("Index", "Help"));
                            //return RedirectToAction("Index", "Home");
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", "ERROR: Try again. " + e.ToString());
                        }
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }