コード例 #1
0
        public OperationStatus UpdateJournal(Journal journal)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                var j = DataContext.Journals.Find(journal.Id);
                if (journal.Title != null)
                {
                    j.Title = journal.Title;
                }

                if (journal.Description != null)
                {
                    j.Description = journal.Description;
                }

                if (journal.Content != null)
                {
                    j.Content = journal.Content;
                }

                if (journal.ContentType != null)
                {
                    j.ContentType = journal.ContentType;
                }

                if (journal.FileName != null)
                {
                    j.FileName = journal.FileName;
                }

                j.ModifiedDate = DateTime.Now;

                DataContext.Entry(j).State = EntityState.Modified;
                DataContext.SaveChanges();
                opStatus.RecordsAffected++;
                RemoveJournalCache();
            }
            catch (DbEntityValidationException e)
            {
                string error = string.Empty;
                foreach (var eve in e.EntityValidationErrors)
                {
                    error += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State) + Environment.NewLine;
                }

                opStatus.CreateFromException(error, e);
                ExceptionHandler.HandleException(e);
            }
            catch (Exception e)
            {
                opStatus.CreateFromException("Error updating journal: ", e);
                ExceptionHandler.HandleException(e);
            }

            return(opStatus);
        }
コード例 #2
0
        private static async Task <OperationStatus> InsertSecuritiesAsync(IEnumerable <Security> securities, AccountAtAGlanceContext context)
        {
            foreach (var security in securities)
            {
                //Update stock's exchange ID so we don't get dups
                if (security is Stock)
                {
                    var stock = (Stock)security;
                    stock.Exchange = await context.Exchanges.FirstAsync(e => e.Title == stock.Exchange.Title);

                    context.Stocks.Add(stock);
                }
                if (security is MutualFund)
                {
                    var mutualFund = (MutualFund)security;
                    mutualFund.MorningStarRating = 4;
                    context.MutualFunds.Add(mutualFund);
                }
            }

            //Insert records
            try
            {
                await context.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                return(OperationStatus.CreateFromException("Error updating security quote.", exp));
            }
            return(new OperationStatus {
                Status = true
            });
        }
コード例 #3
0
        public OperationStatus UnSubscribe(int journalId, int userId)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                using (DataContext)
                {
                    var subscriptions = DataContext.Subscriptions.Where(u => u.JournalId == journalId && u.UserId == userId);

                    foreach (var s in subscriptions)
                    {
                        DataContext.Subscriptions.Remove(s);
                    }
                    DataContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                opStatus = OperationStatus.CreateFromException("Error deleting subscription: ", e);
            }

            return(opStatus);
        }
コード例 #4
0
        private static OperationStatus InsertSecurities(IEnumerable <Security> securities, AccountAtAGlanceContext context)
        {
            foreach (var security in securities)
            {
                //Update stock's exchange ID so we don't get dups
                if (security is Stock)
                {
                    var stock = (Stock)security;
                    stock.Exchange = context.Exchanges.First(e => e.Title == stock.Exchange.Title);
                }
                if (security is MutualFund)
                {
                    ((MutualFund)security).MorningStarRating = 4;
                }
                //Add security into collection and then insert into DB
                context.Securities.Add(security);
            }

            //Insert records
            try
            {
                context.SaveChanges();
            }
            catch (Exception exp)
            {
                return(OperationStatus.CreateFromException("Error updating security quote.", exp));
            }
            return(new OperationStatus {
                Status = true
            });
        }
コード例 #5
0
ファイル: BaseBusiness.cs プロジェクト: navaei/MnFramework
        public virtual OperationStatus DeleteWhere(Expression <Func <TEntity, bool> > filter = null,
                                                   Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null,
                                                   string includeProperties = "")
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                IQueryable <TEntity> query = _dbContext.Set <TEntity>();
                if (filter != null)
                {
                    query = query.Where(filter);
                }
                foreach (var includeProperty in includeProperties.Split
                             (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    query = query.Include(includeProperty);
                }

                foreach (var entity in query)
                {
                    _dbContext.Entry(entity).State = EntityState.Deleted;
                }
                var count = _dbContext.SaveAllChanges();
                opStatus.Status          = count > 0;
                opStatus.RecordsAffected = count;
                return(opStatus);
            }
            catch (Exception exp)
            {
                return(OperationStatus.CreateFromException("Error creating " + typeof(TEntity) + ".", exp));
            }
        }
