public ActionResult Create(idea idea)
 {
     if (ModelState.IsValid)
     {
         simdata.ideas.Add(idea);
         simdata.SaveChanges();
         return(View("Index"));
     }
     else
     {
         ViewBag.error_message = "woops, error occured";
         return(View());
     }
 }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            idea ideas = simdata.ideas.Find(id);

            if (ideas == null)
            {
                return(HttpNotFound());
            }
            return(View(ideas));
        }
Example #3
0
        static void Main(string[] args)
        {
            idea     i = new idea();
            category k = new category();

            //IdeaServices ideas = new IdeaServices();
            //UserServices users = new UserServices();
            CategoryServices categeorys = new CategoryServices();

            categeorys.Add(k);
            categeorys.Commit();



            //i.category = categeorys.GetById(2);
            //i.user = users.GetById(4);

            //ideas.Add(i);
            // ideas.Commit();

            Console.WriteLine("Appuyez sur une touche pour continuer...");
            Console.ReadKey(true);
        }
Example #4
0
        private List <display_idea> getAllDisplayIdeas()
        {
            List <display_idea> display_Ideas = new List <display_idea>();
            List <idea>         ideas         = dbData.ideas.Where(item => item.academic_year_id == current_year.academic_year_id).Where(item => item.isEnabled == 1).ToList();
            /*List<idea> ideas = dbData.ideas.Where(item => item.isEnabled == 1).ToList();*/

            user loggedIn = (user)Session["loggedIn"];

            for (int i = 0; i < ideas.Count; i++)
            {
                idea idea        = ideas[i];
                int  user_id     = Convert.ToInt32(idea.user_id);
                int  isAnonymous = Convert.ToInt32(idea.isAnonymous);
                int  status      = Convert.ToInt32(idea.status);

                user         user         = dbData.users.Where(u => u.user_id == user_id).First();
                display_idea display_Idea = new display_idea();

                display_Idea.idea = idea;
                display_Idea.user = user;
                if (user_id == loggedIn.user_id && isAnonymous == 1)
                {
                    //true
                    user u = new user();
                    u.user_id         = user.user_id;
                    u.user_name       = idea.user.user_name + " (Anonymous)";
                    display_Idea.user = u;
                }
                else if (user_id != loggedIn.user_id && isAnonymous == 1)
                {
                    //true
                    user u = new user();
                    u.user_id         = user.user_id;
                    u.user_name       = "Anonymous";
                    display_Idea.user = u;
                }

                if (status == 1)
                {
                    display_Ideas.Add(display_Idea);
                }


                //display time
                display_Idea.timepast = TimePast(idea);



                //for New comments purposes
                DateTime       lastLogin   = (DateTime)Session["lastLogin"];
                List <comment> newComments = dbData.comments.Where(c => c.idea_id == idea.idea_id).Where(c => c.created_at > lastLogin).Where(c => c.user.role_id == 5).Where(c => c.user_id != loggedIn.user_id).ToList();

                List <idea> viewed_ideas = (List <idea>)Session["viewedIdeas"];

                var count = 0;
                foreach (idea item in viewed_ideas)
                {
                    if (item.idea_id == idea.idea_id)
                    {
                        count++;
                    }
                }


                if (newComments.Count != 0 && count == 0 && loggedIn.role_id == 5 && loggedIn.user_id == idea.user_id)
                {
                    display_Idea.new_comments = true;
                }
            }
            display_Ideas.OrderByDescending(item => item.idea.created_at);
            return(display_Ideas);
        }
