コード例 #1
0
ファイル: IngredientManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: ParticipantManager.cs プロジェクト: cbugs/cadpl
        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
ファイル: DataPurgeModule.cs プロジェクト: cbugs/cadpl
        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
ファイル: IngredientManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: IngredientManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: IngredientManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: ParticipantManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: ParticipantManager.cs プロジェクト: cbugs/cadpl
 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
ファイル: ContextController.cs プロジェクト: cbugs/cadpl
        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();
            }
        }