コード例 #6
0
        public OperationStatus AddJournal(Journal newJournal)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                using (DataContext)
                {
                    newJournal.ModifiedDate = DateTime.Now;
                    var j = DataContext.Journals.Add(newJournal);
                    DataContext.SaveChanges();
                    opStatus.Id = j.Id;
                    opStatus.RecordsAffected++;
                    RemoveJournalCache();
                }
            }
            catch (Exception e)
            {
                opStatus.CreateFromException("Error adding journal: ", e);
                ExceptionHandler.HandleException(e);
            }

            return(opStatus);
        }
コード例 #7
0
ファイル: Service.cs プロジェクト: jamieishere/IDSM3
        public void StartGame(int gameId)
        {
            try
            {
                List <UserTeam> _allUserTeamsForGame = _userTeams.GetList(x => x.GameId == gameId).ToList();
                if (_allUserTeamsForGame.Any())
                {
                    _allUserTeamsForGame.Shuffle();
                    foreach (UserTeam _team in _allUserTeamsForGame)
                    {
                        _team.OrderPosition = _allUserTeamsForGame.IndexOf(_team);
                    }

                    Game _game = _games.Get(x => x.Id == gameId);
                    _game.HasStarted = true;
                    MapGameToDtoAndUpdate(_game);
                }
                Save();
            }
            catch (Exception _exp)
            {
                OperationStatus.CreateFromException(String.Format("StartGame failed. gameId:{0}", gameId), _exp, true);
                throw;
            }
        }
コード例 #8
0
        public async virtual Task <OperationStatus> DeleteAllAsync <T>(Expression <Func <T, bool> > predicate) where T : class
        {
            var status = new OperationStatus {
                Status = true
            };

            try
            {
                if (predicate != null)
                {
                    IQueryable <T> toBeDeleted = DataContext.Set <T>().Where(predicate);
                    DataContext.Set <T>().RemoveRange(toBeDeleted);
                    status.Status = await DataContext.SaveChangesAsync() > 0;
                }
                else
                {
                    throw new ApplicationException("A predicate is needed");
                }
            }
            catch (Exception ex)
            {
                status = OperationStatus.CreateFromException("Error deleting list", ex);
            }
            return(status);
        }
コード例 #9
0
        public OperationStatus DeleteJournal(Journal journal)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                using (DataContext)
                {
                    var subscriptions = DataContext.Subscriptions.Where(j => j.JournalId == journal.Id);
                    foreach (var subscription in subscriptions)
                    {
                        DataContext.Subscriptions.Remove(subscription);
                    }

                    var journalToBeDeleted = DataContext.Journals.Find(journal.Id);
                    DataContext.Journals.Remove(journalToBeDeleted);
                    DataContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                opStatus = OperationStatus.CreateFromException("Error deleting journal: ", e);
            }

            return(opStatus);
        }
コード例 #10
0
ファイル: Service.cs プロジェクト: jamieishere/IDSM3
        private OperationStatus SaveUtPlayerAndUpdateGame(int userTeamId, int gameId, int pixelposy, int pixelposx, int playerId)
        {
            OperationStatus _opStatus;

            try
            {
                _opStatus = SaveUserTeamPlayer(userTeamId, gameId, 1, 1, playerId);
                Save();

                int _teamSize;
                if (int.TryParse(ConfigurationManager.AppSettings["TeamSize"], out _teamSize))
                {
                    _opStatus = UpdateGame(gameId, userTeamId, _teamSize);
                }
                else
                {
                    _opStatus = UpdateGame(gameId, userTeamId, 1);
                }

                Save();
            }
            catch (Exception exp)
            {
                _opStatus = OperationStatus.CreateFromException("Error saving player and updating game: " + exp.Message, exp);
            }

            return(_opStatus);
        }
