public static Task <List <JGN_Ads> > Load(ApplicationDbContext context, AdEntity entity) { var collectionQuery = context.JGN_Ads.Where(returnWhereClause(entity)); collectionQuery = processOptionalConditions(collectionQuery, entity); return(LoadCompleteList(collectionQuery)); }
public JsonResultEntity Create([FromBody] AdEntity adEntity) { AdBL adBL = new AdBL(); JsonResultEntity response = new JsonResultEntity(); if (UtilityHelper.ModelBindingValidator(ModelState).Length > 0) { response.Message = UtilityHelper.ModelBindingValidator(ModelState); return(response); } try { var result = adBL.Create(adEntity); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } response.Success = true; response.Data = result.Value; } catch (Exception ex) { response.Message = ex.Message; LoggerHelper.Error(ex); } return(response); }
public async Task <ActionResult <AdEntity> > PostAd(AdEntity adEntity) { _context.adInfo.Add(adEntity); await _context.SaveChangesAsync(); return(adEntity); }
public static async Task <int> Count(ApplicationDbContext context, AdEntity entity) { if (!entity.iscache || Configs.GeneralSettings.cache_duration == 0 || entity.pagenumber > Configs.GeneralSettings.max_cache_pages) { return(await CountRecords(context, entity)); } else { string key = GenerateKey("cnt_ads", entity); int records = 0; if (!SiteConfig.Cache.TryGetValue(key, out records)) { records = await CountRecords(context, entity); var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetSlidingExpiration(TimeSpan.FromSeconds(3600)); // Save data in cache. SiteConfig.Cache.Set(key, records, cacheEntryOptions); } else { records = (int)SiteConfig.Cache.Get(key); } return(records); } }
public async Task <IActionResult> PutAd(int id, AdEntity adEntity, HttpContext context) { _authService.ValidateAuthorizationPrivilege(context, whoHasAuth); await _adRepository.PutAd(id, adEntity); return(null); }
public AdEntity Create(AdEntity adEntity) { var query = @"INSERT INTO ""Ad""(""ContentID"",""ContentSource"",""AdType"",""IsActive"",""StartDate"",""StartTime"",""EndDate"",""EndTime"",""CreatedDate"",""ModifiedDate"",""AdArea"",""Weight"",""StartDateTime"",""EndDateTime"") VALUES(@ContentID,@ContentSource,@AdType,@IsActive,@StartDate,@StartTime,@EndDate,@EndTime,@CreatedDate,@ModifiedDate,@AdArea,@Weight,@StartDateTime,@EndDateTime) RETURNING ""ID"";"; int id = DbConnection.Query <int>(query, adEntity).Single(); adEntity.ID = id; return(adEntity); }
public void EnableMailBox() { var entity = new AdEntity() { SamAccountName = "BG00012", Alias = "liudehua" }; ExchangePowerShellHelper.EnableUserMailBox(entity, exconfig); }
public async Task <IActionResult> PutAdEntity(int id, AdEntity adEntity) { if (id != adEntity.Id) { return(BadRequest()); } await _adService.PutAd(id, adEntity, this.HttpContext); return(NoContent()); }
public ResultEntity <AdEntity> Create(AdEntity adEntity) { var validationResult = new ResultEntity <AdEntity>(); using (var adDA = new AdDA()) { validationResult.Value = adDA.Create(adEntity); } return(validationResult); }
public int Update(AdEntity adEntity) { int affectedRows = 0; if (IsHaveId <AdEntity>(adEntity) == false) { var query = @"UPDATE ""Ad"" SET ""ContentID""=@ContentID,""ContentSource""=@ContentSource,""AdType""=@AdType,""IsActive""=@IsActive,""StartDate""=@StartDate,""StartTime""=@StartTime,""EndDate""=@EndDate,""EndTime""=@EndTime,""CreatedDate""=@CreatedDate,""ModifiedDate""=@ModifiedDate,""AdArea""=@AdArea,""Weight""=@Weight,""StartDateTime""=@StartDateTime,""EndDateTime""=@EndDateTime WHERE ""ID""=@ID"; affectedRows = DbConnection.Execute(query, adEntity); } return(affectedRows); }
public Option <ValidationMessage> Execute(AdEntity e) { return(e.Match <AdEntity, Option <ValidationMessage> >() .Case <Problem>(p => p.Options(Repo.GetElement).IsEmpty().Then(() => ValidationMessage.Warning("No associated Option"))) .Case <OptionEntity>(o => o.Problems(Repo.GetElement).IsEmpty().Then(() => ValidationMessage.Warning("No associated Problem"))) .Case <ProblemOccurrence>(po => po.Alternatives(Repo.GetElement).IsEmpty().Then(() => ValidationMessage.Warning("No associated Option Occurrence"))) .Case <OptionOccurrence>(oo => oo.AssociatedProblemOccurrences(Repo.GetElement).IsEmpty().Then(() => ValidationMessage.Warning("No associated Problem Occurrence"))) .GetOrThrowNotImplemented()); }
public ResultEntity <AdEntity> Update(AdEntity adEntity) { var validationResult = new ResultEntity <AdEntity>(); using (var adDA = new AdDA()) { var resultUpdate = adDA.Update(adEntity); if (resultUpdate <= 0) { validationResult.Warning.Add("Failed Updating Ad!"); return(validationResult); } validationResult.Value = adEntity; } return(validationResult); }
public async Task <IActionResult> PutAd(int id, AdEntity adEntity) { if (id != adEntity.Id) { } _context.Entry(adEntity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdEntityExists(id)) { } else { throw; } } return(null); }
public async Task <ActionResult <AdEntity> > PostAd(AdEntity adEntity, HttpContext context) { _authService.ValidateAuthorizationPrivilege(context, whoHasAuth); return(await _adRepository.PostAd(adEntity)); }
public bool CanExecute(AdEntity _) { return(true); }
private static System.Linq.Expressions.Expression <Func <JGN_Ads, bool> > returnWhereClause(AdEntity entity) { var where_clause = PredicateBuilder.New <JGN_Ads>(true); if (entity.id > 0) { where_clause = where_clause.And(p => p.id == entity.id); } if (entity.type != Adtype.All) { where_clause = where_clause.And(p => p.type == (byte)entity.type); } if (entity.term != "") { where_clause = where_clause.And(p => p.adscript.Contains(entity.term) || p.name.Contains(entity.term)); } return(where_clause); }
private static IQueryable <JGN_Ads> processOptionalConditions(IQueryable <JGN_Ads> collectionQuery, AdEntity query) { if (query.order != "") { collectionQuery = (IQueryable <JGN_Ads>)collectionQuery.Sort(query.order); } if (query.id == 0) { // skip logic if (query.pagenumber > 1) { collectionQuery = collectionQuery.Skip(query.pagesize * (query.pagenumber - 1)); } // take logic if (!query.loadall) { collectionQuery = collectionQuery.Take(query.pagesize); } } return(collectionQuery); }
private static string GenerateKey(string key, AdEntity entity) { return(key + entity.type); }
private static async Task <int> CountRecords(ApplicationDbContext context, AdEntity entity) { return(await context.JGN_Ads.Where(returnWhereClause(entity)).CountAsync()); }
public async Task <ActionResult <AdEntity> > PostAdEntity(AdEntity adEntity) { var adEntityCreated = await _adService.PostAd(adEntity, this.HttpContext); return(CreatedAtAction("GetAdEntity", new { id = adEntity.Id }, adEntity)); }
public Ad(AdEntity entity, Func <string, string> imagerPath) { Id = entity.Id; Name = entity.Name; Path = imagerPath(entity.Path); }