Exemplo n.º 1
0
 public ActionResult Index()
 {
     return(View(new HomeStatsViewModel()
     {
         Participants = ParticipantManager.Count(CurrentContextType),
         Entries = EntryManager.Count(CurrentContextType),
         Ingredients = IngredientManager.Count(CurrentContextType),
         ExistingBarCombinations = ExistingBarCombinationManager.Count(CurrentContextType),
         NewProCampaignTransactions = ProCampaignTransactionManager.CountByStatus(ProCampaignTransactionStatusKeys.NEW, CurrentContextType),
         SentProCampaignTransactions = ProCampaignTransactionManager.CountByStatus(ProCampaignTransactionStatusKeys.SENT, CurrentContextType)
     }));
 }
Exemplo n.º 2
0
        private void InsertExistingBarCombinations()
        {
            if (ExistingBarCombinationManager.Get(CurrentContextType).Count() != 0)
            {
                throw new Exception("Combinations already inserted !");
            }

            string filename     = System.Configuration.ConfigurationManager.AppSettings["DelistedList"];
            string fullFilename = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/" + filename);

            try
            {
                string[] fileLines = System.IO.File.ReadAllLines(fullFilename);
                foreach (string s in fileLines)
                {
                    string[] ingredientData            = s.Split(new char[] { ',' });
                    ExistingBarCombination existingBar = new ExistingBarCombination();
                    existingBar.BarName     = ingredientData[0];
                    existingBar.Ingredient1 = IngredientManager.GetIngredient(ingredientData[1], CurrentContextType);
                    existingBar.CreatedOn   = DateTime.UtcNow;
                    if (!string.IsNullOrEmpty(ingredientData[2]))
                    {
                        existingBar.Ingredient2 = IngredientManager.GetIngredient(ingredientData[2], CurrentContextType);
                    }

                    if (!string.IsNullOrEmpty(ingredientData[3]))
                    {
                        existingBar.Ingredient3 = IngredientManager.GetIngredient(ingredientData[3], CurrentContextType);
                    }
                    ExistingBarCombinationManager.Insert(existingBar, CurrentContextType);
                }
            }
            catch (System.IO.FileNotFoundException ioExcp)
            {
                throw new Exception("Ingredients file could not be loaded.", ioExcp);
            }
            catch (System.IO.IOException ioGeneralExcp)
            {
                throw new System.IO.IOException("An IO Exception occurred while reading the ingredients file.", ioGeneralExcp);
            }
            catch (Exception excp)
            {
                throw new Exception("A general exception occurred while reading the ingredients file.", excp);
            }
        }
Exemplo n.º 3
0
        public ResultDTO Process()
        {
            string colour = String.Empty;

            IList <Ingredient> ingredients     = GenerateIngredientsList(Ingredient1, Ingredient2, Ingredient3);
            IList <Guid>       ingredientGuids = GenerateIngredientGuidsList(Ingredient1, Ingredient2, Ingredient3);

            // Colour is red if all 3 ingredients are red
            IList <string> colours = ingredients.Select(i => i.Colour).Distinct().ToList();

            if (ingredients.Count == 3 && colours.Count == 1 && Ingredient1.Colour == ColorKeys.RED)
            {
                colour = ColorKeys.RED;
            }

            // Colour is red if an entry corresponds from ExistingBarCombination
            IList <ExistingBarCombination> existingBarCombinations = ExistingBarCombinationManager.Get();

            foreach (ExistingBarCombination existingBarCombination in existingBarCombinations)
            {
                IList <Guid> ingredientGuidsFromExistingBarCombination = GenerateIngredientGuidsList(existingBarCombination.Ingredient1, existingBarCombination.Ingredient2, existingBarCombination.Ingredient3);
                if (ingredientGuids.Count() == ingredientGuidsFromExistingBarCombination.Count())
                {
                    if (ingredientGuids.All(ingredientGuidsFromExistingBarCombination.Contains))
                    {
                        colour = ColorKeys.RED;
                        break;
                    }
                }
            }

            Result.HttpStatusCode = HttpStatusCode.OK;
            Result.Meta           = new
            {
                Colour = colour
            };

            return(Result);
        }
Exemplo n.º 4
0
        public JsonResult List(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                var dbRecords = ExistingBarCombinationManager.Get(jtStartIndex, jtPageSize, CurrentContextType).ToList();
                var records   = new List <object>();
                foreach (var dbRecord in dbRecords)
                {
                    records.Add(new {
                        BarName     = dbRecord.BarName,
                        Ingredient1 = dbRecord.Ingredient1,
                        Ingredient2 = dbRecord.Ingredient2,
                        Ingredient3 = dbRecord.Ingredient3,
                        CreatedOn   = String.Format(
                            "{0:yyyy-MM-dd hh:mm}",
                            dbRecord.CreatedOn
                            )
                    });
                }

                return(Json(new JTableResult
                {
                    Result = "OK",
                    Records = records,
                    TotalRecordCount = ExistingBarCombinationManager.Count(CurrentContextType)
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JTableResult
                {
                    Result = "ERROR",
                    Message = ex.Message
                }));
            }
        }