Ejemplo n.º 1
0
        public string EndorseRoster(Guid listId, Guid itemId)
        {
            if (listId == Guid.Empty)
            {
                listId = TableIDs.TIMESHEET_ROSTERS;
            }

            var dataService = new RosterDataService();
            var roster      = dataService.ListSingleRosterEvent(listId, itemId);
            var rosterProps = roster.RosterEventDictionary;

            if (rosterProps.ContainsKey(FieldNames.WORKER_PERSON_ID) && rosterProps[FieldNames.WORKER_PERSON_ID] != null)
            {
                if (!rosterProps.ContainsKey(FieldNames.STATUS_ID) || rosterProps[FieldNames.STATUS_ID] == null || rosterProps[FieldNames.STATUS_ID].ToInt() != 7)
                {
                    throw new Exception("Only Confirmed roster can be endorsed!");
                }

                int workerId = rosterProps[FieldNames.WORKER_PERSON_ID].ToInt();
                List <Tuple <string, string> > whereCriteria = new List <Tuple <string, string> > {
                    new Tuple <string, string>("Id", workerId.ToString())
                };
                string        currentUserLogin   = SPContext.Current.Web.CurrentUser.LoginName;
                List <string> userLoginAndGroups = new List <string>();
                userLoginAndGroups.Add(currentUserLogin);
                userLoginAndGroups.AddRange(SPContext.Current.Web.CurrentUser.Groups.OfType <SPGroup>().Select(gr => gr.Name));

                var workerInfo = dataService.TableContent("WorkerPerson", "Id", FieldNames.WORKER_TEAMLEADER, whereCriteria).Select(x =>
                {
                    var elem = x.Item2 as IDictionary <string, object>;
                    return(new { WorkerId = x.Item1, TeamLeader = elem[FieldNames.WORKER_TEAMLEADER].ToSafeString() });
                }).FirstOrDefault();

                if (workerInfo == null)
                {
                    throw new Exception("Cannot find information about Worker with ID#" + workerId);
                }
                //if (!workerInfo.TeamLeader.Equals(currentUserLogin))
                if (!userLoginAndGroups.Contains(workerInfo.TeamLeader))
                {
                    throw new Exception("Only TeamLeader can endorse roster for selected Worker!");
                }

                var paramCollection = new List <Tuple <string, object> >
                {
                    new Tuple <string, object>("@id", roster.Id.ToString()),
                    new Tuple <string, object>("@reason",
                                               string.Format("Endorsed at {0} by {1}", DateTime.Now.ToString(), currentUserLogin)),
                    new Tuple <string, object>("@message", "")
                };
                return(dataService.ExecuteProcedure("[dbo].[Endorsed]", paramCollection));
            }
            throw new Exception("Cannot find '" + FieldNames.WORKER_PERSON_ID +
                                "' field in a roster or value of this field is NULL!");
        }
Ejemplo n.º 2
0
        public string SubmitTimesheet(Guid listId, Guid itemId)
        {
            if (listId == Guid.Empty)
            {
                listId = TableIDs.TIMESHEET_ROSTERS;
            }
            var dataService = new RosterDataService();
            var roster      = dataService.ListSingleRosterEvent(listId, itemId);
            var rosterProps = roster.RosterEventDictionary;

            if (rosterProps.ContainsKey(FieldNames.WORKER_PERSON_ID) && rosterProps[FieldNames.WORKER_PERSON_ID] != null)
            {
                // execute global Submit procedure
                return(SubmitTimesheet(
                           "[dbo].[RorterEvents_TimesheetSubmit]",
                           rosterProps[FieldNames.WORKER_PERSON_ID].ToInt(),
                           itemId.ToSafeString(),
                           SPUtility.CreateISO8601DateTimeFromSystemDateTime(rosterProps[FieldNames.START_DATE].ToDateTime()),
                           SPUtility.CreateISO8601DateTimeFromSystemDateTime(rosterProps[FieldNames.END_DATE].ToDateTime())
                           ));
            }
            throw new Exception("Cannot find '" + FieldNames.WORKER_PERSON_ID + "' field in a roster or value of this field is NULL");
        }