Example #5
0
        private String TimePast(idea idea)
        {
            String   str   = null;
            DateTime date1 = (DateTime)idea.created_at;
            DateTime date2 = DateTime.Now;

            DateTime fromDate = new DateTime();
            DateTime toDate   = new DateTime();

            int[] monthDay = new int[12] {
                31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
            };
            int    year;
            int    month;
            int    day;
            int    hour;
            int    minute;
            String now = "Just now";

            if (date2 > date1)
            {
                fromDate = date1;
                toDate   = date2;
            }
            else
            {
                fromDate = date2;
                toDate   = date1;
            }


            TimeSpan span = (toDate - fromDate);

            minute = span.Minutes;
            hour   = span.Hours;

            //Day calculation
            int increment = 0;

            if (fromDate.Day > toDate.Day)
            {
                increment = monthDay[fromDate.Month - 1];
            }

            if (increment == -1)
            {
                if (DateTime.IsLeapYear(fromDate.Year))
                {
                    increment = 29;
                }
                else
                {
                    increment = 28;
                }
            }

            if (increment != 0)
            {
                day       = (toDate.Day + increment) - fromDate.Day;
                increment = 1;
            }
            else
            {
                day = toDate.Day - fromDate.Day;
            }

            //Month
            if ((fromDate.Month + increment) > toDate.Month)
            {
                month     = (toDate.Month + 12) - (fromDate.Month + increment);
                increment = 1;
            }
            else
            {
                month     = (toDate.Month) - (fromDate.Month + increment);
                increment = 0;
            }

            //Year
            year = toDate.Year - (fromDate.Year + increment);



            if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0)
            {
                str = now;
            }
            else if (year == 0 && month == 0 && day == 0 && hour == 0 && minute > 0)
            {
                if (minute == 1)
                {
                    str = minute + " minute ago";
                }
                else
                {
                    str = minute + " minutes ago";
                }
            }
            else if (year == 0 && month == 0 && day == 0 && hour > 0)
            {
                if (hour == 1)
                {
                    str = hour + " hour ago";
                }
                else
                {
                    str = hour + " hours ago";
                }
            }
            else if (year == 0 && month == 0 && day > 0)
            {
                if (day == 1)
                {
                    str = day + " day ago";
                }
                else
                {
                    str = day + " days ago";
                }
            }
            else if (year == 0 && month > 0)
            {
                if (month == 1)
                {
                    str = month + " month ago";
                }
                else
                {
                    str = month + " months ago";
                }
            }
            else if (year > 0)
            {
                if (year == 1)
                {
                    str = year + " year ago";
                }
                else
                {
                    str = year + " years ago";
                }
            }



            return(str);
        }
Example #6
0
        public ActionResult Details(int idea_id)
        {
            //check logged in?
            if (Session["loggedIn"] == null)
            {
                return(Redirect("~/Home/LoginPage"));
            }

            user loggedIn = (user)Session["loggedIn"];

            idea           idea     = dbData.ideas.Where(i => i.idea_id == idea_id).First();
            int            uid      = Convert.ToInt32(idea.user_id);
            List <comment> comments = comments = dbData.comments.Where(c => c.idea_id == idea_id).OrderByDescending(c => c.created_at).ToList();
            List <comment> temp     = new List <comment>();


            List <idea> viewed_ideas = (List <idea>)Session["viewedIdeas"];

            //Views not added for own ideas
            if (idea.user.user_id != loggedIn.user_id)
            {
                idea.viewed_count += 1;
                dbData.SaveChanges();
            }
            else
            {
                var count = 0;
                foreach (idea i in viewed_ideas)
                {
                    if (i.idea_id == idea.idea_id)
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    viewed_ideas.Add(idea);
                }
            }



            //student can't see staff comments
            if (loggedIn.role_id == 5)
            {
                foreach (comment c in comments)
                {
                    int  user_id = Convert.ToInt32(c.user_id);
                    user user    = dbData.users.Where(u => u.user_id == user_id).First();
                    if (user.role_id != 5)
                    {
                        temp.Add(c);
                    }
                }
                foreach (comment c in temp)
                {
                    comments.Remove(c);
                }
            }
            //get all comments
            List <user> comment_users = new List <user>();

            for (int i = 0; i < comments.Count; i++)
            {
                comment comment = comments[i];

                int user_id     = Convert.ToInt32(comment.user_id);
                int isAnonymous = Convert.ToInt32(comment.isAnonymous);

                user user = dbData.users.Where(u => u.user_id == user_id).First();
                comment_users.Add(user);
                if (user_id == loggedIn.user_id && isAnonymous == 1)
                {
                    //true
                    user u = new user();
                    u.user_id        = user.user_id;
                    u.user_name      = user.user_name + " (Anonymous)";
                    comment_users[i] = u;
                }
                else if (user_id != loggedIn.user_id && isAnonymous == 1)
                {
                    //true
                    user u = new user();
                    u.user_id        = user.user_id;
                    u.user_name      = "Anonymous";
                    comment_users[i] = u;
                }
                else if (isAnonymous == 0)
                {
                    //true
                    user u = new user();
                    u.user_id        = user.user_id;
                    u.user_name      = user.user_name;
                    comment_users[i] = u;
                }
            }
            //get attachment
            List <document> documents = dbData.documents.Where(d => d.idea_id == idea_id).ToList();

            ViewBag.documents = documents;

            ViewBag.currentUser = loggedIn;

            //get rate
            IQueryable <rate> rates = dbData.rates.Where(r => r.idea_id == idea_id).Where(r => r.user_id == loggedIn.user_id);

            if (rates.Any())
            {
                ViewBag.rate = rates.First().rate_point;
            }

            //show difference between staff and student comments
            int studentComments = dbData.comments.Where(c => c.idea_id == idea_id).Where(c => c.user.role_id == 5).Count();

            ViewBag.commentCountStudent = studentComments;

            int staffComments = dbData.comments.Where(c => c.idea_id == idea_id).Count();

            ViewBag.commentCountStaff = staffComments;

            ViewBag.Idea = idea;
            if (idea.isAnonymous == 0)
            {
                ViewBag.Idea_user = dbData.users.Where(u => u.user_id == uid).First();
            }

            ViewBag.timepast = TimePast(idea);

            dynamic mymodel = new ExpandoObject();

            mymodel.Comments      = comments;
            mymodel.Comment_users = comment_users;

            if (current_year.deadline_comments < DateTime.Now)
            {
                ViewBag.error = "1";
            }
            return(View(mymodel));
        }
