public string SubmitTimesheet(string procedureName, int workerId, string rosterIDs, string periodStart, string periodEnd) { var dataService = new RosterDataService(); { string currentUserLogin = SPContext.Current.Web.CurrentUser.LoginName; List <Tuple <string, string> > whereCriteria = new List <Tuple <string, string> > { new Tuple <string, string>(FieldNames.WORKER_AD_ACCOUNT, currentUserLogin) }; var currentWorkerId = dataService .TableContent("WorkerPerson", "Id", "Id", whereCriteria) .Select(x => { return(x.Item1); }).FirstOrDefault(); if (currentWorkerId == 0) { throw new Exception(string.Format("Cannot find '{0}' in Employee list", currentUserLogin)); } if (currentWorkerId != workerId) { throw new Exception("Current timesheet(s) can be submitted only by Worker with ID#" + workerId); } List <Guid> ids = rosterIDs.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.ToGuid()).ToList(); var rosters = dataService.GetRosterEvents(ids, true); // get unly rejected OR unconfirmed rosters var rostersInCorrectStatus = rosters.Where(r => { var _props = r.RosterEventDictionary; return(_props.ContainsKey(FieldNames.STATUS_ID) && (_props[FieldNames.STATUS_ID].ToInt() == 6 || _props[FieldNames.STATUS_ID].ToInt() == 9)); }); var paramCollection = new List <Tuple <string, object> >(); paramCollection.Add(new Tuple <string, object>("@startDate", periodStart)); paramCollection.Add(new Tuple <string, object>("@endDate", periodEnd)); paramCollection.Add(new Tuple <string, object>("@workerId", workerId)); paramCollection.Add(new Tuple <string, object>("@workingRosterIds", string.Join(",", rostersInCorrectStatus.Where(r => r.EventTypeId == 1).Select(r => r.Id)))); paramCollection.Add(new Tuple <string, object>("@timesheetRosterIds", string.Join(",", rostersInCorrectStatus.Where(r => r.EventTypeId == 3).Select(r => r.Id)))); paramCollection.Add(new Tuple <string, object>("@currentUser", DbFieldUser.GetUserRosterId(SPContext.Current.Web.CurrentUser))); paramCollection.Add(new Tuple <string, object>("@message", string.Format("Sumbit at {0}", DateTime.Now.ToString(CultureInfo.InvariantCulture)))); return(dataService.ExecuteProcedure(procedureName, paramCollection)); } }