public static Entities.Ingredient GetIngredientFromName(string name, ContextType contextType = ContextType.Default) { using (var ctx = ContextSwitcher.CreateContext(contextType)) { return((from ingredientToSearch in ctx.Ingredients where ingredientToSearch.Name.ToLower() == name.ToLower() select ingredientToSearch).FirstOrDefault()); } }
public static void InsertFromExistingParticipant(Participant participant, ParticipantDataCache participantDataCache, Entry entry, ContextType contextType = ContextType.Default) { try { using (var context = ContextSwitcher.CreateContext(contextType)) { participantDataCache.ParticipantId = participant.Id; context.ParticipantDataCaches.Add(participantDataCache); if (entry.Ingredient1 != null) { context.Ingredients.Attach(entry.Ingredient1); } if (entry.Ingredient2 != null) { context.Ingredients.Attach(entry.Ingredient2); } if (entry.Ingredient3 != null) { context.Ingredients.Attach(entry.Ingredient3); } entry.ParticipantId = participant.Id; entry.ParticipantDataCacheId = participantDataCache.Id; context.Entries.Add(entry); context.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public static int Count(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.Entries.Count()); } }
public ResultDTO Process() { var dateTimeFromNow = DateTime.UtcNow.AddDays(-DaysPeriodFromNow); using (var context = ContextSwitcher.CreateContext()) { IList <ParticipantDataCache> participantDataCaches = context.ParticipantDataCaches .Where( e => e.Email.Contains("@") && e.CreatedOn < dateTimeFromNow ).ToList(); foreach (ParticipantDataCache participantDataCache in participantDataCaches) { participantDataCache.Email = StringUtils.HashSHA256(participantDataCache.Email.ToLower()); participantDataCache.FirstName = StringUtils.HashSHA256(participantDataCache.FirstName.ToLower()); participantDataCache.LastName = StringUtils.HashSHA256(participantDataCache.LastName.ToLower()); participantDataCache.MobileNumber = StringUtils.HashSHA256(participantDataCache.MobileNumber.ToLower()); participantDataCache.City = StringUtils.HashSHA256(participantDataCache.City.ToLower()); participantDataCache.UpdatedOn = DateTime.UtcNow; context.Entry(participantDataCache).State = EntityState.Modified; context.SaveChanges(); } } Result.HttpStatusCode = HttpStatusCode.OK; return(Result); }
public static int Count(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ExistingBarCombinations.Count()); } }
public static int Count(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ProCampaignStatuses.Count()); } }
public static void Insert(Entities.Ingredient entity, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { context.Ingredients.Add(entity); context.SaveChanges(); } }
public static void Update(ProCampaignStatus entity, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } }
public static void Insert(ProCampaignStatus entity, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { context.ProCampaignStatuses.Add(entity); context.SaveChanges(); } }
public static int CountByStatus(string status, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ProCampaignTransactions .Count(e => e.Status == status)); } }
public static IList <ProCampaignStatus> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ProCampaignStatuses .OrderByDescending(e => e.CreatedOn) .ToList()); } }
public static List <Entities.Ingredient> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(( from ingredient in context.Ingredients orderby ingredient.CreatedOn descending select ingredient ).ToList()); } }
public static IList <ExistingBarCombination> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ExistingBarCombinations .Include(nameof(ExistingBarCombination.Ingredient1)) .Include(nameof(ExistingBarCombination.Ingredient2)) .Include(nameof(ExistingBarCombination.Ingredient3)) .OrderByDescending(e => e.CreatedOn) .ToList()); } }
public static IList <ProCampaignTransaction> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.ProCampaignTransactions .Include(nameof(ProCampaignTransaction.ProCampaignStatus)) .Include(e => e.ProCampaignStatus.Entry) .Include(e => e.ProCampaignStatus.Entry.Participant) .OrderByDescending(e => e.CreatedOn) .ToList()); } }
public static Entities.Ingredient GetIngredient(Guid id, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(( from ingredientToSearch in context.Ingredients where ingredientToSearch.Id == id select ingredientToSearch ).FirstOrDefault()); } }
public static IList <Participant> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.Participants .Include(nameof(InventorContext.ParticipantDataCaches)) .Include(nameof(InventorContext.Entries)) .Include(p => p.Entries.Select(e => e.Ingredient1)) .Include(p => p.Entries.Select(e => e.Ingredient2)) .Include(p => p.Entries.Select(e => e.Ingredient3)) .OrderByDescending(e => e.CreatedOn) .ToList()); } }
public static IList <Entry> Get(ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.Entries .Include(nameof(Entry.Ingredient1)) .Include(nameof(Entry.Ingredient2)) .Include(nameof(Entry.Ingredient3)) .Include(nameof(Entry.Participant)) .Include(nameof(Entry.ParticipantDataCache)) .OrderByDescending(e => e.CreatedOn) .ToList()); } }
public static Participant GetByEmailHash(string emailHash, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { return(context.Participants .Include(nameof(InventorContext.ParticipantDataCaches)) .Include(nameof(InventorContext.Entries)) .Include(p => p.Entries.Select(e => e.Ingredient1)) .Include(p => p.Entries.Select(e => e.Ingredient2)) .Include(p => p.Entries.Select(e => e.Ingredient3)) .Where(p => p.EmailHash == emailHash) .OrderByDescending(e => e.CreatedOn) .FirstOrDefault()); } }
public ActionResult ChangeContext(string newContext) { if (Session["CurrentContext"] == null) { Session["CurrentContext"] = ContextType.Default; } ContextType selectedEnvironment = (ContextType)Enum.Parse(typeof(ContextType), Session["CurrentContext"].ToString(), true); if (Enum.TryParse <ContextType>(newContext, out selectedEnvironment)) { using (InventorContext context = ContextSwitcher.CreateContext(selectedEnvironment)) { if (!context.Database.Exists()) { return(Json(new { Result = "FAILED", Message = String.Format( "Database not found for context \"{0}\" !", newContext ) })); } else { Session["CurrentContext"] = newContext; } } return(Json(new { Result = "OK" })); } else { return(Json(new { Result = "FAILED", Message = String.Format( "Context \"{0}\" not found in contexts list !", newContext ) })); } }
public static void Insert(ExistingBarCombination existingBarCombination, ContextType contextType = ContextType.Default) { using (var context = ContextSwitcher.CreateContext(contextType)) { if (existingBarCombination.Ingredient1 != null) { context.Ingredients.Attach(existingBarCombination.Ingredient1); } if (existingBarCombination.Ingredient2 != null) { context.Ingredients.Attach(existingBarCombination.Ingredient2); } if (existingBarCombination.Ingredient3 != null) { context.Ingredients.Attach(existingBarCombination.Ingredient3); } context.ExistingBarCombinations.Add(existingBarCombination); context.SaveChanges(); } }