Example #7
0
        public ActionResult Create(idea idea, HttpPostedFileBase[] files)
        {
            //check logged in?
            if (Session["loggedIn"] == null)
            {
                return(Redirect("~/Home/LoginPage"));
            }
            if (!ModelState.IsValid)
            {
                List <category> categories = dbData.categories.ToList();
                SelectList      listItems  = new SelectList(categories, "category_id", "category_name");
                Session["cateCbb"] = listItems;
                return(View(idea));
            }
            // 0 = false; 1 = true
            idea.category_id = Convert.ToInt32(Request.Form["categoryID"].ToString());

            idea.isEnabled        = 1;
            idea.status           = 0;
            idea.viewed_count     = 0;
            idea.academic_year_id = current_year.academic_year_id;
            idea.created_at       = DateTime.Now;
            idea.user_id          = ((user)Session["loggedIn"]).user_id;
            //check anonymous
            if (Request.Form["isAnonymous"] != null)
            {
                idea.isAnonymous = 1;
            }
            else
            {
                idea.isAnonymous = 0;
            }

            dbData.ideas.Add(idea);
            //file upload
            try
            {
                foreach (HttpPostedFileBase file in files)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        string        oldfileName  = Path.GetFileName(file.FileName);
                        string        sessionID    = HttpContext.Session.SessionID;
                        string        newfilename  = sessionID + Guid.NewGuid().ToString() + oldfileName;
                        string        fileSavePath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadedFiles");
                        DirectoryInfo dirInfo      = new DirectoryInfo(fileSavePath);
                        string        path         = Path.Combine(dirInfo.FullName + "/", newfilename);
                        file.SaveAs(path);
                        document document = new document();
                        document.new_file_name = newfilename;
                        document.old_file_name = oldfileName;
                        document.created_at    = DateTime.Now;
                        document.idea_id       = idea.idea_id;
                        dbData.documents.Add(document);
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.error = ("There was an error: " + ex.Message);
            }


            //Configuring webMail class to send emails
            //gmail smtp server
            WebMail.SmtpServer = "smtp.gmail.com";
            //gmail port to send emails
            WebMail.SmtpPort = 587;
            WebMail.SmtpUseDefaultCredentials = true;
            //sending emails with secure protocol
            WebMail.EnableSsl = true;
            //EmailId used to send emails from application
            WebMail.UserName = "******";
            WebMail.Password = "******";

            //Get QA coordinator's email of the appropriate Department
            user loggedIn             = (user)Session["loggedIn"];
            IEnumerable <user> userQA = dbData.users.Where(u => u.role_id == 3).Where(u => u.department_id == loggedIn.department_id);



            //Sender email address.
            try
            {
                WebMail.From = "*****@*****.**";
                String ToEmail      = userQA.Single().email;
                String EmailSubject = "New Student Idea has been added!";
                String EMailBody    = "A student with <b> Student ID: " + loggedIn.user_university_id + "</b>"
                                      + " and <b> Username: "******"</b>"
                                      + " has submitted the following idea to the SIMS system." + "<br><br>"
                                      + "<b>Idea Title: </b>" + idea.idea_title + "<br><br>"
                                      + "<b>Idea Content: </b>" + idea.idea_content + "<br><br>"
                                      + "Please review this newly submitted idea and change its status in the SIMS." + "<br/>"

                                      + "<b>Link Idea: </b> <a href ='simscw2018.somee.com/Manager/Details?mode=approve&idea_id=" + idea.idea_id + "'>Click here</a>" + "<br><br>"

                                      + "Best regards," + "<br/><br/>"
                                      + "Quality Assurance team";
                //Send email
                WebMail.Send(to: ToEmail, subject: EmailSubject, body: EMailBody, isBodyHtml: true);
            }
            catch (Exception ex) { ViewBag.error = ("There was an error sending email : " + ex.Message); }
            //New Code: Validation Handling
            try
            {
                dbData.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            initIdealCreateComp(Session["cateCbb"] == null);
            ViewBag.Ideamessage = "Your idea has been submitted for approval";
            ViewBag.redirectUrl = (Url.Action("Index", "Idea", new { page = 1 }));
            return(View());
            //End COde
        }