public ListTemplatesResult ListTemplates(ListTemplatesQuery query) { DisableCaching(); var result = new ListTemplatesResult { Page = query.Page, Items = new List <ListTemplatesResultItem>() }; try { var templates = new RosterDataService().ListTemplates(); string field_ID = new MasterRoster().PrimaryField; string field_Description = new MasterRoster().Description; foreach (var properties in templates) { var id = properties.First(item => item.Key == field_ID).Value; string value = properties.First(item => item.Key == field_Description).Value.ToSafeString(); if (value.ContainsIgnoreCase(query.Query)) { result.Items.Add(new ListTemplatesResultItem { id = id.ToSafeString(), text = value }); } } } catch (Exception ex) { HandleException(ex); } return(result); }
public listView <Entity> ListTemplates(string version, QueryDisplayParams query) { DisableCaching(); var result = new listView <Entity>(); try { result.page = new pager <Entity>(); var service = new RosterDataService(); var content = service.ListTemplates().ToList(); result.total = content.Count(); content.Take(query.currentPageSize).Skip(query.currentPageNum * query.currentPageSize).ToList().ForEach(item => { result.page.pageItems.Add(new Entity { Key = item.FindValue("Id").ToSafeString(), Fields = item.ExpandoToNamed() }); }); } catch (Exception ex) { //HandleException(ex); } return(result); }
public void FillInFromTemplate(Guid tmplId) { if (ControlMode == SPControlMode.New && tmplId != Guid.Empty) { // Templates work ONLY on a NewForm try { var tmplRoster = new RosterDataService().ListSingleRosterEvent(TableIDs.TEMPLATE_ROSTERS, tmplId); if (tmplRoster != null) { var tmplRosterProps = tmplRoster.RosterEventDictionary; foreach (var rowItem in FieldControls) { if (!tmplRosterProps.ContainsKey(rowItem.Item3.InternalNameOriginal)) { continue; } rowItem.Item2.Value = tmplRosterProps[rowItem.Item3.InternalNameOriginal]; } } } catch (Exception ex) { ErrorHolder.Controls.Add(new Label() { Text = ex.Message, ForeColor = System.Drawing.Color.Red }); } } }
public listView <Entity> RosterEventList(string version, ICollection <abstractSearch> filter, QueryDisplayParams query) { DisableCaching(); var result = new listView <Entity>(); try { var listId = filter.filterTextValue("listId").ToGuid(); result.page = new pager <Entity>(); var service = new RosterDataService(); var content = service.ListRosterEvents(listId).ToList(); result.total = content.Count(); content.Take(query.currentPageSize).Skip(query.currentPageNum * query.currentPageSize).ToList().ForEach(item => { result.page.pageItems.Add(new Entity { Key = item.Id.ToSafeString(), Fields = item.RosterEventProperties.ExpandoToNamed() }); }); } catch (Exception ex) { result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; //HandleException(ex); } return(result); }
protected void btnLock_Click(object sender, EventArgs e) { try { var dataService = new RosterDataService(); { List <Tuple <int, string> > trusteeRights = new List <Tuple <int, string> >(); if (chNeedResetRights.Checked) { trusteeRights.AddRange(new [] { new Tuple <int, string>((int)AccessRight.Read, RoleService.ACCOUNT_ID_EVERYONE.ToString()), new Tuple <int, string>((int)AccessRight.Control, new RoleService().GetGroupIdForRole(Constants.Role.RosterAdmins, SPContext.Current.Web).ToString()) }); } dataService.WorkingLock( txtStoredProcName.Text, dtStart.SelectedDate, dtEnd.SelectedDate, trusteeRights, string.Format("{0} Locked at {1}. Locked by {2}. Lock period [{3} - {4}].", txtReason.Text, DateTime.Now.ToString(), SPContext.Current.Web.CurrentUser.Name, dtStart.SelectedDate.ToString(), dtEnd.SelectedDate.ToString())); } // close form Utils.GoBackOnSuccess(this, this.Context); } catch (Exception ex) { ErrorHolder.Controls.Add(new System.Web.UI.WebControls.Label { Text = ex.Message }); } }
public itemView <string> ExecuteAction(string version, ICollection <abstractSearch> filter) { DisableCaching(); var result = new itemView <string>(); try { var name = filter.filterTextValue("name"); var dataService = new RosterDataService(); { var paramCollection = !filter.Any() ? new List <Tuple <string, object> >() : filter.Select(item => new Tuple <string, object>(item.LabelText, (item as textSearch).searchTerm)).ToList(); var currentUserParam = paramCollection.FirstOrDefault(p => p.Item1.Equals("@currentUser")); if (currentUserParam != null) { paramCollection.Remove(currentUserParam); paramCollection.Add(new Tuple <string, object>("@currentUser", DbFieldUser.GetUserRosterId(SPContext.Current.Web.CurrentUser))); } result.item = dataService.ExecuteProcedure(name, paramCollection); } } catch (Exception ex) { result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; //HandleException(ex); } return(result); }
public ExecuteActionResult ExecuteAction(ExecuteActionQuery query) { DisableCaching(); var result = new ExecuteActionResult(); try { if (query == null) { throw new ArgumentNullException("query"); } var dataService = new RosterDataService(); { var paramCollection = query.Parameters == null ? new List <Tuple <string, object> >(): query.Parameters.Select(item => new Tuple <string, object>(item.Name, item.Value)).ToList(); var currentUserParam = paramCollection.FirstOrDefault(p => p.Item1.Equals("@currentUser")); if (currentUserParam != null) { // change :: sharepoint user id -> roster user id paramCollection.Remove(currentUserParam); paramCollection.Add(new Tuple <string, object>("@currentUser", DbFieldUser.GetUserRosterId(SPContext.Current.Web.CurrentUser))); } result.Message = dataService.ExecuteProcedure(query.Name, paramCollection); } } catch (Exception ex) { HandleException(ex); } return(result); }
public void SaveRosterAsTemplate(ItemDataQuery query) { DisableCaching(); try { // init source Roster var sourceRoster = new RosterDataService().ListSingleRosterEvent(query.ListId, query.ItemId); var sourceRosterProps = sourceRoster.RosterEventDictionary; // create empty Template Roster RosterDataService _dataService = new RosterDataService(); var newRosterTemplate = _dataService.CreateRosterEvent(Roster.Common.TableIDs.TEMPLATE_ROSTERS, (int)RosterEventType.TemplateRosterEvent); // fill template Roster properties var rosterTemplateFields = new RosterConfigService().GetList(Roster.Common.TableIDs.TEMPLATE_ROSTERS).ListMetadataFields; foreach (var field in rosterTemplateFields) { if (field.InternalName == FieldNames.ROSTER_EVENT_ID || field.InternalName == FieldNames.ID || !sourceRosterProps.ContainsKey(field.InternalName)) { continue; } newRosterTemplate.RosterEventDictionary[field.InternalName] = sourceRosterProps[field.InternalName]; } // save template Roster _dataService.SaveRosterEvent(newRosterTemplate, Roster.Common.TableIDs.TEMPLATE_ROSTERS); } catch (Exception ex) { HandleException(ex); } }
private List <RosterEvent> GetTimesheetsByStatus(int statusId) { var dataService = new RosterDataService(); var query = new QueryParams(); var listFields = new RosterConfigService().GetList(TableIDs.TIMESHEET_ROSTERS).ListMetadataFields; // add filter by WorkerId var workerFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.WORKER_PERSON_ID); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(workerFld, CompareType.Equal, ConcateOperator.And, this.WorkerId, null)); // add filter by StatusId var statusFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.STATUS_ID); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(statusFld, CompareType.Equal, ConcateOperator.And, statusId, null)); // add filter according period displayed by Calendar var calendarPeriod = Utils.GetCalendarViewPeriod(SPContext.Current.Web.GetDateOptions(Request), "week"); var startDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.START_DATE); var endDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.END_DATE); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(startDateFld, CompareType.LessOrEqual, ConcateOperator.And, calendarPeriod.Item2, null)); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, calendarPeriod.Item1, null)); // get timesheets return(dataService.ListRosterEvents(TableIDs.TIMESHEET_ROSTERS, query)); }
protected void btnBulkApprove_Click(object sender, EventArgs e) { if (this.IsApprovePossible()) { try { if (!IsCurrentUserAManagerForWorker()) { throw new Exception("Only Manager can approve timesheets for current user!"); } // get timesheets to APPROVE var timesheetRosters = this.GetTimesheetsByStatus(8); // 8 = 'Endorsed' // init StoredProcedure params var paramCollection = new List <Tuple <string, object> >(); paramCollection.Add(new Tuple <string, object>("@id", String.Join(",", timesheetRosters.Select(tsr => tsr.Id.ToString())))); paramCollection.Add(new Tuple <string, object>("@reason", string.Format("Bulk approve at {0}", DateTime.Now.ToString()))); paramCollection.Add(new Tuple <string, object>("@message", "")); string message = new RosterDataService().ExecuteProcedure("[dbo].[Approved]", paramCollection); txtNotification.Value = "Timesheets approved successfully"; } catch (Exception ex) { txtErrorMsg.Value = ex.Message; } } }
protected override void CreateChildControls() { base.CreateChildControls(); try { SPWeb web = SPContext.Current.Web; spCalendarHolidayView = new SPCalendarView(); spCalendarHolidayView.EnableViewState = true; spCalendarHolidayView.EnableV4Rendering = web.UIVersion >= 4; spCalendarHolidayView.NewItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=3"; spCalendarHolidayView.EditItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=2"; spCalendarHolidayView.DisplayItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=1"; string viewType = this.CalendarPeriod; string selectedDate = SPUtility.GetSelectedDate(Request, web); Tuple <DateTime, DateTime> calendarPeriod = Utils.GetCalendarViewPeriod(SPContext.Current.Web.GetDateOptions(Request), viewType); spCalendarHolidayView.ViewType = viewType; spCalendarHolidayView.SelectedDate = selectedDate; // Bind the datasource to the SPCalendarView var ds = new SPCalendarItemCollection(); short calendarType = web.RegionalSettings.CalendarType; var holidays = new RosterDataService().ListHolidayEvents().OrderBy(item => item.HolidayDate).ToList(); ds.AddRange(holidays.Select(item => new SPCalendarItem() { DisplayFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=1", CalendarType = calendarType, ItemID = item.Id.ToString(), StartDate = item.HolidayDate.Date, EndDate = item.HolidayDate.Date.AddSeconds(86400), hasEndDate = true, Title = item.Holiday.Name, Location = item.Holiday.HolidayType.Name, IsAllDayEvent = true, IsRecurrence = false }).ToList()); // data bind spCalendarHolidayView.DataSource = ds; spCalendarHolidayView.DataBind(); // add Calendar to page this.Controls.Add(spCalendarHolidayView); } catch (Exception ex) { Controls.Add(new Label() { Text = ex.Message, ForeColor = System.Drawing.Color.Red }); Controls.Add(new Label() { Text = " StackTrace: " + ex.StackTrace, ForeColor = System.Drawing.Color.Red }); } }
public ItemDataResult RosterItemData(ItemDataQuery query) { DisableCaching(); var result = new ItemDataResult { Props = new List <ItemDataElem> () }; try { var roster = new RosterDataService().ListSingleRosterEvent(query.ListId, query.ItemId); if (roster != null) { var origRosterProps = roster.RosterEventDictionary; foreach (string fldKey in origRosterProps.Keys) { bool isFilterByLookupId = false; object val = origRosterProps[fldKey]; string valAsStr = string.Empty; if (val is DateTime) { valAsStr = ((DateTime)val).ToString("yyyy-MM-dd"); } else if (val is Boolean) { valAsStr = (bool)val ? "1" : "0"; } else if (val is int) { valAsStr = ((int)val).ToString("N" + 13); } else { valAsStr = val.ToSafeString(); if (valAsStr.StartsWith("<Items>")) { valAsStr = string.Join(";#", valAsStr.XmlToList()); // choice values } // LookupId ? int dummy; isFilterByLookupId = val.ToSafeString().Split(',').Where(x => Int32.TryParse(x, out dummy)).Any(); } ((List <ItemDataElem>)result.Props).Add(new ItemDataElem { FieldName = fldKey, FieldValue = SPHttpUtility.UrlKeyValueEncode(valAsStr), FilterLookupId = isFilterByLookupId }); } } } catch (Exception ex) { HandleException(ex); } return(result); }
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!"); }
private static UserPickerEntity EnsureUser(UserPickerEntity entity, string listId, int listSource, string lookupKey) { if (entity.RosterLookupId != 0 && entity.IsResolved) { return(entity); } if (string.IsNullOrEmpty(entity.Key) && entity.RosterLookupId == 0) { throw new ArgumentException("To ensureUser please specify accountName OR rosterLookupId!"); } UserPickerEntity dbUser = null; List <Tuple <string, string> > whereCriteria = new List <Tuple <string, string> >(); if (!string.IsNullOrEmpty(entity.Key)) { whereCriteria.Add(new Tuple <string, string>(FieldNames.USER_LOGIN_NAME, entity.Key)); } else { whereCriteria.Add(new Tuple <string, string>(lookupKey, entity.RosterLookupId.ToString())); } var userFields = new[] { FieldNames.USER_LOGIN_NAME, FieldNames.USER_DISPLAY_NAME, FieldNames.USER_EMAIL, FieldNames.USER_SIP, FieldNames.USER_DEPARTMENT, FieldNames.USER_PRINCIPAL_TYPE }; var users = BLExtensions.SourceContent(listId, lookupKey, String.Join("$", userFields), listSource, whereCriteria); if (users == null || !users.Any()) { // add new user int newLookupId = new RosterDataService().SaveRow(lookupKey, listId, entity.ToSyncObject()); if (newLookupId == 0) { throw new Exception("Cannot add user to system table"); } else { dbUser = entity; dbUser.RosterLookupId = newLookupId; } } else { var user = users.First(); if (entity.IsResolved) { dbUser = entity; dbUser.RosterLookupId = user.Item1; } else { dbUser = new UserPickerEntity(user.Item1, user.Item2 as IDictionary <string, object>); } } return(dbUser); }
public RosterEventResult RosterEvents(RosterEventQuery query) { DisableCaching(); var result = new RosterEventResult { Page = query.Page, Items = new List <RosterEventResultItem>() }; try { var list = new RosterConfigService().GetList(query.ListId); if (list == null) { throw new Exception(string.Format("List '{0}' not found", query.ListId)); } var fieldId = list.ListMetadataFields.FirstOrDefault(item => item.InternalName == FieldNames.ROSTER_EVENT_ID); if (fieldId == null) { throw new Exception("Field 'RosterEventId' not found"); } var fieldTitle = list.ListMetadataFields.FirstOrDefault(item => item.InternalName == FieldNames.ROSTER_EVENT_TITLE); if (fieldTitle == null) { throw new Exception("Field 'Title' not found"); } result.Page = query.Page; var queryParams = new QueryParams { SkipRows = 0, TakeRows = PageSize }; queryParams.SelectCriteria.AddRange(new[] { fieldId, fieldTitle }); queryParams.OrderCriteria.Add(new Tuple <ListMetadataField, SortDirection, string> (fieldTitle, SortDirection.Ascending, fieldTitle.InternalName)); queryParams.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string> (fieldTitle, CompareType.Contains, ConcateOperator.And, query.Query, null)); var content = new RosterDataService().ListRosterEventProperties(list.Id, queryParams); foreach (var properties in content) { var id = properties.First(item => item.Key == fieldId.InternalName).Value; var value = properties.First(item => item.Key == fieldTitle.InternalName).Value; result.Items.Add(new RosterEventResultItem { id = id.ToSafeString(), text = value.ToSafeString() }); } } catch (Exception ex) { HandleException(ex); } return(result); }
public void SaveMasterAsTemplate(SaveAsTemplateQuery query) { DisableCaching(); try { // set flag IsTemplate for Master roster var _confService = new RosterConfigService(); var _dataService = new RosterDataService(); _dataService.SetAsTemplate(query.MasterId); // init filter by MasterRosterId var plannedRostersList = _confService.GetList(TableIDs.PLANNED_ROSTERS); var queryPar = new QueryParams(); var masterRosterFld = plannedRostersList.ListMetadataFields.FirstOrDefault(item => item.InternalName == FieldNames.MASTER_ROSTER_ID); queryPar.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(masterRosterFld, CompareType.Equal, ConcateOperator.And, query.MasterId, null)); // get Planned rosters by MasterRosterId var plannedRosters = _dataService.ListRosterEvents(plannedRostersList.Id, queryPar); // limit access to Planned rosters inside Template int rosterAdminGroupId = new RoleService().GetGroupIdForRole(Roster.Presentation.Constants.Role.RosterAdmins, SPContext.Current.Web); foreach (RosterEvent re in plannedRosters) { List <AccessControlItem> reRights = _confService.GetItemAccessControls(re.Id); // clear old if (reRights != null && reRights.Any()) { reRights.ForEach(ipItm => _confService.DeleteAccessControlItem(ipItm.Id)); } // add 'Edit' to RosterAdmins _confService.SaveAccessControlItem(new AccessControlItem { AccessRight = (int)AccessRight.Write, Id = Guid.NewGuid(), ItemId = re.Id, ListMetadataId = plannedRostersList.Id, TrusteeId = rosterAdminGroupId }); // add 'Read' to Everyone _confService.SaveAccessControlItem(new AccessControlItem { AccessRight = (int)AccessRight.Read, Id = Guid.NewGuid(), ItemId = re.Id, ListMetadataId = plannedRostersList.Id, TrusteeId = RoleService.ACCOUNT_ID_EVERYONE }); } } catch (Exception ex) { HandleException(ex); } }
public ListResult List(ListQuery query) { DisableCaching(); var result = new ListResult { Page = query.Page, Items = new List <ListResultItem>() }; try { var view = new RosterConfigService().GetView(query.ViewId); var field = view.ListMetadata.ListMetadataFields.FirstOrDefault(item => item.Id == query.FieldId); if (field == null) { throw new Exception(string.Format("Field {0} not found", query.FieldId)); } if (field.FieldType() == SPFieldType.Choice) { result.Items.AddRange(field.FieldValues().Where( item => item.Contains(query.Query)).Select(item => new ListResultItem { id = item, text = item }).ToList()); } else { result.Page = query.Page; var queryParams = new QueryParams { SkipRows = 0, TakeRows = 1, Dictinct = true }; queryParams.SelectCriteria.Add(field); queryParams.OrderCriteria.Add(new Tuple <ListMetadataField, SortDirection, string> (field, SortDirection.Ascending, query.DisplayField.ExtractField())); queryParams.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string> (field, CompareType.Contains, ConcateOperator.And, query.Query, query.DisplayField.ExtractField())); var content = new RosterDataService().ListRosterEventProperties(view.ListMetadataId, queryParams); foreach (var value in content.Select(properties => properties.First(item => item.Key == query.DisplayField).Value)) { result.Items.Add(new ListResultItem { id = value.ToSafeString(), text = value.ToSafeString() }); } } } catch (Exception ex) { HandleException(ex); } return(result); }
public static void SyncList(Guid listId) { var configProvider = new RosterConfigService(); var mappingSetting = configProvider.GetMappingByList(listId.ToString()); if (mappingSetting == null) { return; } var dataProvider = new RosterDataService(); { var list = SPContext.Current.SPList(listId); var listitems = list.ListItems(mappingSetting.Key, String.Join("$", mappingSetting.ListMappingFields.Select(item => item.ItemName).ToList()), true); dataProvider.SaveRows(mappingSetting, listitems); } }
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)); } }
private bool IsCurrentUserATeamLeaderForWorker() { 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)); List <Tuple <string, string> > whereCriteria = new List <Tuple <string, string> > { new Tuple <string, string>("Id", this.WorkerId.ToString()) }; var workersInfo = new RosterDataService().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() }); }); //return workersInfo.Any() && workersInfo.FirstOrDefault().TeamLeader.Equals(currentUserLogin); return(workersInfo.Any() && userLoginAndGroups.Contains(workersInfo.FirstOrDefault().TeamLeader)); }
public itemView <bool> DeleteRosterEventItem(string version, string id) { DisableCaching(); var result = new itemView <bool>(); try { var service = new RosterDataService(); service.DeleteRosterEvent(id.ToGuid()); result.item = true; } catch (Exception ex) { result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; //HandleException(ex); } return(result); }
public LookupFieldResult LookupField(LookupFieldQuery query) { DisableCaching(); var result = new LookupFieldResult { Page = query.Page, Items = new List <LookupFieldResultItem>() }; try { result.Page = query.Page; var queryTerm = query.Query.ToSafeString().ToLowerInvariant(); var field = (SPContext.Current.SPList(query.ListId.ToGuid()).FieldById(query.FieldId.ToGuid()) as RosterTableLookupField); if (field != null) { var content = new RosterDataService().TableContent(field.TableName, field.KeyName, field.FieldName). Where(i => i.Item2.ToSeparatedString().ToLowerInvariant().Contains(queryTerm)).OrderBy(e => e.Item2.ToSeparatedString()); content.Take(PageSize).Skip(PageSize * result.Page).ToList().ForEach(item => { var resultItem = new LookupFieldResultItem { id = item.Item1, name = item.Item2.FirstValue(), }; ((List <LookupFieldResultItem>)result.Items).Add(resultItem); }); } } catch (SqlException ex) { if (!ex.Message.Contains("Conversion failed")) { HandleException(ex); } } catch (Exception ex) { HandleException(ex); } return(result); }
public itemView <Entity> CreateRosterEventItem(string version, string listId, int eventTypeId) { DisableCaching(); var result = new itemView <Entity>(); try { result.item = new Entity(); var service = new RosterDataService(); var content = service.CreateRosterEvent(listId.ToGuid(), eventTypeId); result.item.Key = content.Id.ToSafeString(); result.item.Fields = content.RosterEventProperties.ExpandoToNamed(); } catch (Exception ex) { result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; //HandleException(ex); } return(result); }
public static List <Tuple <int, ExpandoObject> > SourceContent(string source, string key, string fields, int type, List <Tuple <string, string> > whereCriteria = null) { List <Tuple <int, ExpandoObject> > itemCollection = null; switch (type) { case (int)LookupSourceType.SpList: { itemCollection = SPContext.Current.SPList(source.ToGuid()).ListItemsByCriteria(key, fields, false, whereCriteria); break; } case (int)LookupSourceType.Table: case (int)LookupSourceType.Query: { itemCollection = new RosterDataService().TableContent(source, key, fields, whereCriteria); break; } } return(itemCollection); }
public override void ItemUpdated(SPItemEventProperties properties) { base.ItemUpdated(properties); try { var configProvider = new RosterConfigService(properties.Web); var mappingSetting = configProvider.GetMappingByList(properties.ListId.ToString()); if (mappingSetting == null) { return; } var dataProvider = new RosterDataService(properties.Web); { dataProvider.SaveRow(mappingSetting, properties.ListItem.ToSyncObject(mappingSetting)); } } catch (Exception ex) { LogHelper.Instance.ErrorULS("ItemUpdated error", ex); } }
public override void ItemDeleting(SPItemEventProperties properties) { base.ItemDeleting(properties); try { var configProvider = new RosterConfigService(properties.Web); var mappingSetting = configProvider.GetMappingByList(properties.ListId.ToString()); if (mappingSetting == null) { return; } var dataProvider = new RosterDataService(properties.Web); { dataProvider.Delete(mappingSetting.TableName, mappingSetting.Key, properties.ListItemId); } } catch (Exception ex) { LogHelper.Instance.ErrorULS("ItemDeleting error", ex); } }
public GetContentTypeResult GetContentTypeByRosterId(GetContentTypeQuery query) { DisableCaching(); var result = new GetContentTypeResult(); try { var dataService = new RosterDataService(); { var roster = dataService.GetRosterEvent(query.RosterId); if (roster != null) { var rosterProps = roster.RosterEventDictionary; if (rosterProps.ContainsKey(FieldNames.CONTENT_TYPE_ID)) { int ctId = rosterProps[FieldNames.CONTENT_TYPE_ID].ToInt(); var ct = new RosterConfigService().GetContentType(ctId); if (ct != null) { result.DispItemUrl = ct.DispItemUrl; result.EditItemUrl = ct.EditItemUrl; result.NewItemUrl = ct.NewItemUrl; result.Name = ct.Name; result.Id = ct.Id; result.IsDefault = ct.IsDefault; result.IsOnNewAction = ct.IsOnNewAction; } } } } } catch (Exception ex) { HandleException(ex); } return(result); }
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"); }
public void SaveRosterItemData(SaveItemDataQuery query) { DisableCaching(); try { if (query == null) { throw new ArgumentNullException("query"); } var rosterConfigService = new RosterConfigService(); if (!rosterConfigService.HasRights(query.ItemId, query.ListId, AccessRight.Write)) { throw new Exception("You don't have permissions to modify current roster"); } var rosterDataService = new RosterDataService(); rosterDataService.SaveRosterEventItem(query.ListId, query.ItemId, query.FieldName, query.Value); } catch (Exception ex) { HandleException(ex); } }
protected void btnBulkSendToNAV_Click(object sender, EventArgs e) { try { var config = SPContext.Current.GetNavWebServiceConnection(); if (config.IsEmpty()) { throw new Exception("NAV connection info has not been specified!"); } if (!IsCurrentUserAManagerForWorker()) { throw new Exception("Only Manager can Send timesheets to NAV for current user!"); } // get timesheets to Send to NAV var approvedRosters = this.GetTimesheetsByStatus(10); // 10 = 'Approved' if (!approvedRosters.Any()) { throw new Exception("There is nothing to send to NAV"); } // get mapping var _mappingSettings = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <List <Roster.Presentation.Layouts.MapElem> >(config.Mapping); var calendarPeriod = Utils.GetCalendarViewPeriod(SPContext.Current.Web.GetDateOptions(Request), "week"); var listDbFields = new RosterConfigService().GetList(TableIDs.TIMESHEET_ROSTERS).ListMetadataFields.Select(fld => fld.GetDbField()); // init Servicea CreateTimeSheetLines_Service srv = new CreateTimeSheetLines_Service(); srv.Url = config.CreateTimesheetUrl; srv.Credentials = new NetworkCredential(config.User, config.Password); ProcessTimeSheets procSrv = new ProcessTimeSheets(); procSrv.Url = config.ProcessTimesheetsUrl; procSrv.Credentials = new NetworkCredential(config.User, config.Password); Dictionary <Guid, string> errors = new Dictionary <Guid, string>(); List <Guid> successIDs = new List <Guid>(); foreach (var roster in approvedRosters) { string batchNo = Guid.NewGuid().ToString("N").Substring(0, 20); try { var newLine = new CreateTimeSheetLines(); // generic values newLine.Key = "0"; newLine.External_Time_Sheet_No = batchNo; newLine.Time_Sheet_Starting_Date = calendarPeriod.Item1.Date; newLine.Time_Sheet_Starting_DateSpecified = true; // fill Line from timesheet roster newLine.FillFromRoster(roster, listDbFields, _mappingSettings); // create entry in NAV temp table srv.Create(ref newLine); // process timesheet entry procSrv.ProcessTimeSheet(batchNo, false); successIDs.Add(roster.Id); } catch (Exception ex) { errors.Add(roster.Id, ex.Message); } } // init StoredProcedure params var paramCollection = new List <Tuple <string, object> >(); paramCollection.Add(new Tuple <string, object>("@id", String.Join(",", successIDs))); paramCollection.Add(new Tuple <string, object>("@reason", string.Format("Bulk submit to NAV at {0}", DateTime.Now.ToString()))); paramCollection.Add(new Tuple <string, object>("@message", "")); // set new STATUS string message = new RosterDataService().ExecuteProcedure("[dbo].[SubmitedToNAV]", paramCollection); if (errors.Any()) { throw new Exception(String.Join("<br/>", errors.Select(er => string.Format("Error submitting roster '{0}': {1}", er.Key, er.Value)))); } txtNotification.Value = "Success"; } catch (Exception ex) { txtErrorMsg.Value = ex.Message; } }