コード例 #1
0
 public ActionResult ApproveIdea(int id)
 {
     using (var context = new ENSE496Entities())
     {
         Idea       idea      = context.Ideas.Where(x => x.Id == id).FirstOrDefault();
         Status_log statusLog = new Status_log();
         statusLog.Idea_id = id;
         return(View(statusLog));
     }
 }
コード例 #2
0
 public ActionResult ApproveIdea(Status_log statusLogParam)
 {
     using (var context = new ENSE496Entities())
     {
         Idea       idea      = context.Ideas.Where(x => x.Id == statusLogParam.Idea_id).FirstOrDefault();
         Status_log statusLog = new Status_log();
         statusLog.Current_status  = "Approved";
         statusLog.Previous_status = idea.Status;
         statusLog.Idea_id         = statusLogParam.Idea_id;
         statusLog.User_id         = Convert.ToInt32(Session["UserID"]);
         statusLog.Description     = statusLogParam.Description;
         context.Ideas.Where(x => x.Id == statusLogParam.Idea_id).FirstOrDefault().Status = "Approved";
         context.Status_log.Add(statusLog);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #3
0
        public ActionResult PlanIdea(Status_log statusLogParam)
        {
            using (var context = new ENSE496Entities())
            {
                if (ModelState.IsValid)
                {
                    Idea       idea      = context.Ideas.Where(x => x.Id == statusLogParam.Idea_id).FirstOrDefault();
                    Status_log statusLog = new Status_log();
                    statusLog.Current_status  = "Planned";
                    statusLog.Previous_status = idea.Status;
                    statusLog.Idea_id         = statusLogParam.Idea_id;
                    statusLog.User_id         = Convert.ToInt32(Session["UserID"]);
                    statusLog.Description     = statusLogParam.Description;
                    context.Ideas.Where(x => x.Id == statusLogParam.Idea_id).FirstOrDefault().Status = "Planned";
                    context.Status_log.Add(statusLog);

                    if (idea.User_id != statusLog.User_id) //checks to see if status change was made by someone other than who submitted the idea
                    {
                        Notification notification = new Notification();
                        notification.Recipient_id = idea.User_id;
                        notification.Message      = Session["Username"].ToString() + " has planned your idea. (Idea #" + statusLog.Idea_id.ToString() + ")";
                        notification.Active       = true;
                        context.Notifications.Add(notification);
                    }
                    if (context.Subscriptions.Where(x => x.Idea_id == statusLog.Idea_id).Any())
                    {
                        var subs = context.Subscriptions.Where(x => x.Idea_id == statusLog.Idea_id).ToList();
                        foreach (Subscription sub in subs)
                        {
                            Notification notification = new Notification();
                            notification.Recipient_id = sub.User_id;
                            notification.Message      = Session["Username"].ToString() + " has planned an idea you are subscribed to. (Idea #" + statusLog.Idea_id.ToString() + ")";
                            notification.Active       = true;
                            context.Notifications.Add(notification);
                        }
                    }
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View());
            }
        }