Example #1
0
        public JsonResult TimeSheet(string queryItems)
        {
            if (String.IsNullOrEmpty(queryItems))
            {
                return(Json(new { status = "error", message = "No query data provided!" }, JsonRequestBehavior.AllowGet));
            }

            //get the myActivity from the Session
            var myActivity = getMyActivityFromSession();

            Models.Activity.MyActivity tempData = new Models.Activity.MyActivity();
            tempData = (Models.Activity.MyActivity)myActivity.Clone();

            const int numberOfItems = 5;
            var       custom        = new
            {
                selectedItems = new List <string>(),
                numberOfItems = ""
            };
            var convertedJson = custom;

            //Deserialze de json accordin to the custom settings!
            try
            {
                convertedJson = JsonConvert.DeserializeAnonymousType(queryItems, custom);
            }
            catch (Exception ex)
            {
                //log the exception
                return(Json(new { status = "error", message = "Wrong Json provided in query. Contact System Administrator!" }, JsonRequestBehavior.AllowGet));
            }

            //Set a default if no value provided in the Json
            if (String.IsNullOrEmpty(convertedJson.numberOfItems))
            {
                tempData.numberOfItems = numberOfItems;
            }
            else
            {
                tempData.numberOfItems = Int32.Parse(convertedJson.numberOfItems);
            }


            if (!convertedJson.selectedItems.Contains("0"))
            {
                List <Models.Portal.WorkRecord> workLogsFiltered = new List <Models.Portal.WorkRecord>();

                foreach (var projectId in convertedJson.selectedItems)
                {
                    int projectIdAsInt = Int32.Parse(projectId);
                    workLogsFiltered.AddRange(tempData.workLogs.Where(x => x.projectId == projectIdAsInt).ToList());
                }
                tempData.workLogs = workLogsFiltered.OrderByDescending(x => x.startDate).ToList();
            }



            IncreaseSessionTimout();
            return(Json(new { status = "success", data = tempData }, JsonRequestBehavior.AllowGet));
        }
Example #2
0
 protected MyActivity(Models.Activity.MyActivity myActivity)
 {
     this.workLogs      = myActivity.workLogs;
     this.projects      = myActivity.projects;
     this.leaves        = myActivity.leaves;
     this.numberOfItems = myActivity.numberOfItems;
 }
Example #3
0
 private void SetMyStatSession(Models.Activity.MyActivity myActivity)
 {
     Session["myActivity"] = myActivity;
     IncreaseSessionTimout();
 }