public IQueryable <ReturnRaceModel> GetAll( [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { return(this.ExecuteOperationAndHandleExceptions(() => { var context = new GameContext(); var user = BasePersister.GetUserBySessionKey(sessionKey, context); if (user == null) { throw new NullReferenceException(); } var races = context.Races; var models = (from r in races select new ReturnRaceModel { Id = r.Id, Name = r.Name }); return models; })); }
public HttpResponseMessage GetHeroUnits(int id, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { return(this.ExecuteOperationAndHandleExceptions(() => { var context = new GameContext(); var user = BasePersister.GetUserBySessionKey(sessionKey, context); if (user == null) { throw new InvalidOperationException("Invalid username or password!"); } var units = context.Units.Where(h => h.Hero.Id == id); var models = ( from u in units select new ViewUnitModel { Id = u.Id, Name = u.Name, Image = u.Image, Health = u.Health, Attack = u.Attack, Defense = u.Defense, Damage = u.Damage, Speed = u.Speed }); var response = this.Request.CreateResponse(HttpStatusCode.OK, models); return response; })); }
public WizardModelView(T dto) : base(typeof(WizardModelView <>).Name) { Dto = dto; FinishCommand = new RelayCommand(OnFinishCommand); CancelCommand = new RelayCommand(OnCancelCommand); InfoVisibility = Visibility.Visible; ValidationMessageVisibility = Visibility.Hidden; _crudService = (ICRUDService <T>)ServiceActivator.Get(HandlerUtils.DTO_TO_SERVICE[typeof(T)]); _persister = new BasePersister <T>(_crudService, Dto); CreateTitle(); }
public HttpResponseMessage GetAllHeros( [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { return(this.ExecuteOperationAndHandleExceptions(() => { var context = new GameContext(); var user = BasePersister.GetUserBySessionKey(sessionKey, context); if (user == null) { throw new InvalidOperationException("Invalid username or password!"); } var heroes = user.Heroes; var models = ( from h in heroes select new ViewHeroModel { Id = h.Id, Name = h.Name, Image = h.Image, Money = h.Money, NumberOfWins = h.NumberOfWins, NumberOfLoses = h.NumberOfLoses, Level = h.Level, Race = h.Race.Name, Points = h.Points }); var response = this.Request.CreateResponse(HttpStatusCode.OK, models); return response; })); }
public HttpResponseMessage CreateHeroe(CreateHeroeModel model, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { return(this.ExecuteOperationAndHandleExceptions(() => { var context = new GameContext(); var user = BasePersister.GetUserBySessionKey(sessionKey, context); if (user == null) { throw new InvalidOperationException("Invalid username or password!"); } HeroePersister.ValidateCreateHeroe(model, context); Hero newHeroe = new Hero() { Name = model.Name, Race = context.Races.First(r => r.Id == model.Race), Level = StartHeroeLevel, Points = StartHeroePoints, Money = StartHeroeMoney, NumberOfLoses = 0, NumberOfWins = 0, User = BasePersister.GetUserBySessionKey(sessionKey, context), Units = new HashSet <Unit>() }; context.Heroes.Add(newHeroe); context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.NoContent); return response; })); }
public void SetPersister(BasePersister <T> persister) { _persister = persister; }