public ActionResult Detail(int id)
 {
     using (BillsListEntities entities = new BillsListEntities())
     {
         return(View(entities.Items.FirstOrDefault(i => i.Id == id)));
     }
 }
        public async Task <ActionResult> Create(Item item)
        {
            //convert the image to a base64 string
            if (Request.Files.Count > 0)
            {
                byte[] bytes = new byte[Request.Files[0].InputStream.Length];
                Request.Files[0].InputStream.Read(bytes, 0, bytes.Length);
                item.Image = "data:image/jpg;base64, " + Convert.ToBase64String(bytes);
            }

            //set additional properties
            item.Owner    = System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username").Value.ToLower();
            item.PostDate = DateTime.Now;

            //save the item to the database
            using (BillsListEntities entities = new BillsListEntities())
            {
                entities.Items.Add(item);
                var id = entities.SaveChanges();

                //loop through subscriptions and call webhooks for each
                foreach (var sub in entities.Subscriptions)
                {
                    await callWebhook(sub.WebHookUri, item);
                }

                return(RedirectToAction("Detail", new { id = item.Id }));
            }
        }
 public ActionResult Index()
 {
     using (BillsListEntities entities = new BillsListEntities())
     {
         return(View(entities.Items.OrderByDescending(i => i.PostDate).ToList()));
     }
 }
Exemple #4
0
        // GET: Callback
        public ActionResult Index()
        {
            var error = Request["error"];
            var state = Request["state"];

            if (!String.IsNullOrEmpty(error))
            {
                return(RedirectToAction("Error", "Home", null));
            }
            else
            {
                var          group   = Request["group_name"];
                var          webhook = Request["webhook_url"];
                Subscription sub     = new Subscription();
                sub.GroupName  = group;
                sub.WebHookUri = webhook;

                //save the subscription
                using (BillsListEntities entities = new BillsListEntities())
                {
                    entities.Subscriptions.Add(sub);
                    entities.SaveChanges();
                    return(Redirect(state));
                }
            }
        }
 public ActionResult Category(string c)
 {
     ViewData.Add("category", c);
     using (BillsListEntities entities = new BillsListEntities())
     {
         return(View(entities.Items.Where(i => i.Category == c).OrderByDescending(i => i.PostDate).ToList()));
     }
 }
        public ActionResult My()
        {
            var user = System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username").Value.ToLower();

            using (BillsListEntities entities = new BillsListEntities())
            {
                return(View(entities.Items.Where(i => i.Owner == user).OrderByDescending(i => i.PostDate).ToList()));
            }
        }
        public ActionResult Index(Subscription sub)
        {
            //save the subscription
            using (BillsListEntities entities = new BillsListEntities())
            {
                entities.Subscriptions.Add(sub);
                entities.SaveChanges();

                //redirect back to the original location the user was at
                return(Redirect(Request["state"]));
            }
        }
        public ActionResult Delete(int id)
        {
            var user = System.Security.Claims.ClaimsPrincipal.Current.FindFirst("preferred_username").Value.ToLower();

            using (BillsListEntities entities = new BillsListEntities())
            {
                var item = entities.Items.FirstOrDefault(i => i.Id == id && i.Owner == user);
                if (item != null)
                {
                    entities.Items.Remove(item);
                    entities.SaveChanges();
                }
                return(RedirectToAction("My"));
            }
        }