コード例 #11
0
        public async Task <OperationStatus> InsertMarketDataAsync()
        {
            var marketIndexes = await _StockEngine.GetMarketQuotesAsync(_MarketIndexSymbols);

            if (marketIndexes != null && marketIndexes.Count > 0)
            {
                var opStatus = DeleteMarketIndexRecords(DataContext);
                if (!opStatus.Status)
                {
                    return(opStatus);
                }

                foreach (var marketIndex in marketIndexes)
                {
                    DataContext.MarketIndexes.Add(marketIndex);
                }

                try
                {
                    await DataContext.SaveChangesAsync();
                }
                catch (Exception exp)
                {
                    return(OperationStatus.CreateFromException("Error inserting market index data.", exp));
                }
            }
            return(new OperationStatus {
                Status = true
            });
        }
コード例 #12
0
        //could use void, this is a good practice
        public OperationStatus UpdateCustomers()
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            //if (localdataonly) return opStatus;

            //blah blah blah

            //insert records
            try
            {
                DataContext.SaveChanges();
            }
            catch (Exception exp)
            {
                //var opstatus = OperationStatus.CreateFromException("Error updating customers", exp);
                //Logger.Log(opStatus);
                //return opstatus;

                return(OperationStatus.CreateFromException("Error updating sth", exp));
            }
            return(opStatus);
        }
コード例 #13
0
        public OperationStatus AddSubscription(int journalId, int userId)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                using (DataContext)
                {
                    Subscription s = new Subscription();
                    s.JournalId = journalId;
                    s.UserId    = userId;
                    var j = DataContext.Subscriptions.Add(s);
                    DataContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                opStatus.CreateFromException("Error adding subscription: ", e);
                ExceptionHandler.HandleException(e);
            }

            return(opStatus);
        }
コード例 #14
0
        public OperationStatus DeleteTimesheet(int id)
        {
            var opStatus = new OperationStatus();

            try
            {
                var timesheet = DataContext.Timesheets
                                .Include(ts => ts.Rows)
                                .SingleOrDefault(ts => ts.ID == id);
                if (timesheet != null)
                {
                    DataContext.Timesheets.Remove(timesheet);
                    DataContext.SaveChanges();
                    opStatus.Status = true;
                }
                else
                {
                    opStatus.Message = "Unable to delete timesheet - not found";
                }
            }
            catch (Exception exp)
            {
                OperationStatus.CreateFromException("Error inserting timesheet", exp);
            }
            return(opStatus);
        }
コード例 #15
0
        public OperationStatus UpdateTimesheet(Timesheet timesheet)
        {
            var opStatus = new OperationStatus();

            try
            {
                var originalTimesheet = DataContext.Timesheets
                                        .Include(ts => ts.Rows)
                                        .SingleOrDefault(ts => ts.ID == timesheet.ID);
                if (originalTimesheet != null)
                {
                    DataContext.Timesheets.Remove(originalTimesheet);
                    DataContext.Timesheets.Add(timesheet);
                    DataContext.SaveChanges();
                    opStatus.Status = true;
                }
                else
                {
                    opStatus.Message = "Unable to update timesheet";
                }
            }
            catch (Exception exp)
            {
                OperationStatus.CreateFromException("Error inserting timesheet", exp);
            }
            return(opStatus);
        }
コード例 #16
0
 private async Task <OperationStatus> DeleteSecurityRecordsAsync(AccountAtAGlanceContext context)
 {
     try
     {
         return(await context.DeleteSecuritiesAndExchanges());
     }
     catch (Exception exp)
     {
         return(OperationStatus.CreateFromException("Error deleting security/exchange data.", exp));
     }
 }
コード例 #17
0
        public OperationStatus UpdateJournal(Journal journal)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                var j = DataContext.Journals.Find(journal.Id);
                if (journal.Title != null)
                {
                    j.Title = journal.Title;
                }

                if (journal.Description != null)
                {
                    j.Description = journal.Description;
                }

                if (journal.Content != null)
                {
                    j.Content = journal.Content;
                }

                if (journal.ContentType != null)
                {
                    j.ContentType = journal.ContentType;
                }

                if (journal.FileName != null)
                {
                    j.FileName = journal.FileName;
                }

                j.ModifiedDate = DateTime.Now;

                DataContext.Entry(j).State = EntityState.Modified;
                DataContext.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    OperationStatus.CreateFromException(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State), e);
                }
            }
            catch (Exception e)
            {
                opStatus = OperationStatus.CreateFromException("Error updating journal: ", e);
            }

            return(opStatus);
        }
