Example #1
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(((Themes.Models.user)curUser).person_id);

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

            using (Themes.Models.prjEntities ctx = new Themes.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 Themes.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));
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the tp_timer EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotp_timer(tp_timer tp_timer)
 {
     base.AddObject("tp_timer", tp_timer);
 }
 /// <summary>
 /// Create a new tp_timer object.
 /// </summary>
 /// <param name="t_p_t_id">Initial value of the t_p_t_id property.</param>
 public static tp_timer Createtp_timer(global::System.Int32 t_p_t_id)
 {
     tp_timer tp_timer = new tp_timer();
     tp_timer.t_p_t_id = t_p_t_id;
     return tp_timer;
 }