public static EntityWrap <TEntity> TrackCollection <TEntity, T>(this EntityWrap <TEntity> src, IEnumerable <T> origin, ICollection <T> current) where TEntity : HotelData where T : HotelDataOwnId { var deleted = origin.Where(o => current.FirstOrDefault(c => c.Id == o.Id) == null).ToList(); src.CollectionList.Add(deleted); return(src); }
public static EntityWrap <TEntity> IncludeCompany <TEntity>(this TEntity src, Type tp) where TEntity : HotelData { var res = new EntityWrap <TEntity>() { Src = src }; res.CompanyList.Add(tp); return(res); }
public static EntityWrap <TEntity> ExcludeTrack <TEntity>(this TEntity src, Type tp) where TEntity : HotelData { var res = new EntityWrap <TEntity>() { Src = src }; res.ExclusionList.Add(tp); return(res); }
public static EntityWrap <TEntity> TrackCollection <TEntity, T>(this TEntity src, IQueryable <T> origin, ICollection <T> current) where TEntity : HotelData where T : HotelDataOwnId { var res = new EntityWrap <TEntity>() { Src = src }; res.TrackCollection(origin, current); return(res); }
public virtual async Task <IActionResult> UpdateEntityAsync(TModel entity, EntityWrap <TModel> wrap = null) { if (!ModelState.IsValid) { return(PartialView(entity)); } OnBeforeUpdateEntity(entity); bool res = await _generalRepo.UpdateEntityAsync(entity, wrap); OnAfterUpdateEntity(entity); if (!res) { return(NotFound()); } return(UpdateOk()); }
public override void LoadContent() { entityFactory = new EntityFactory(new NormalBodyFactory(world)); var entitySet = EntitySets.GameStateSet(entityFactory); var User = Chat.ChatRoom.users.Where(x => x.Value.Admin).FirstOrDefault(); var enemyUser = Chat.ChatRoom.users.Where(x => !x.Value.Admin).FirstOrDefault(); ball = entityFactory.CreateDynamicCircle(520, 435, 15f, "Ball", true); player = entityFactory.CreateDynamicPlayer(917, 752, 30, $"{User.Key},{User.Value.Skin}", true); enemyPlayer = entityFactory.CreateDynamicPlayer(112, 752, 30, $"{enemyUser.Key},{enemyUser.Value.Skin}", true); foot = entityFactory.CreateDynamicBox(250, 350, new Vector2(35, 10), "rfoot", true); enemyFoot = entityFactory.CreateDynamicBox(250, 350, new Vector2(60, 10), "foot", true); legJoint = entityFactory.CreateRevoluteJointJoint(player, foot); enemyLegJoint = entityFactory.CreateRevoluteJointJoint(enemyPlayer, enemyFoot, true); playerFootSpeed = legJoint.MotorSpeed; enemyFootSpeed = enemyLegJoint.MotorSpeed; ballPosition = ball.body.Position; playerPosition = player.body.Position; enemyPlayerPosition = enemyPlayer.body.Position; entitySet.Add(ball); entitySet.Add(enemyPlayer); entitySet.Add(player); entitySet.Add(foot); entitySet.Add(enemyFoot); Game.Game.Entities = entitySet; var inputHandler = new InputHandler(); inputHandler.ReciveHandler = handleInput; if (UDPServer is null) { UDPServer = new UDPServer <Frame>(1337); } MyContactListener.playerScore += PlayerScore; MyContactListener.enemyScore += EnemyScore; Game.Game.IsLive = true; isLoaded = true; }
public static EntityWrap <TEntity> ExcludeTrack <TEntity>(this EntityWrap <TEntity> src, Type tp) where TEntity : HotelData { src.ExclusionList.Add(tp); return(src); }
private static void PostApplyWraps <TEntity>(this TEntity entity, AppDbContext _context, EntityWrap <TEntity> wrap, int companyId) where TEntity : HotelDataOwnId { // return; foreach (var entry in _context.ChangeTracker.Entries()) { if (wrap.ExclusionList.Contains(entry.Entity.GetType())) { entry.State = EntityState.Unchanged; //_context.Entry(entry.Entity).State = EntityState.Detached; } if (wrap.CompanyList.Contains(entry.Entity.GetType())) { (entry.Entity as HotelData).AssignCompantAttr(companyId); } } }
private static void PreApplyWraps <TEntity>(this TEntity entity, AppDbContext _context, EntityWrap <TEntity> wrap) where TEntity : HotelDataOwnId { foreach (var dels in wrap.CollectionList) { entity.TrackCollection(_context, dels); } foreach (var entry in _context.ChangeTracker.Entries()) { if (entry.State != EntityState.Deleted) { entry.State = EntityState.Detached; } } }
private static void PreApplyWraps <TEntity>(this Controller ctl, TEntity entity, AppDbContext _context, EntityWrap <TEntity> wrap) where TEntity : HotelDataOwnId { entity.PreApplyWraps(_context, wrap); }
public static async Task <bool> UpdateDBCompanyDataAsync <TEntity>(this TEntity entity, AppDbContext _context, ILogger <HotelUser> _logger, int companyId, EntityWrap <TEntity> wrap = null) where TEntity : HotelDataOwnId { try { if (wrap != null) { entity.PreApplyWraps(_context, wrap); } entity.AssignCompantAttr(companyId); _context.Update(entity); var entry = _context.Entry(entity); if (entry.State == EntityState.Modified) { if (entry.OriginalValues.GetValue <int>("HotelId") != companyId) //something wrong with hack { throw new Exception("Fobidden"); } } if (wrap != null) { entity.PostApplyWraps(_context, wrap, companyId); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException exdb) { _logger.LogError(exdb, "Update {0}", entity.GetType().Name); if (_context.Find(entity.GetType(), entity.Id) == null) { return(false); } return(true); } catch (Exception ex) { _logger.LogError(ex, "Update {0}", entity.GetType().Name); return(false); //to do } return(true); }
public static async Task <IActionResult> UpdateDBCompanyDataAsyncEx2 <TEntity, TController>(this TController ctl, TEntity entity, ILogger <TController> _logger, Func <TEntity, Task <Result> > funcUpdate = null, EntityWrap <TEntity> wrap = null) where TEntity : HotelDataOwnId where TController : Controller { if (!ctl.ModelState.IsValid) { return(ctl.PartialView(entity)); } if (funcUpdate != null) { var update_result = await funcUpdate(entity); if (!update_result.Success) { ctl.ModelState.AddModelError("general", update_result.Error); } return(ctl.PartialView(entity)); } return(ctl.UpdateOk()); }
public static async Task <IActionResult> UpdateDBCompanyDataAsyncEx <TEntity, TController>(this TController ctl, TEntity entity, ILogger <TController> _logger, Func <TEntity, Task <bool> > funcUpdate = null, EntityWrap <TEntity> wrap = null) where TEntity : HotelDataOwnId where TController : Controller { if (!ctl.ModelState.IsValid) { return(ctl.PartialView(entity)); } if (funcUpdate != null) { if (!await funcUpdate(entity)) { return(ctl.BadRequest()); } } return(ctl.UpdateOk()); }
public static async Task <IActionResult> UpdateCompanyDataAsync <TEntity, TController>(this TController ctl, TEntity entity, AppDbContext _context, ILogger <TController> _logger, Func <TEntity, Task <bool> > postSaveAction = null, EntityWrap <TEntity> wrap = null) where TEntity : HotelDataOwnId where TController : Controller { if (!ctl.ModelState.IsValid) { return(ctl.PartialView(entity)); } bool res = await ctl.UpdateDBCompanyDataAsync(entity, _context, _logger, wrap); if (!res) { return(ctl.NotFound()); } if (postSaveAction != null) { if (!await postSaveAction(entity)) { return(ctl.BadRequest()); } } return(ctl.UpdateOk()); }
public static async Task <IActionResult> UpdateCompanyDataAsync <TEntity, TController>(this TController ctl, EntityWrap <TEntity> wrap, AppDbContext _context, ILogger <TController> _logger, Func <TEntity, Task <bool> > postSaveAction = null) where TEntity : HotelDataOwnId where TController : Controller { return(await ctl.UpdateCompanyDataAsync(wrap.Src, _context, _logger, postSaveAction, wrap)); }
public static EntityWrap <TEntity> IncludeCompany <TEntity>(this EntityWrap <TEntity> src, Type tp) where TEntity : HotelData { src.CompanyList.Add(tp); return(src); }