Ejemplo n.º 1
0
        public JsonResult json_savePermissions()
        {
            var pars = Request.Params;

            string roleIds = pars["roleIds"];


            using (TransactionScope t = new TransactionScope())
            {
                using (Models.prjEntities ctx = new Models.prjEntities())
                {
                    //Delete all related permissions first
                    var allUserPermissions =
                        (
                            from p in ctx.permission
                            select p
                        );
                    foreach (var pi in allUserPermissions)
                    {
                        ctx.permission.DeleteObject(pi);
                        ctx.SaveChanges();
                    }
                    if (!String.IsNullOrEmpty(roleIds))
                    {
                        string[] roles = roleIds.Split(',');
                        foreach (var role in roles)
                        {
                            var roleId = Convert.ToInt32(role);
                            //Check if already exists
                            var roleUserExists =
                                (
                                    from p in ctx.permission
                                    where p.user_id == 1 && p.role_id == (int)roleId
                                    select new { temp = 1 }
                                );

                            if (roleUserExists.Count() != 0)
                            {
                                continue;
                            }

                            //Build New Permission Object
                            var newPermission = new Models.permission()
                            {
                                user_id = 1,
                                role_id = roleId
                            };

                            ctx.permission.AddObject(newPermission);
                            ctx.SaveChanges();
                        }
                    }

                    t.Complete();
                }
            }

            return(Json(new { result = "Done" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        //update timer
        public JsonResult json_updateTaskProgress()
        {
            var pars    = Request.Params;
            int task_id = Convert.ToInt32(pars["task_id"]);

            var curUser   = Session["user"];
            int person_id = Convert.ToInt32(((Models.user)curUser).person_id);

            int task_person_id = this.getCurTaskPerson(task_id, person_id).First().task_person_id;

            using (Models.prjEntities ctx = new Models.prjEntities())
            {
                var cur_task_person =
                    (
                        from tp in ctx.task_person
                        where tp.task_person_id == task_person_id
                        select tp
                    ).First();


                /* First check if there is any open timer then update end_timestamp else create new with open end_timestamp */
                var q =
                    (
                        from tpt in ctx.tp_timer
                        where
                        tpt.task_person.task_person_id == task_person_id &&
                        tpt.task_person.user_task_status_id != 3 &&/*Not Finalized*/
                        tpt.end_stamp == null    /*open timer*/
                        select tpt
                    );
                if (q.Count() != 0)
                {
                    q.First().end_stamp = DateTime.Now;
                    q.First().is_commited = true;
                    q.First().task_person.user_task_status_id = 2 /*Progressing*/;
                    ctx.SaveChanges();
                }
                else
                {
                    var newTimer = new Models.tp_timer()
                    {
                        t_p_id      = task_person_id,
                        start_stamp = DateTime.Now,
                        end_stamp   = null,
                        is_commited = false
                    };

                    ctx.tp_timer.AddObject(newTimer);
                    ctx.SaveChanges();
                }
            }

            //return back current timer status after operation
            return(Json(new { result = this.getTaskPersontimerStat(task_id, person_id) }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public JsonResult json_saveNewTask()
        {
            var    pars             = Request.Params;
            string task_title       = pars["Task_title"];
            string task_description = pars["Task_description"];
            string task_deadline    = pars["task_deadline"];
            string filenames        = pars["filenames"];


            using (Models.prjEntities ctx = new Models.prjEntities())
            {
                Models.task newTask = new Models.task()
                {
                    title          = task_title,
                    description    = task_description,
                    task_status_id = 2,/*Progressing*/
                    stamp          = DateTime.Now,
                    is_active      = true
                };
                ctx.task.AddObject(newTask);
                ctx.SaveChanges();
            }

            //(2) add document objects for Task


            return(Json(new { result = "done" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        //Adds new descriptive content for specific task person
        public JsonResult json_saveNewTaskStat()
        {
            var pars = Request.Params;

            int    task_id     = Convert.ToInt32(pars["task_id"]);
            string description = pars["description"];

            var curUser   = Session["user"];
            int person_id = Convert.ToInt32(((Models.user)curUser).person_id);

            int task_person_id = this.getCurTaskPerson(task_id, person_id).First().task_person_id;

            using (Models.prjEntities ctx = new Models.prjEntities())
            {
                var newTaskProgress = new Models.tp_progress()
                {
                    t_p_id      = task_person_id,
                    description = description,
                    datetime    = DateTime.Now
                };

                ctx.tp_progress.AddObject(newTaskProgress);
                ctx.SaveChanges();
            }

            return(Json(new { result = "done" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public JsonResult json_saveUserSequence()
        {
            var pars    = Request.Params;
            int task_id = Convert.ToInt32(pars["task_id"]);

            string[] person_ids = pars["taskUsersSequence"].Split(',');


            using (Models.prjEntities ctx = new Models.prjEntities())
            {
                foreach (var item in person_ids)
                {
                    Models.task_person tp = new Models.task_person()
                    {
                        task_id             = task_id,
                        person_id           = Convert.ToInt32(item),
                        user_task_status_id = 1 /*Not Started*/
                    };
                    ctx.task_person.AddObject(tp);
                    ctx.SaveChanges();
                }
            }

            return(Json(new { result = "done" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        //if tjhere is any open timer close it . and finalu task_person obect goes to finalize stat
        public JsonResult json_finalizeTaskPerson()
        {
            var pars = Request.Params;

            int task_id   = Convert.ToInt32(pars["task_id"]);
            var curUser   = Session["user"];
            int person_id = Convert.ToInt32(((Models.user)curUser).person_id);

            using (Models.prjEntities ctx = new Models.prjEntities())
            {
                var cur_task_person =
                    (
                        from tp in ctx.task_person

                        where tp.task_id == task_id && tp.user_task_status_id != 3 /*NOT (finalized)*/
                        orderby tp.task_person_id ascending
                        select tp
                    ).First();



                if (this.getTaskPersontimerStat(task_id, person_id) == "pause")   //timer open
                {
                    //close timer
                    var open_time_task_person = (
                        from tpt in ctx.tp_timer
                        where
                        tpt.task_person.task_person_id == cur_task_person.task_person_id &&
                        tpt.task_person.user_task_status_id == 2 &&    /*Progressing*/
                        tpt.end_stamp == null        /*open timer*/
                        select tpt
                        ).First();
                    open_time_task_person.end_stamp = DateTime.Now;
                }
                //finally finalize task person
                cur_task_person.user_task_status_id = 3;
                ctx.SaveChanges();
            }

            return(Json(new { result = "done" }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult json_savePermissions()
        {
            var pars = Request.Params;

            string roleIds = pars["roleIds"];

            using (TransactionScope t = new TransactionScope())
            {
                using (Models.prjEntities ctx = new Models.prjEntities())
                {
                    //Delete all related permissions first
                    var allUserPermissions =
                    (
                            from p in ctx.permission
                            select p
                    );
                    foreach (var pi in allUserPermissions)
                    {
                        ctx.permission.DeleteObject(pi);
                        ctx.SaveChanges();
                    }
                    if (!String.IsNullOrEmpty(roleIds))
                    {
                        string[] roles = roleIds.Split(',');
                        foreach (var role in roles)
                        {
                            var roleId = Convert.ToInt32(role);
                            //Check if already exists
                            var roleUserExists =
                            (
                               from p in ctx.permission
                               where p.user_id == 1 && p.role_id == (int)roleId
                               select new { temp = 1 }
                            );

                            if (roleUserExists.Count() != 0)
                                continue;

                            //Build New Permission Object
                            var newPermission = new Models.permission()
                            {
                                user_id = 1,
                                role_id = roleId
                            };

                            ctx.permission.AddObject(newPermission);
                            ctx.SaveChanges();
                        }
                    }

                    t.Complete();
                }

            }

            return Json(new { result = "Done" }, JsonRequestBehavior.AllowGet);
        }