コード例 #18
0
 protected virtual IQueryable <T> GetList <T>() where T : class
 {
     try
     {
         return(DataContext.Set <T>());
     }
     catch (Exception exp)
     {
         OperationStatus.CreateFromException("Error executing GetLIst<T>: ", exp);
     }
     return(null);
 }
コード例 #19
0
 protected virtual IQueryable <T> GetList <T, TKey>(Expression <Func <T, TKey> > orderBy) where T : class
 {
     try
     {
         return(GetList <T>().OrderBy(orderBy));
     }
     catch (Exception exp)
     {
         OperationStatus.CreateFromException("Error executing GetList<T, TKey>: ", exp);
     }
     return(null);
 }
コード例 #20
0
        public OperationStatus RefreshAccountsData()
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            using (var ts = new TransactionScope())
            {
                using (DataContext)
                {
                    var securities = DataContext.Securities.ToList();
                    try
                    {
                        //Delete existing account info
                        opStatus.Status = DataContext.DeleteAccounts() >= 0;

                        if (opStatus.Status)
                        {
                            var cust = new Customer
                            {
                                FirstName    = "Marcus",
                                LastName     = "Hightower",
                                Address      = "1234 Anywhere St.",
                                City         = "Phoenix",
                                State        = "AZ",
                                Zip          = 85229,
                                CustomerCode = "C15643",
                            };

                            AddBrokerageAccounts(securities, cust);
                            DataContext.Customers.Add(cust);


                            opStatus.Status = DataContext.SaveChanges() > 0;
                        }
                    }
                    catch (Exception exp)
                    {
                        opStatus = OperationStatus.CreateFromException("Error updating security exchange: " + exp.Message, exp);
                    }
                }

                if (opStatus.Status)
                {
                    ts.Complete();
                }
            } //end transactionscope

            return(opStatus);
        }
コード例 #21
0
 private OperationStatus DeleteMarketIndexRecords(AccountAtAGlanceContext context)
 {
     try
     {
         ExecuteStoreCommand("DELETE FROM MarketIndex;");
     }
     catch (Exception exp)
     {
         return(OperationStatus.CreateFromException("Error deleting market index data.", exp));
     }
     return(new OperationStatus {
         Status = true
     });
 }
コード例 #22
0
ファイル: HomeController.cs プロジェクト: jamieishere/IDSM3
        public ActionResult Upload(HttpPostedFileBase FileUpload)
        {
            var opStatus = new OperationStatus()
            {
                Status = false
            };

            if (FileUpload != null && FileUpload.ContentLength > 0)
            {
                string fileName = Path.GetFileName(FileUpload.FileName);

                string path = Path.Combine(ConfigurationManager.AppSettings["AppDataUploadsPath"], fileName);

                // take the upload file and save to the app_data/uploads folder.
                try
                {
                    opStatus.Status = true;
                    FileUpload.SaveAs(path);
                }
                catch (Exception ex)
                {
                    opStatus = OperationStatus.CreateFromException("Error saving CSV file to " + path, ex);
                    ILogger _logger = LogFactory.Logger();
                    _logger.Error(opStatus.Message, ex);
                }

                // process the csv and save players to database
                if (opStatus.Status)
                {
                    try
                    {
                        //opStatus = PlayerRepository.UploadPlayersCSV(path);
                    }
                    catch (Exception ex)
                    {
                        opStatus = OperationStatus.CreateFromException("Error saving Players from csv file to database", ex);
                        ILogger _logger = LogFactory.Logger();
                        _logger.Error(opStatus.Message, ex);
                    }
                }
            }
            else
            {
                opStatus = OperationStatus.CreateFromException("Please select a file", null);
            }

            ViewBag.OperationStatus = opStatus;
            return(View());
        }
        public OperationStatus UpdateSecurities()
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            if (localDataOnly)
            {
                return(opStatus);
            }

            var securities        = DataContext.Securities; //Get existing securities
            var engine            = new StockEngine();
            var updatedSecurities = engine.GetSecurityQuotes(securities.Select(s => s.Symbol).ToArray());

            //Return if updatedSecurities is null
            if (updatedSecurities == null)
            {
                return new OperationStatus {
                           Status = false
                }
            }
            ;

            foreach (var security in securities)
            {
                //Grab updated version of security
                var updatedSecurity = updatedSecurities.Where(s => s.Symbol == security.Symbol).Single();

                security.Change                   = updatedSecurity.Change;
                security.Last                     = updatedSecurity.Last;
                security.PercentChange            = updatedSecurity.PercentChange;
                security.RetrievalDateTime        = updatedSecurity.RetrievalDateTime;
                security.Shares                   = updatedSecurity.Shares;
                DataContext.Entry(security).State = System.Data.EntityState.Modified;
            }

            //Insert records
            try
            {
                DataContext.SaveChanges();
            }
            catch (Exception exp)
            {
                return(OperationStatus.CreateFromException("Error updating security quote.", exp));
            }
            return(opStatus);
        }
