Example #1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            fact fact = await db.facts.FindAsync(id);

            db.facts.Remove(fact);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,description")] fact fact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(fact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(fact));
        }
Example #3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,description")] fact fact)
        {
            if (ModelState.IsValid)
            {
                db.facts.Add(fact);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(fact));
        }
Example #4
0
        // GET: facts/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            fact fact = await db.facts.FindAsync(id);

            if (fact == null)
            {
                return(HttpNotFound());
            }
            return(View(fact));
        }
Example #5
0
        // GET: facts/Random
        ///<summary>
        ///Get random fact.
        ///</summary>
        ///<return>
        ///Return random fact.
        ///</return>
        public ActionResult Random()
        {
            // Fact identify.
            int id;

            Random rnd = new Random();

            // Get Random number. Range values between 1 to max row number to facts.
            id = rnd.Next(1, db.facts.Count());

            // Not use search async because need show partial view in other view. (Index.cshtml)
            fact fact = db.facts.Find(id);

            if (fact == null)
            {
                return(HttpNotFound());
            }

            // Necesary for no show footer page.
            return(PartialView(fact));
        }
Example #6
0
        public static long Part2(string input)
        {
            List <customRange> ranges   = new List <customRange>();
            string             step     = "range";
            List <int>         myTicket = new List <int>();
            List <fact>        answers  = new List <fact>();

            foreach (string line in input.Split(Environment.NewLine))
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                else if (line == "your ticket:")
                {
                    step = "mine";
                }
                else if (line == "nearby tickets:")
                {
                    step = "nearby";
                }
                else if (step == "mine")
                {
                    myTicket = line.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                }
                else if (step == "range" && line != "")
                {
                    Regex range = new Regex(@"(.*): (\d+)-(\d+) or (\d+)-(\d+)");
                    Match m     = range.Match(line);
                    (int, int)fRange = (Convert.ToInt32(m.Groups[2].Value), Convert.ToInt32(m.Groups[3].Value));
                    (int, int)sRange = (Convert.ToInt32(m.Groups[4].Value), Convert.ToInt32(m.Groups[5].Value));
                    customRange r = new customRange(fRange, sRange, m.Groups[1].Value);
                    ranges.Add(r);
                }
                else if (step == "nearby")
                {
                    int[] values  = line.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
                    bool  isValid = true;
                    for (int i = 0; i < values.Length; i++)
                    {
                        fact answer = answers.FirstOrDefault(x => x.index == i);

                        if (answer == null || answer.possibles.Count != 1)
                        {
                            List <string> temp = new List <string>();
                            foreach (customRange range in ranges)
                            {
                                if (range.Include(values[i]))
                                {
                                    temp.Add(range.name);
                                }
                            }
                            if (answer == null)
                            {
                                answers.Add(new fact(i, temp));
                            }
                            else if (temp.Count > 0)
                            {
                                answer.Intersect(temp);
                            }
                            else
                            {
                                isValid = false;
                                break;
                            }
                        }
                    }
                    if (isValid)
                    {
                        answers.ForEach(x => x.Perform());
                    }
                }
            }
            while (answers.Exists(x => x.possibles.Count > 1))
            {
                List <fact> solved = answers.Where(x => x.possibles.Count == 1).ToList();
                answers.ForEach(x => x.Remove(solved.SelectMany(y => y.possibles).ToList()));
            }
            long res = 1;

            foreach (int index in answers.Where(x => x.Solution.StartsWith("departure")).Select(x => x.index))
            {
                res *= myTicket[index];
            }
            return(res);
        }
Example #7
0
        static void Main(string[] args)
        {
            int j;

            Console.WriteLine("ecrire le no total  des Articles");

            bool res0 = int.TryParse(Console.ReadLine(), out j);

            while (!res0)
            {
                Console.WriteLine("ecrire le no total  des Articles correct SVP");

                res0 = int.TryParse(Console.ReadLine(), out j);
            }

            if (j > 0)
            {
                for (int i = 0; i < j; i++)
                {
                    fact F = new fact();
                    Console.WriteLine("ecrire le no d,Article  ");

                    bool res = int.TryParse(Console.ReadLine(), out F.no);
                    while (!res)
                    {
                        Console.WriteLine("ecrire le no d,Article autre fois ");
                        res = int.TryParse(Console.ReadLine(), out F.no);
                    }

                    Console.WriteLine("ecrire le nom d article ");
                    F.nom = Console.ReadLine();

                    Console.WriteLine("ecrire le NoTotal d article ");

                    bool res2 = int.TryParse(Console.ReadLine(), out F.NoTotal);

                    while (!res2)
                    {
                        Console.WriteLine("ecrire le NoTotal d article  correst svp ");
                        res2 = int.TryParse(Console.ReadLine(), out F.NoTotal);
                    }

                    Console.WriteLine("ecrire le prix Svp");
                    bool res3 = double.TryParse(Console.ReadLine(), out F.prix);

                    while (!res3)
                    {
                        Console.WriteLine("ecrire le prix Svp correct  svp ");
                        res3 = double.TryParse(Console.ReadLine(), out F.prix);
                    }


                    Utils.remplier(F);
                    Utils.afficher();
                }

                Console.WriteLine("*****************************************************");
                Utils.afficherTotal();
            }
            else
            {
                Console.WriteLine(" le  no  d article doit etre positive plus de 0 ");
            }
        }