public ActionResult Create(pojectdev pojectdev)
        {
            if (ModelState.IsValid)
            {
                db.pojectdevs.Add(pojectdev);
                db.SaveChanges();

                //for adding ADD Developer action to activity stream
                String username = Convert.ToString(Session["UserName"]);
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "ADD DEVELOPER";
                activitystr.description = username + " Added Developer " + pojectdev.devname;
                activitystr.issueid     = 4;
                activitystr.issuekey    = "-";
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = pojectdev.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();

                return(RedirectToAction("Create", new { pid = pojectdev.projectid }));
            }

            ViewBag.id = new SelectList(db.projects, "id", "projectkey", pojectdev.id);
            return(View(pojectdev));
        }
        public ActionResult Edit(issue issue)
        {
            if (ModelState.IsValid)
            {
                db.Entry(issue).State = EntityState.Modified;
                db.SaveChanges();
                //for adding edit action to activity stream
                String username = Convert.ToString(Session["UserName"]);
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Edit Issue";
                activitystr.description = username + " Edited issue " + issue.keyname;
                activitystr.issueid     = issue.id;
                activitystr.issuekey    = issue.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = issue.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();



                return(RedirectToAction("Details", "issues", new { id = issue.id }));
            }
            return(View(issue));
        }
        //delete
        public ActionResult prevcol(int issueid = 0)
        {
            var columns = db.columns.Include(c => c.project);

            var xx         = db.issues.Select(x => x).Where(x => x.id == issueid).FirstOrDefault();
            var projectid  = xx.projectid;
            var currentcol = xx.status;
            var zz         = db.columns.Select(x => x).Where(x => x.projectid == projectid).OrderBy(x => x.colid).ToList();
            int index      = zz.FindIndex(x => x.colid == currentcol);

            if (index > 0)
            {
                int prevcol = xx.status;
                xx.status = zz[index - 1].colid; db.SaveChanges();
                //for adding changing status action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Change Status";
                activitystr.description = "Changed an issue Statue from col " + prevcol + "to col " + xx.status;
                activitystr.issueid     = xx.id;
                activitystr.issuekey    = xx.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = xx.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();
            }



            return(RedirectToAction("Indexproject", new { id = projectid }));
        }
        public ActionResult Create(column column)
        {
            if (ModelState.IsValid)
            {
                db.columns.Add(column);
                db.SaveChanges();
                //for adding adding to the current sprint to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                var xx = db.projects.Select(x => x).Where(x => x.id == column.projectid).FirstOrDefault();

                String username = Convert.ToString(Session["UserName"]);
                activitystr.actiontype  = "Add Column";
                activitystr.description = username + " Added Column " + column.name + " To Project " + xx.projectname;
                activitystr.issueid     = 4;
                activitystr.issuekey    = "-";
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = column.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();

                return(RedirectToAction("indexproject", "Column", new { id = column.projectid }));;
            }

            ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", column.projectid);
            return(View(column));
        }
        public ActionResult Create(attachment attachment, HttpPostedFileBase fileToUpload)
        {
            if (ModelState.IsValid)
            {
                var filevalid = fileToUpload as HttpPostedFileBase;
                if (filevalid == null)
                {
                    ViewBag.pid   = attachment.projectid;
                    ViewBag.isid  = attachment.issueid;
                    ViewBag.error = "File is Required";
                    return(View(attachment));
                }
                //save the uploaded file in a variable
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    //for the file name
                    var fileName = Path.GetFileName(file.FileName);
                    //for not doubling
                    string path2 = Path.GetRandomFileName();
                    fileName = path2 + fileName;
                    //for saving file path
                    var path = Path.Combine(Server.MapPath("~/Upload/"), fileName);
                    //for saving file
                    attachment.attachmentdest = fileName;

                    file.SaveAs(path);//saved the file in path
                }


                db.attachments.Add(attachment);
                db.SaveChanges();


                String username = Convert.ToString(Session["UserName"]);

                db.SaveChanges();
                var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Add Attachment";
                activitystr.description = username + " Added Attachment " + attachment.Name + " To Issue " + ii.keyname;
                activitystr.issueid     = attachment.issueid;
                activitystr.issuekey    = ii.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = attachment.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();


                return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
            }

            ViewBag.pid  = attachment.projectid;
            ViewBag.isid = attachment.issueid;
            return(View(attachment));
        }
        public ActionResult Createe(Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.date = DateTime.Now.ToString();
                db.Comments.Add(comment);
                db.SaveChanges();
                ViewBag.pid  = comment.projectid;
                ViewBag.isid = comment.issueid;
                String username = Convert.ToString(Session["UserName"]);
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                int uid = int.Parse(Session["UserId"] + "");
                // if the comment was on the project
                if (comment.issueid == 4)
                {
                    var xx = db.projects.Select(x => x).Where(x => x.id == comment.projectid).FirstOrDefault();
                    //for adding Comment action to activity stream

                    activitystr.actiontype  = "Comment";
                    activitystr.description = username + " Commented on Project " + xx.projectname + " : " + comment.comment1;
                    activitystr.issueid     = 4;
                    activitystr.issuekey    = "-";
                    activitystr.actiondate  = DateTime.Now.ToString();
                    activitystr.projectid   = xx.id;

                    activitystr.userid = uid;
                    db.activitystreams.Add(activitystr);
                    db.SaveChanges();
                    return(RedirectToAction("indexproject", "column", new { id = comment.projectid }));
                }

                //if the comment was on the issue

                var zz = db.issues.Select(x => x).Where(x => x.id == comment.issueid).FirstOrDefault();
                //for adding Comment action to activity stream

                activitystr.actiontype  = "Comment";
                activitystr.description = username + " Commented on Issue " + zz.keyname + " : " + comment.comment1;
                activitystr.issueid     = zz.id;
                activitystr.issuekey    = zz.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = zz.projectid;

                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();

                return(RedirectToAction("Details", "issues", new { id = comment.issueid }));
            }
            if (comment.issueid != 4)
            {
                return(RedirectToAction("Details", "issues", new { id = comment.issueid }));
            }
            else
            {
                return(RedirectToAction("indexproject", "column", new { id = comment.projectid }));
            }
        }
        public ActionResult Edit(project project)
        {
            if (ModelState.IsValid)
            {
                UsersContext uc   = new UsersContext();
                var          user = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectleader).FirstOrDefault();
                project.projectleader = user.UserName;
                var user2 = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectowner).FirstOrDefault();
                project.projectowner = user2.UserName;

                var pro = db.projects.Select(x => x).Where(x => x.id == project.id).FirstOrDefault();
                pro.date          = project.date;
                pro.projectkey    = project.projectkey;
                pro.projectleader = project.projectleader;
                pro.projectname   = project.projectname;
                pro.projectowner  = project.projectowner;
                pro.projecttype   = project.projecttype;

                try
                {
                    db.Entry(pro).State = EntityState.Modified;
                    db.SaveChanges();
                    //for adding edit to activity stream
                    MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                    String username = Convert.ToString(Session["UserName"]);
                    activitystr.actiontype  = "Edit project";
                    activitystr.description = username + " Edited project " + project.projectname;
                    activitystr.issueid     = 4;
                    activitystr.issuekey    = "-";
                    activitystr.actiondate  = DateTime.Now.ToString();
                    activitystr.projectid   = project.id;
                    int uid = int.Parse(Session["UserId"] + "");
                    activitystr.userid = uid;
                    db.activitystreams.Add(activitystr);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            string errorMessages = string.Join("; ", ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.PropertyName + ": " + x.ErrorMessage));
                            throw new DbEntityValidationException(errorMessages);
                        }
                    }
                }
            }
            return(View(project));
        }