コード例 #24
0
        public virtual OperationStatus Save <T>(T entity) where T : class
        {
            OperationStatus opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                opStatus.Status = DataContext.SaveChanges() > 0;
            }
            catch (Exception ex)
            {
                opStatus = OperationStatus.CreateFromException("Error Saving " + typeof(T) + ".", ex);
            }
            return(opStatus);
        }
コード例 #25
0
        protected OperationStatus ExecuteStoreCommand(string cmdText, params object[] parameters)
        {
            var opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                opStatus.RecordsAffected = DataContext.Database.ExecuteSqlCommand(cmdText, parameters);
            }
            catch (Exception exp)
            {
                OperationStatus.CreateFromException("Error executing store command: ", exp);
            }
            return(opStatus);
        }
コード例 #26
0
ファイル: Service.cs プロジェクト: jamieishere/IDSM3
 public void AddBanter(int gameId, int userTeamId, string banter)
 {
     try
     {
         _banters.Create(new Banter()
         {
             GameId = gameId, UserTeamId = userTeamId, BanterText = banter, TimeStamp = DateTime.Now
         });
         Save();
     }
     catch (Exception _exp)
     {
         OperationStatus.CreateFromException(String.Format("AddBanter failed. userTeamId:{0}", userTeamId), _exp, true);
         throw;
     }
 }
コード例 #27
0
ファイル: Service.cs プロジェクト: jamieishere/IDSM3
 public AddUserTeamViewModel GetAddUserTeamViewModelForGame(Game game)
 {
     try
     {
         IEnumerable <UserProfile> _allusers = _users.GetList();
         return(new AddUserTeamViewModel()
         {
             Users = _allusers, Game = game
         });
     }
     catch (Exception _exp)
     {
         OperationStatus.CreateFromException(String.Format("GetAddUserTeamViewModelForGame failed. gameid:{0}", game.Id), _exp, true);
         throw;
     }
 }
コード例 #28
0
        public async Task <OperationStatus> DeleteAccounts()
        {
            OperationStatus opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                await Task.Run(() => Database.ExecuteSqlCommand("DeleteAccounts"));
            }
            catch (Exception exp)
            {
                return(OperationStatus.CreateFromException(exp.Message, exp));
            }
            return(opStatus);
        }
コード例 #29
0
ファイル: BaseBusiness.cs プロジェクト: navaei/MnFramework
        //public virtual IQueryable<TEntity> Include<TEntity>(this ObjectQuery<TEntity> query, Expression<Func<TEntity, object>> selector)
        //{
        //    string propertyName = GetPropertyName(selector);
        //    return query.Include(propertyName);
        //}
        public virtual OperationStatus Save()
        {
            OperationStatus opStatus = new OperationStatus {
                Status = true
            };

            try
            {
                opStatus.Status = _dbContext.SaveAllChanges() > 0;
            }
            catch (Exception exp)
            {
                opStatus = OperationStatus.CreateFromException("Error saving " + typeof(TEntity) + ".", exp);
            }

            return(opStatus);
        }
コード例 #30
0
 protected virtual IQueryable <T> GetList <T>(Expression <Func <T, bool> > predicate) where T : class
 {
     try
     {
         var coll = DataContext.Set <T>();
         if (predicate != null)
         {
             return(coll.Where(predicate));
         }
         return(coll);
     }
     catch (Exception exp)
     {
         OperationStatus.CreateFromException("Error executing GetList<T>: ", exp);
     }
     return(null);
 }