Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CounterContext db    = new CounterContext();
            var            found = db.Visitors.FirstOrDefault();

            if (found == null)
            {
                db.Visitors.Add(new Visitor()
                {
                    Count = 1
                });
                db.SaveChanges();
                found = new Visitor()
                {
                    Count = 1
                };
            }
            else
            {
                found.Count++;
                db.SaveChanges();
            }


            Bitmap generatedImage = new Bitmap(110, 110);

            using (generatedImage)
            {
                Graphics gr = Graphics.FromImage(generatedImage);
                using (gr)
                {
                    gr.FillRectangle(Brushes.MediumSeaGreen, 0, 0, 200, 200);

                    gr.DrawString(found.Count.ToString(),
                                  new Font("Segoe UI", 25),
                                  new SolidBrush(Color.BlanchedAlmond),
                                  new PointF(35, 30));


                    // Set response header and write the image into response stream
                    Response.ContentType = "image/jpeg";

                    //Response.AppendHeader("Content-Disposition",
                    //    "attachment; filename=\"Financial-Report-April-2013.gif\"");

                    generatedImage.Save(Response.OutputStream, ImageFormat.Jpeg);
                }
            }
        }
Example #2
0
 public void AddCockpitEnvironmentDetails(IList <Environment> environmentList)
 {
     // You could've gotten it like this instead of passing it in...
     // IEnumerable<Environments> environmentList = db.Environments;
     foreach (Environment entity in environmentList)
     {
         db.Environments.Add(entity);
     }
     db.SaveChanges();
 }
Example #3
0
        protected void Page_PreInit(object sender, EventArgs e)
        {
            this.context = new CounterContext();

            context.Logs.Add(new Log()
            {
                IpAddres     = this.GetIpAddress(),
                VisitingDate = DateTime.Now
            });

            context.SaveChanges();
        }
Example #4
0
        private Counter adjustCount()
        {
            Counter counter = new Counter();

            if (HttpContext.Items[_itemName].ToString().Equals("Y"))
            {
                counter.count = _context.Counters.Count() + 1;
                _context.Add(counter);
                _context.SaveChanges();
            }
            counter = _context.Counters.LastOrDefault();
            return(counter);
        }
Example #5
0
        public IActionResult OnPost()
        {
            Guid counterKey;

            if (!Request.Cookies.TryGetValue(MewTwoCookieName, out string key) || !Guid.TryParse(key, out counterKey))
            {
                return(RedirectToPage());
            }

            var counter = new Counter
            {
                Date       = DateTime.UtcNow,
                CounterKey = counterKey
            };

            db.Counters.Add(counter);
            db.SaveChanges();

            return(RedirectToPage());
        }
        public int UpdateCounter()
        {
            int defaultCounter = 1;

            try
            {
                using (var context = new CounterContext())
                {
                    if (context.Counters.Count() == 0)
                    {
                        // Add new counter if no exist
                        context.Counters.Add(new Counter {
                            ClickCount = defaultCounter
                        });
                    }
                    else
                    {
                        //update counter if exist
                        var counter = context.Counters.First();
                        if (counter.ClickCount >= 10)
                        {
                            return(counter.ClickCount);
                        }
                        counter.ClickCount = counter.ClickCount + defaultCounter;
                    }
                    context.SaveChanges();

                    // return number of click
                    return(context.Counters.First().ClickCount);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public void Save()
 {
     _repoContext.SaveChanges();
 }