예제 #1
0
 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());
     }
 }
예제 #2
0
        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;
            }
        }
예제 #3
0
 public static int Count(ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         return(context.Entries.Count());
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 public static int Count(ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         return(context.ExistingBarCombinations.Count());
     }
 }
예제 #6
0
 public static int Count(ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         return(context.ProCampaignStatuses.Count());
     }
 }
예제 #7
0
 public static void Insert(Entities.Ingredient entity, ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         context.Ingredients.Add(entity);
         context.SaveChanges();
     }
 }
예제 #8
0
 public static void Update(ProCampaignStatus entity, ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #9
0
 public static void Insert(ProCampaignStatus entity, ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         context.ProCampaignStatuses.Add(entity);
         context.SaveChanges();
     }
 }
예제 #10
0
 public static int CountByStatus(string status, ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         return(context.ProCampaignTransactions
                .Count(e => e.Status == status));
     }
 }
예제 #11
0
 public static IList <ProCampaignStatus> Get(ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         return(context.ProCampaignStatuses
                .OrderByDescending(e => e.CreatedOn)
                .ToList());
     }
 }
예제 #12
0
 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());
     }
 }
예제 #13
0
 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());
     }
 }
예제 #14
0
 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());
     }
 }
예제 #15
0
 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());
     }
 }
예제 #16
0
 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());
     }
 }
예제 #17
0
 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());
     }
 }
예제 #18
0
 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());
     }
 }
예제 #19
0
        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
                        )
                }));
            }
        }
예제 #20
0
        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();
            }
        }