Beispiel #8
0
        public ActionResult Edit(Tag tag)
        {
            if (ModelState.IsValid)
            {    // for checking if the tag is already in use
                var zz = db.Tags.Select(x => x).Where(x => x.Tag1 == tag.Tag1 && x.projectid == tag.projectid && x.issueid == tag.issueid).FirstOrDefault();
                if (zz != null)
                {
                    ViewBag.errormsg = "Tag is already Used";
                    ViewBag.pid      = tag.projectid;
                    ViewBag.isid     = tag.issueid;
                    return(View(tag));
                }
                Tag oldtag = db.Tags.Find(tag.id);
                // for the old tag name for the activity stream
                String old = oldtag.Tag1;
                oldtag.Tag1 = tag.Tag1;

                db.SaveChanges();



                String username = Convert.ToString(Session["UserName"]);


                var ii = db.issues.Select(x => x).Where(x => x.id == tag.issueid).FirstOrDefault();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Edit Tag";
                activitystr.description = username + " Edited Tag " + old + " In Issue " + ii.keyname + " To " + tag.Tag1;
                activitystr.issueid     = tag.issueid;
                activitystr.issuekey    = ii.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = tag.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();



                return(RedirectToAction("Details", "issues", new { id = tag.issueid }));
            }
            ViewBag.pid  = tag.projectid;
            ViewBag.isid = tag.issueid;
            return(View(tag));
        }
        public ActionResult addtocurrentsprint(int issueid = 0)
        {
            var xx = db.issues.Select(x => x).Where(x => x.id == issueid).FirstOrDefault();
            //for checking if the user is allowed
            var adminproj = db.projects.Select(x => x).Where(x => x.id == xx.projectid && x.projectleader == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            var projid = xx.projectid;
            //for checking if there are columns in the project
            var cc = db.columns.Select(x => x).Where(x => x.projectid == projid).First();

            if (cc != null)
            {
                var zz = db.projects.Select(x => x).Where(x => x.id == projid).FirstOrDefault();
                var currentsprintid = zz.currentsprint;
                // to make the issue in the current sprint
                xx.sprintid = currentsprintid;
                db.SaveChanges();
                //for adding adding to the current sprint action to activity stream
                var yy = db.sprints.Select(x => x).Where(x => x.sid == currentsprintid).FirstOrDefault();
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                String username = Convert.ToString(Session["UserName"]);
                activitystr.actiontype  = "Add to Sprint";
                activitystr.description = username + " Added An Issue To Sprint Number " + yy.number;
                activitystr.issueid     = xx.id;
                activitystr.issuekey    = xx.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = xx.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();
            }



            return(RedirectToAction("Indexproject", "column", new { id = projid }));
        }
        public ActionResult assigneissue(int id = 0)
        {
            // to assign issue to developer
            issue issue = db.issues.Find(id);
            // for checking if the user allowed
            var adminproj = db.pojectdevs.Select(x => x).Where(x => x.projectid == issue.projectid && x.devname == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            //int uid = int.Parse(Session["UserId"] + "");
            if (issue == null)
            {
                return(HttpNotFound());
            }
            // for checking if the issue has already an assignee
            if (issue.assignee == null)
            {
                String username = Convert.ToString(Session["UserName"]);
                issue.assignee = username;
                db.SaveChanges();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Assign";
                activitystr.description = username + " Assgined issue " + issue.keyname;
                activitystr.issueid     = issue.id;
                activitystr.issuekey    = issue.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = issue.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();
                return(View("Details", issue));
            }
            ViewBag.errormsg = "already assigned";
            //html condition using viewbag if the viewbag contains some value
            return(View("Details", issue));
        }
        public ActionResult Edit(attachment attachment)
        {
            if (ModelState.IsValid)
            {
                attachment oldattachment = db.attachments.Find(attachment.id);
                // for the activity stream
                String old = oldattachment.Name;
                oldattachment.Name = attachment.Name;

                db.SaveChanges();



                String username = Convert.ToString(Session["UserName"]);

                db.SaveChanges();
                var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Edit Attachment";
                activitystr.description = username + " Edited Attachment " + old + " In Issue " + ii.keyname + " To " + attachment.Name;
                activitystr.issueid     = attachment.issueid;
                activitystr.issuekey    = ii.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = attachment.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();



                return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
            }
            ViewBag.issueid   = new SelectList(db.issues, "id", "keyname", attachment.issueid);
            ViewBag.projectid = new SelectList(db.projects, "id", "projectkey", attachment.projectid);
            return(View(attachment));
        }
        public ActionResult unassignissuemaster(int id = 0)
        {   // for unassign the issue from the developer by the scrum master
            issue issue     = db.issues.Find(id);
            var   adminproj = db.projects.Select(x => x).Where(x => x.id == issue.projectid && x.projectleader == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            //int uid = int.Parse(Session["UserId"] + "");
            if (issue == null)
            {
                return(HttpNotFound());
            }
            if (issue.assignee != null)
            {
                String username    = Convert.ToString(Session["UserName"]);
                var    oldassignne = issue.assignee;
                issue.assignee = null;
                db.SaveChanges();
                //for adding assign action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "UnAssign Issue From DEV";
                activitystr.description = username + " UnAssigned Issue " + issue.keyname + " From Developer " + oldassignne;
                activitystr.issueid     = issue.id;
                activitystr.issuekey    = issue.keyname;
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = issue.projectid;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();
                return(View("Details", issue));
            }
            ViewBag.errormsg = "Not assigned";
            //html condition using viewbag if the viewbag contains some value
            return(View("Details", issue));
        }
        public ActionResult DeleteComplete(int id)
        {
            issue issue = db.issues.Find(id);

            //for adding delete action to activity stream
            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            activitystr.actiontype  = "Delete Issue";
            activitystr.description = "Deleted an issue";
            activitystr.issueid     = issue.id;
            activitystr.issuekey    = issue.keyname;
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = issue.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();


            db.issues.Remove(issue);
            db.SaveChanges();
            return(RedirectToAction("indexproject", "Column", new { id = issue.projectid }));
        }
        public ActionResult Delete(int id = 0)
        {
            attachment attachment = db.attachments.Find(id);
            // for checking if the user is allowed
            var adminproj = db.pojectdevs.Select(x => x).Where(x => x.projectid == attachment.projectid && x.devname == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            db.attachments.Remove(attachment);
            db.SaveChanges();


            String username = Convert.ToString(Session["UserName"]);

            db.SaveChanges();
            var ii = db.issues.Select(x => x).Where(x => x.id == attachment.issueid).FirstOrDefault();

            //for adding assign action to activity stream
            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            activitystr.actiontype  = "Delete Attachment";
            activitystr.description = username + " Deleted Attachment " + attachment.Name + " In Issue " + ii.keyname;
            activitystr.issueid     = attachment.issueid;
            activitystr.issuekey    = ii.keyname;
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = attachment.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();



            return(RedirectToAction("Details", "issues", new { id = attachment.issueid }));
        }
        public ActionResult Delete(int id = 0)
        {
            var issueids  = db.issues.Select(x => x).Where(x => x.id == id).FirstOrDefault();
            var adminproj = db.projects.Select(x => x).Where(x => x.id == issueids.projectid && x.projectleader == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            issue issue = db.issues.Find(id);

            if (issue == null)
            {
                return(HttpNotFound());
            }
            //for adding delete action to activity stream
            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            String username = Convert.ToString(Session["UserName"]);

            activitystr.actiontype  = "Delete Issue";
            activitystr.description = username + " Deleted issue " + issue.keyname;
            activitystr.issueid     = issue.id;
            activitystr.issuekey    = issue.keyname;
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = issue.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();


            db.issues.Remove(issue);
            db.SaveChanges();
            return(RedirectToAction("indexproject", "Column", new { id = issue.projectid }));
        }
        public ActionResult assignissuemaster(issue issue)
        {
            issue issue1 = db.issues.Find(issue.id);

            issue1.assignee = issue.assignee;
            db.SaveChanges();
            //for adding edit action to activity stream
            String username = Convert.ToString(Session["UserName"]);

            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            activitystr.actiontype  = "Assign Issue To DEV";
            activitystr.description = username + " Assigned Issue " + issue.keyname + " To Developer " + issue.assignee;
            activitystr.issueid     = issue.id;
            activitystr.issuekey    = issue.keyname;
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = issue.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = issue.id }));
        }
        public ActionResult UpdateIssuesAjax(string itemIds)
        {
            // for updating the issues position
            List <int> itemIdList = new List <int>();

            // to put the ajax info from the agile board in a int list without the ',' between items
            itemIdList = itemIds.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
            // for the column id of the issue
            int state = 1;
            // flag for column if true the next item is for colmun id
            Boolean colflag = false;
            // flag for issue if true the next item is for issue id
            Boolean issueflag = false;


            foreach (var item in itemIdList)
            {
                // the next item is a column id
                if (item == 0)
                {
                    colflag   = true;
                    issueflag = false;
                    continue;
                }

                if (colflag)
                {
                    //the current item is the column id and the next item is an issue id
                    state = item; colflag = false; issueflag = true; continue;
                }
                if (issueflag)
                {       //selecting the issue and put the state (column id) in the status field of the issue
                    var iss = db.issues.Select(x => x).Where(m => m.id == item).FirstOrDefault();
                    if (iss.status != state)
                    {
                        var beforestate = iss.status;
                        iss.status = state;
                        db.SaveChanges();

                        //for adding changing status action to activity stream
                        MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                        var    before   = db.columns.Select(x => x).Where(x => x.colid == beforestate).FirstOrDefault();
                        var    after    = db.columns.Select(x => x).Where(x => x.colid == state).FirstOrDefault();
                        String username = Convert.ToString(Session["UserName"]);
                        activitystr.actiontype  = "Change Issue Status";
                        activitystr.description = username + " Changed Issue " + iss.keyname + " Status From (" + before.name + ") To (" + after.name + ")";
                        activitystr.issueid     = iss.id;
                        activitystr.issuekey    = iss.keyname;
                        activitystr.actiondate  = DateTime.Now.ToString();
                        activitystr.projectid   = iss.projectid;
                        int uid = int.Parse(Session["UserId"] + "");
                        activitystr.userid = uid;
                        db.activitystreams.Add(activitystr);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbEntityValidationException e)
                        {
                            var newException = new FormattedDbEntityValidationException(e);
                            throw newException;
                        }
                    }
                }
            }


            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(issue issue)
        {
            if (ModelState.IsValid)
            {   // for the keyname error message
                ViewBag.errormsg = "";

                var zzz = db.projects.Select(x => x).Where(x => x.id == issue.projectid).FirstOrDefault();
                // for compining the keyname of the project with the keyname of the issue
                String kname = zzz.projectkey + "_" + issue.keyname;
                // for checking if the keyname is already in use
                var mm = db.issues.Select(x => x).Where(x => x.keyname == kname).FirstOrDefault();
                if (mm != null)
                {
                    ViewBag.errormsg = "Key Name is in Use";
                    // for passing the list of the developers in the project to the view
                    var devsinproj = db.pojectdevs.Where(x => x.projectid == issue.projectid).Select(x => x.devname).ToList();
                    var users      = Roles.GetUsersInRole("developer");
                    foreach (var user in users)
                    {
                        if (!devsinproj.Contains(user))
                        {
                            users = users.Select(x => x).Where(x => x != user).ToArray();
                        }
                    }
                    SelectList slist = new SelectList(users);

                    ViewBag.Usersq = slist;
                    ViewBag.projid = issue.projectid;


                    return(View(issue));
                }
                issue.keyname = kname;
                //for getting the first column id in the agileboard and save it in the status field , when we add it to the agileboard it
                // takes place in the first column
                var zq = db.columns.Select(x => x).Where(x => x.projectid == issue.projectid).FirstOrDefault();
                issue.status = zq.colid;
                if (issue.priority == "High")
                {
                    issue.priority = "1";
                }
                if (issue.priority == "Medium")
                {
                    issue.priority = "2";
                }
                if (issue.priority == "Low")
                {
                    issue.priority = "3";
                }


                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:4419");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.PostAsJsonAsync("api/Backlogapi", issue).Result;
                String username = Convert.ToString(Session["UserName"]);
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                int uid = int.Parse(Session["UserId"] + "");
                // if the response successeded
                if (response.IsSuccessStatusCode)
                {
                    //for adding create action to activity stream
                    var issueaftersave = db.issues.Select(z => z).Where(z => z.keyname == issue.keyname).FirstOrDefault();
                    activitystr.actiontype  = "Create Issue";
                    activitystr.description = username + " Created issue " + issue.keyname;
                    activitystr.issueid     = issueaftersave.id;
                    activitystr.issuekey    = issue.keyname;
                    activitystr.actiondate  = DateTime.Now.ToString();
                    activitystr.projectid   = issue.projectid;
                    //int uid = int.Parse(Session["UserId"] + "");
                    activitystr.userid = uid;
                    db.activitystreams.Add(activitystr);
                    db.SaveChanges();

                    return(RedirectToAction("indexproject", "Column", new { id = issue.projectid }));
                }
                else
                {
                    return(View(issue));
                }



                //db.issues.Add(issue);
                //db.SaveChanges();


                //  String username = Convert.ToString(Session["UserName"]);
                // MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                //activitystr.actiontype = "Create Issue";
                //activitystr.description = username + " Created issue " + issue.keyname;
                //activitystr.issueid = issue.id ;
                //activitystr.issuekey = issue.keyname ;
                //activitystr.actiondate = DateTime.Now.ToString();
                //activitystr.projectid = issue.projectid ;

                //activitystr.userid = uid;
                //db.activitystreams.Add(activitystr);
                //db.SaveChanges();
            }

            return(View(issue));
        }
        public ActionResult EndSprint(int id = 0)
        {
            // for checking if the user allowed
            var adminproj = db.projects.Select(x => x).Where(x => x.id == id && x.projectleader == User.Identity.Name).FirstOrDefault();

            if (adminproj == null)
            {
                return(RedirectToAction("Index", "project"));
            }
            // creating a new sprint
            MvcApplicationTest1.DAL.sprint sp = new DAL.sprint();
            sp.date      = DateTime.Now.ToString();
            sp.projectid = id;

            // for giving the new sprint its id
            var zz = db.projects.Select(x => x).Where(x => x.id == id).FirstOrDefault();
            var xx = db.sprints.Select(x => x).Where(x => x.sid == zz.currentsprint).FirstOrDefault();

            sp.number = xx.number + 1;

            db.sprints.Add(sp);
            db.SaveChanges();

            //for moving not completed issues to the next sprint
            var zz2       = db.columns.Select(x => x).Where(x => x.projectid == id).OrderByDescending(x => x.colid).FirstOrDefault();
            var lastcolid = zz2.colid;

            //list of unfinished issues
            var zz3 = db.issues.Select(x => x).Where(x => x.projectid == id && x.status != lastcolid && x.sprintid == zz.currentsprint).ToList();

            // it copies the unfinshed issue to a new issue and add it to the current sprint
            // and moves the unfinished issues to the new sprint for saving the change log
            foreach (var item in zz3)
            {
                MvcApplicationTest1.DAL.issue s = new MvcApplicationTest1.DAL.issue();
                s.keyname     = item.keyname;
                s.status      = item.status;
                s.descreption = item.descreption;
                s.type        = item.type;
                s.priority    = item.priority;
                s.tags        = item.tags;
                s.estimate    = item.estimate;
                s.assignee    = item.assignee;
                s.rankid      = item.rankid;
                s.projectid   = item.projectid;
                s.sprintid    = zz.currentsprint;
                item.sprintid = sp.sid;
                db.issues.Add(s);
                db.SaveChanges();
            }
            // make the new sprint the current sprint
            zz.currentsprint = sp.sid;
            db.SaveChanges();

            MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
            String username = Convert.ToString(Session["UserName"]);

            activitystr.actiontype  = "End Sprint";
            activitystr.description = username + " Ended Sprint Number " + xx.number;
            activitystr.issueid     = 4;
            activitystr.issuekey    = "-";
            activitystr.actiondate  = DateTime.Now.ToString();
            activitystr.projectid   = sp.projectid;
            int uid = int.Parse(Session["UserId"] + "");

            activitystr.userid = uid;
            db.activitystreams.Add(activitystr);
            db.SaveChanges();
            return(RedirectToAction("Indexproject", "Column", new { id = zz.id }));;
        }
        public ActionResult Create(project project)
        {
            if (ModelState.IsValid)
            {
                UsersContext uc   = new UsersContext();
                var          user = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectleader).FirstOrDefault();
                project.projectleader = user.UserName;
                var user2 = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectowner).FirstOrDefault();
                project.projectowner = user2.UserName;
                // for checking if the keyname is in use
                var pro = db.projects.Select(x => x).Where(x => x.projectkey == project.projectkey).FirstOrDefault();

                if (pro != null)
                {
                    ViewBag.ErrorMessage = "Key is in use";

                    var        users = Roles.GetUsersInRole("teamleader");
                    SelectList list  = new SelectList(users);
                    ViewBag.Usersq = list;

                    var        users2 = Roles.GetUsersInRole("projectowner");
                    SelectList list2  = new SelectList(users2);
                    ViewBag.Usersqq = list2;


                    return(View(project));
                }
                project.date = DateTime.Now.ToString();
                db.projects.Add(project);
                db.SaveChanges();

                // for creating the first sprint
                MvcApplicationTest1.DAL.sprint sp = new DAL.sprint();
                sp.date      = DateTime.Now.ToString();
                sp.projectid = project.id;
                sp.number    = 1;
                db.sprints.Add(sp);
                db.SaveChanges();
                // for making the new sprint the projects first sprint
                project.currentsprint = sp.sid;



                db.SaveChanges();
                Session["projectid"] = project.id;
                String username = Convert.ToString(Session["UserName"]);
                //for adding delete action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "Create Project";
                activitystr.description = username + " Created Project " + project.projectname;
                activitystr.issueid     = 4;
                activitystr.issuekey    = "-";
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = project.id;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
        public ActionResult EndProject(int id = 0)
        {
            //UsersContext uc = new UsersContext();
            //var user = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectleader).FirstOrDefault();
            //project.projectleader = user.UserName;
            //var user2 = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectowner).FirstOrDefault();
            //project.projectowner = user2.UserName;
            //var pro = db.projects.Select(x => x).Where(x => x.projectkey == project.projectkey).FirstOrDefault();



            //for checking if the user allowed to show this action
            //var adminproj = db.projects.Select(x => x).Where(x => x.id == id && x.projectleader == User.Identity.Name).FirstOrDefault();
            //if (adminproj == null)
            //{
            //    return RedirectToAction("Index", "project");
            //}


            //for checking if the user allowed to show this action
            if (User.IsInRole("developer"))
            {
                var adminproj = db.pojectdevs.Select(x => x).Where(x => x.projectid == id && x.devname == User.Identity.Name).FirstOrDefault();
                if (adminproj == null)
                {
                    return(RedirectToAction("Index", "project"));
                }
            }

            if (User.IsInRole("projectowner"))
            {
                var adminproj = db.projects.Select(x => x).Where(x => x.id == id && x.projectowner == User.Identity.Name).FirstOrDefault();
                if (adminproj == null)
                {
                    return(RedirectToAction("Index", "project"));
                }
            }

            if (User.IsInRole("teamleader"))
            {
                var adminproj = db.projects.Select(x => x).Where(x => x.id == id && x.projectleader == User.Identity.Name).FirstOrDefault();
                if (adminproj == null)
                {
                    return(RedirectToAction("Index", "project"));
                }
            }



            var xx = db.projects.Select(x => x).Where(x => x.id == id).FirstOrDefault();

            if (xx.status != "closed" && User.IsInRole("teamleader"))
            {
                xx.status = "closed";
                db.SaveChanges();

                Session["projectid"] = id;
                String username = Convert.ToString(Session["UserName"]);
                //for adding delete action to activity stream
                MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream();
                activitystr.actiontype  = "End Project";
                activitystr.description = username + " Ended Project " + xx.projectname;
                activitystr.issueid     = 4;
                activitystr.issuekey    = "-";
                activitystr.actiondate  = DateTime.Now.ToString();
                activitystr.projectid   = id;
                int uid = int.Parse(Session["UserId"] + "");
                activitystr.userid = uid;
                db.activitystreams.Add(activitystr);
                db.SaveChanges();
            }
            //for checking if the project does closed or not
            var tt = db.projects.Select(x => x).Where(x => x.id == id).FirstOrDefault();

            if (tt.status != "closed")
            {
                return(RedirectToAction("Indexproject", "column", new { id = id }));
            }
            var zz = db.issues.Select(x => x).Where(x => x.projectid == id).GroupBy(x => x.keyname).Select(z => z.OrderByDescending(q => q.sprintid).FirstOrDefault()).ToList();

            ViewBag.numofissues = zz.Count;
            var uu = db.sprints.Select(x => x).Where(x => x.projectid == id).ToList();

            ViewBag.numofsprints = uu.Count;

            //for counting unfinished issues
            // the last column id
            var zz2 = db.columns.Select(x => x).Where(x => x.projectid == id).OrderByDescending(x => x.colid).FirstOrDefault();

            if (zz2 != null)
            {
                var lastcolid = zz2.colid;

                //count the list of unfinished issues in the last sprint
                var zz3 = db.issues.Select(x => x).Where(x => x.projectid == id && x.status != lastcolid && x.sprintid == xx.currentsprint).ToList();
                ViewBag.numofunfinishedissues = zz3.Count;
            }
            else
            {
                ViewBag.numofunfinishedissues = 0;
            }



            return(View(xx));
        }