Exemplo n.º 1
0
        public static OperationStatus CreateFromException(string message, Exception ex, bool doLog = false)
        {
            var _opStatus = new OperationStatus
            {
                Status = false,
                Message = message,
                OperationId = null
            };

            if (ex != null)
            {
                _opStatus.ExceptionMessage = ex.Message;
                _opStatus.ExceptionStackTrace = ex.StackTrace;
                _opStatus.ExceptionInnerMessage = (ex.InnerException == null) ? null : ex.InnerException.Message;
                _opStatus.ExceptionInnerStackTrace = (ex.InnerException == null) ? null : ex.InnerException.StackTrace;
            }

            if (doLog)
            {
                ILogger _logger = LogFactory.Logger();
                _logger.Error(message, ex);
            }

            return _opStatus;
        }
Exemplo n.º 2
0
        public void Game_AddUserToGame_Returns_ActionResult()
        {
            //Arrange
            GamesAdminController Controller = new GamesAdminController(_mockServiceLayer.Object);
            var _opStatus = new OperationStatus();
            _mockServiceLayer.Setup(s => s.AddUserToGame(123,123));

            //Act
            ActionResult result = Controller.AddUserToGame(123, 123);

            //Assert
            Assert.IsInstanceOf<ActionResult>(result);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 //
 // GET: /Upload/
 public ActionResult Upload()
 {
     var opStatus = new OperationStatus() { Status = false };
     ViewBag.OperationStatus = opStatus;
     return View();
 }
Exemplo n.º 5
0
        public OperationStatus AddUserTeamPlayer(int playerId, int userTeamId, int gameId)
        {
            Player _player = null;
            var _opStatus = new OperationStatus();
            // check a Player exists for this playerId
            if (!_players.TryGet(out _player, x => x.Id == playerId)) return _opStatus;

            try
            {
                _opStatus = SaveUtPlayerAndUpdateGame(userTeamId, gameId, 1, 1, playerId);
                Save();
            }
            catch (Exception _exp)
            {
                OperationStatus.CreateFromException(String.Format("AddUserTeamPlayer failed. playerId:{0}, userTeamId:{1}, gameId:{2}", playerId, userTeamId, gameId), _exp, true);
                throw;
            }
            return _opStatus;
        }
Exemplo n.º 6
0
        public void Game_Create_Returns_ViewResult()
        {
            //Arrange
            GamesAdminController Controller = new GamesAdminController(_mockServiceLayer.Object);
            var _opStatus = new OperationStatus();
            _mockServiceLayer.Setup(s => s.CreateGame(_game.CreatorId, _game.Name)).Returns(_opStatus);

            //Act
            ViewResult result = Controller.Create(_game);

            //Assert
            Assert.IsInstanceOf<ViewResult>(result);
        }