protected void holidayForm_DataBound(object sender, EventArgs e)
        {
            if (holidayForm.CurrentMode == DetailsViewMode.Edit)
            {
                ListBox ddlObserved = holidayForm.FindControl("ddlObserved") as ListBox;
                if (ddlObserved != null)
                {
                    ddlObserved.DataTextField  = "Name";
                    ddlObserved.DataValueField = "Id";
                    ddlObserved.DataSource     = _dataService.TableContent("State", "Id", "Id$Name").Select(x => {
                        var elem = x.Item2 as IDictionary <string, object>;
                        return(new { Id = elem["Id"], Name = elem["Name"].ToSafeString() });
                    });
                    ddlObserved.DataBind();
                }

                DropDownList ddlType = holidayForm.FindControl("ddlType") as DropDownList;
                if (ddlType != null)
                {
                    ddlType.DataTextField  = "Name";
                    ddlType.DataValueField = "Id";
                    ddlType.DataSource     = _dataService.TableContent("HolidayType", "Id", "Id$Name").Select(x => {
                        var elem = x.Item2 as IDictionary <string, object>;
                        return(new { Id = elem["Id"], Name = elem["Name"].ToSafeString() });
                    });
                    ddlType.DataBind();
                }
            }
        }
Exemple #2
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!");
        }
Exemple #3
0
        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));
            }
        }