public List <DepartmentGroupMember> GetAllMembersForGroupAndChildGroups(DepartmentGroup group) { var result = new List <DepartmentGroupMember>(); if (group != null && group.Members.Any()) { result.AddRange(group.Members); } if (group != null && group.Children != null && group.Children.Any()) { foreach (var child in group.Children) { result.AddRange(GetAllMembersForGroupAndChildGroups(child)); } } return(result); }
// GET: DepartmentGroups/Details/5 public ActionResult Details(int?id) { if (Session["ADMIN"] != null || Session["ADMIN"].ToString() == "admin") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DepartmentGroup departmentGroup = db.DepartmentGroup.Find(id); if (departmentGroup == null) { return(HttpNotFound()); } return(View(departmentGroup)); } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Edit([Bind(Include = "Id,Code,Name,CreatedBy,CreateDate,UpdatedBy,UpdateDate,Status")] DepartmentGroup departmentGroup) { if (Session["ADMIN"] != null || Session["ADMIN"].ToString() == "admin") { departmentGroup.UpdatedBy = Convert.ToInt32(Session["ADMINID"]); departmentGroup.UpdateDate = DateTime.Now; if (ModelState.IsValid) { db.Entry(departmentGroup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CreatedBy = new SelectList(db.Employee, "Id", "Code", departmentGroup.CreatedBy); ViewBag.UpdatedBy = new SelectList(db.Employee, "Id", "Code", departmentGroup.UpdatedBy); return(View(departmentGroup)); } else { return(RedirectToAction("Login", "Account")); } }
// GET: DepartmentGroups/Edit/5 public ActionResult Edit(int?id) { if (Session["ADMIN"] != null || Session["ADMIN"].ToString() == "admin") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DepartmentGroup departmentGroup = db.DepartmentGroup.Find(id); if (departmentGroup == null) { return(HttpNotFound()); } ViewBag.CreatedBy = new SelectList(db.Employee, "Id", "Code", departmentGroup.CreatedBy); ViewBag.UpdatedBy = new SelectList(db.Employee, "Id", "Code", departmentGroup.UpdatedBy); return(View(departmentGroup)); } else { return(RedirectToAction("Login", "Account")); } }
public void Handle(RegisterNewDepartmentGroupCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } var department = DepartmentGroup.Create(message.Code, message.Description); if (_departmentRepository.GetByDescription(department.Description) != null) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "The Department Group Description has already been taken.")); return; } _departmentRepository.Add(department); if (Commit()) { Bus.RaiseEvent(new DepartmentGroupRegisteredEvent(department.Code, department.Description)); } }
public CoreDataResult GetCoreData() { var results = new CoreDataResult(); results.Personnel = new List <PersonnelInfoResult>(); results.Groups = new List <GroupInfoResult>(); results.Units = new List <UnitInfoResult>(); results.Roles = new List <RoleInfoResult>(); results.Statuses = new List <CustomStatusesResult>(); results.Priorities = new List <CallPriorityResult>(); results.Departments = new List <JoinedDepartmentResult>(); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); var allRoles = _personnelRolesService.GetRolesForDepartment(DepartmentId); var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId); var allGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitTypes = _unitsService.GetUnitTypesForDepartment(DepartmentId); var callPriorites = _callsService.GetCallPrioritesForDepartment(DepartmentId); foreach (var user in users) { UserProfile profile = null; if (allProfiles.ContainsKey(user.UserId)) { profile = allProfiles[user.UserId]; } DepartmentGroup group = null; if (groups.ContainsKey(user.UserId)) { group = groups[user.UserId]; } List <PersonnelRole> roles = null; if (rolesForUsersInDepartment.ContainsKey(user.UserId)) { roles = rolesForUsersInDepartment[user.UserId]; } var result = new PersonnelInfoResult(); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknown"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } if (user != null) { result.Eml = user.Email; } result.Did = DepartmentId; result.Uid = user.UserId.ToString(); if (group != null) { result.Gid = group.DepartmentGroupId; result.Gnm = group.Name; } result.Roles = new List <string>(); if (roles != null && roles.Count > 0) { foreach (var role in roles) { if (role != null) { result.Roles.Add(role.Name); } } } results.Personnel.Add(result); } results.Rights = new DepartmentRightsResult(); var currentUser = _usersService.GetUserByName(UserName); if (currentUser == null) { throw HttpStatusCode.Unauthorized.AsException(); } var department = _departmentsService.GetDepartmentById(DepartmentId, false); results.Rights.Adm = department.IsUserAnAdmin(currentUser.UserId); results.Rights.Grps = new List <GroupRight>(); var currentGroup = _departmentGroupsService.GetGroupForUser(currentUser.UserId, DepartmentId); if (currentGroup != null) { var groupRight = new GroupRight(); groupRight.Gid = currentGroup.DepartmentGroupId; groupRight.Adm = currentGroup.IsUserGroupAdmin(currentUser.UserId); results.Rights.Grps.Add(groupRight); } foreach (var group in allGroups) { var groupInfo = new GroupInfoResult(); groupInfo.Gid = group.DepartmentGroupId; groupInfo.Nme = group.Name; if (group.Type.HasValue) { groupInfo.Typ = group.Type.Value; } if (group.Address != null) { groupInfo.Add = group.Address.FormatAddress(); } results.Groups.Add(groupInfo); } foreach (var unit in units) { var unitResult = new UnitInfoResult(); unitResult.Uid = unit.UnitId; unitResult.Did = DepartmentId; unitResult.Nme = unit.Name; unitResult.Typ = unit.Type; if (!string.IsNullOrWhiteSpace(unit.Type)) { var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type); if (unitType != null) { unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault(); } } else { unitResult.Cid = 0; } if (unit.StationGroup != null) { unitResult.Sid = unit.StationGroup.DepartmentGroupId; unitResult.Snm = unit.StationGroup.Name; } results.Units.Add(unitResult); } foreach (var role in allRoles) { var roleResult = new RoleInfoResult(); roleResult.Rid = role.PersonnelRoleId; roleResult.Nme = role.Name; results.Roles.Add(roleResult); } var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(DepartmentId); foreach (var customState in customStates) { if (customState != null) { if (customState.IsDeleted || customState.Details == null) { continue; } foreach (var stateDetail in customState.Details) { if (stateDetail == null || stateDetail.IsDeleted) { continue; } var customStateResult = new CustomStatusesResult(); customStateResult.Id = stateDetail.CustomStateDetailId; customStateResult.Type = customState.Type; customStateResult.StateId = stateDetail.CustomStateId; customStateResult.Text = stateDetail.ButtonText; customStateResult.BColor = stateDetail.ButtonColor; customStateResult.Color = stateDetail.TextColor; customStateResult.Gps = stateDetail.GpsRequired; customStateResult.Note = stateDetail.NoteType; customStateResult.Detail = stateDetail.DetailType; if (customState.IsDeleted) { customStateResult.IsDeleted = true; } else { customStateResult.IsDeleted = stateDetail.IsDeleted; } results.Statuses.Add(customStateResult); } } } foreach (var priority in callPriorites) { var priorityResult = new CallPriorityResult(); priorityResult.Id = priority.DepartmentCallPriorityId; priorityResult.DepartmentId = priority.DepartmentId; priorityResult.Name = priority.Name; priorityResult.Color = priority.Color; priorityResult.Sort = priority.Sort; priorityResult.IsDeleted = priority.IsDeleted; priorityResult.IsDefault = priority.IsDefault; results.Priorities.Add(priorityResult); } var members = _departmentsService.GetAllDepartmentsForUser(UserId); foreach (var member in members) { if (member.IsDeleted) { continue; } if (member.IsDisabled.GetValueOrDefault()) { continue; } var depRest = new JoinedDepartmentResult(); depRest.Did = member.DepartmentId; depRest.Nme = member.Department.Name; results.Departments.Add(depRest); } return(results); }
public static PersonnelViewModel Create(string name, ActionLog actionLog, UserState userState, Department department, DepartmentGroup respondingToDepartment, DepartmentGroup group, List <PersonnelRole> roles, string callNumber) { DateTime updateDate = TimeConverterHelper.TimeConverter(DateTime.UtcNow, department); string status = ""; string statusCss = ""; string state = ""; string stateCss = ""; string stateStyle = ""; string statusStyle = ""; double?latitude = null; double?longitude = null; int statusValue = 0; double eta = 0; int destinationType = 0; if (userState != null) { if (userState.State <= 25) { if (userState.State == 0) { state = "Available"; stateCss = "label-default"; } else if (userState.State == 1) { state = "Delayed"; stateCss = "label-warning"; } else if (userState.State == 2) { state = "Unavailable"; stateCss = "label-danger"; } else if (userState.State == 3) { state = "Committed"; stateCss = "label-info"; } else if (userState.State == 4) { state = "On Shift"; stateCss = "label-info"; } } else { var customState = CustomStatesHelper.GetCustomState(department.DepartmentId, userState.State); if (customState != null) { state = customState.ButtonText; stateCss = "label-default"; stateStyle = string.Format("color:{0};background-color:{1};", customState.TextColor, customState.ButtonColor); } else { state = "Unknown"; stateCss = "label-default"; } } } else { state = "Available"; stateCss = "label-default"; } if (actionLog == null) { status = "Standing By"; statusCss = "label-default"; } else { updateDate = TimeConverterHelper.TimeConverter(actionLog.Timestamp, department); eta = actionLog.Eta; destinationType = actionLog.DestinationType.GetValueOrDefault(); statusValue = actionLog.ActionTypeId; if (actionLog.ActionTypeId <= 25) { if (actionLog.ActionTypeId == 1) { status = "Not Responding"; statusCss = "label-danger"; } else if (actionLog.ActionTypeId == 2) { status = "Responding"; statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } } else if (actionLog.ActionTypeId == 0) { status = "Standing By"; statusCss = "label-default"; } else if (actionLog.ActionTypeId == 3) { status = "On Scene"; statusCss = "label-inverse"; } else if (actionLog.ActionTypeId == 4) { if (respondingToDepartment == null) { status = "Available Station"; } else { status = string.Format("Available at {0}", respondingToDepartment.Name); } statusCss = "label-default"; } else if (actionLog.ActionTypeId == 5) { statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } if (respondingToDepartment == null) { status = "Responding to Station"; } else { status = string.Format("Responding to {0}", respondingToDepartment.Name); } } else if (actionLog.ActionTypeId == 6) { statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } if (!actionLog.DestinationId.HasValue) { status = "Responding to Call"; } else { if (!String.IsNullOrWhiteSpace(callNumber)) { status = string.Format("Responding to Call {0}", callNumber); } else { status = string.Format("Responding to Call {0}", actionLog.DestinationId); } } } } else { var customStatus = CustomStatesHelper.GetCustomState(department.DepartmentId, actionLog.ActionTypeId); if (customStatus != null) { status = customStatus.ButtonText; statusCss = "label-default"; statusStyle = string.Format("color:{0};background-color:{1};", customStatus.TextColor, customStatus.ButtonColor); if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } } else { status = "Unknown"; statusCss = "label-default"; } } } string groupName = ""; int groupId = 0; if (group != null) { groupName = group.Name; groupId = group.DepartmentGroupId; } var newRoles = new StringBuilder(); foreach (var role in roles) { if (newRoles.Length > 0) { newRoles.Append(", " + role.Name); } else { newRoles.Append(role.Name); } } return(new PersonnelViewModel { Name = name, Status = status, StatusCss = statusCss, State = state, StateCss = stateCss, UpdatedDate = updateDate, Group = groupName, Roles = newRoles.ToString(), GroupId = groupId, StateStyle = stateStyle, StatusStyle = statusStyle, Latitude = latitude, Longitude = longitude, StatusValue = statusValue, Eta = eta, DestinationType = destinationType }); }
public static void ProcessCallQueueItem(CallQueueItem cqi) { ICommunicationService _communicationService; ICallsService _callsService; try { if (cqi != null && cqi.Call != null && cqi.Call.HasAnyDispatches()) { _communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>(); _callsService = Bootstrapper.GetKernel().Resolve <ICallsService>(); List <int> groupIds = new List <int>(); /* Trying to see if I can eek out a little perf here now that profiles are in Redis. Previously the * the parallel operation would cause EF errors. This shouldn't be the case now because profiles are * cached and GetProfileForUser operations will hit that first. */ if (cqi.Profiles == null || !cqi.Profiles.Any()) { var userProfilesService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); cqi.Profiles = userProfilesService.GetAllProfilesForDepartment(cqi.Call.DepartmentId).Select(x => x.Value).ToList(); } if (cqi.CallDispatchAttachmentId > 0) { //var callsService = Bootstrapper.GetKernel().Resolve<ICallsService>(); cqi.Call.ShortenedAudioUrl = _callsService.GetShortenedAudioUrl(cqi.Call.CallId, cqi.CallDispatchAttachmentId); } cqi.Call.ShortenedCallUrl = _callsService.GetShortenedCallLinkUrl(cqi.Call.CallId); try { cqi.Call.CallPriority = _callsService.GetCallPrioritesById(cqi.Call.DepartmentId, cqi.Call.Priority, false); } catch { /* Doesn't matter */ } var dispatchedUsers = new HashSet <string>(); // Dispatch Personnel if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any()) { foreach (var d in cqi.Call.Dispatches) { dispatchedUsers.Add(d.UserId); } Parallel.ForEach(cqi.Call.Dispatches, d => { try { var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == d.UserId); if (profile != null) { _communicationService.SendCall(cqi.Call, d, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address); } } catch (SocketException sex) { } }); } var departmentGroupsService = Bootstrapper.GetKernel().Resolve <IDepartmentGroupsService>(); // Dispatch Groups if (cqi.Call.GroupDispatches != null && cqi.Call.GroupDispatches.Any()) { foreach (var d in cqi.Call.GroupDispatches) { if (!groupIds.Contains(d.DepartmentGroupId)) { groupIds.Add(d.DepartmentGroupId); } var members = departmentGroupsService.GetAllMembersForGroup(d.DepartmentGroupId); foreach (var member in members) { if (!dispatchedUsers.Contains(member.UserId)) { dispatchedUsers.Add(member.UserId); try { var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId); _communicationService.SendCall(cqi.Call, new CallDispatch() { UserId = member.UserId }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address); } catch (SocketException sex) { } catch (Exception ex) { Logging.LogException(ex); } } } } } // Dispatch Units if (cqi.Call.UnitDispatches != null && cqi.Call.UnitDispatches.Any()) { var unitsService = Bootstrapper.GetKernel().Resolve <IUnitsService>(); foreach (var d in cqi.Call.UnitDispatches) { var unit = unitsService.GetUnitById(d.UnitId); if (unit != null && unit.StationGroupId.HasValue) { if (!groupIds.Contains(unit.StationGroupId.Value)) { groupIds.Add(unit.StationGroupId.Value); } } _communicationService.SendUnitCall(cqi.Call, d, cqi.DepartmentTextNumber, cqi.Address); var unitAssignedMembers = unitsService.GetCurrentRolesForUnit(d.UnitId); if (unitAssignedMembers != null && unitAssignedMembers.Count() > 0) { foreach (var member in unitAssignedMembers) { if (!dispatchedUsers.Contains(member.UserId)) { dispatchedUsers.Add(member.UserId); try { var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId); _communicationService.SendCall(cqi.Call, new CallDispatch() { UserId = member.UserId }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address); } catch (SocketException sex) { } catch (Exception ex) { Logging.LogException(ex); } } } } else { if (unit.StationGroupId.HasValue) { var members = departmentGroupsService.GetAllMembersForGroup(unit.StationGroupId.Value); foreach (var member in members) { if (!dispatchedUsers.Contains(member.UserId)) { dispatchedUsers.Add(member.UserId); try { var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId); _communicationService.SendCall(cqi.Call, new CallDispatch() { UserId = member.UserId }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address); } catch (SocketException sex) { } catch (Exception ex) { Logging.LogException(ex); } } } } } } } // Dispatch Roles if (cqi.Call.RoleDispatches != null && cqi.Call.RoleDispatches.Any()) { var rolesService = Bootstrapper.GetKernel().Resolve <IPersonnelRolesService>(); foreach (var d in cqi.Call.RoleDispatches) { var members = rolesService.GetAllMembersOfRole(d.RoleId); foreach (var member in members) { if (!dispatchedUsers.Contains(member.UserId)) { dispatchedUsers.Add(member.UserId); try { var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId); _communicationService.SendCall(cqi.Call, new CallDispatch() { UserId = member.UserId }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address); } catch (SocketException sex) { } catch (Exception ex) { Logging.LogException(ex); } } } } } // Send Call Print to Printer var printerProvider = Bootstrapper.GetKernel().Resolve <IPrinterProvider>(); Dictionary <int, DepartmentGroup> fetchedGroups = new Dictionary <int, DepartmentGroup>(); if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any()) { foreach (var d in cqi.Call.Dispatches) { var group = departmentGroupsService.GetGroupForUser(d.UserId, cqi.Call.DepartmentId); if (group != null) { if (!groupIds.Contains(group.DepartmentGroupId)) { groupIds.Add(group.DepartmentGroupId); } if (!fetchedGroups.ContainsKey(group.DepartmentGroupId)) { fetchedGroups.Add(group.DepartmentGroupId, group); } } } } foreach (var groupId in groupIds) { try { DepartmentGroup group = null; if (fetchedGroups.ContainsKey(groupId)) { group = fetchedGroups[groupId]; } else { group = departmentGroupsService.GetGroupById(groupId); } if (!String.IsNullOrWhiteSpace(group.PrinterData) && group.DispatchToPrinter) { var printerData = JsonConvert.DeserializeObject <DepartmentGroupPrinter>(group.PrinterData); var apiKey = SymmetricEncryption.Decrypt(printerData.ApiKey, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase); var callUrl = _callsService.GetShortenedCallPdfUrl(cqi.Call.CallId, true, groupId); var printJob = printerProvider.SubmitPrintJob(apiKey, printerData.PrinterId, "CallPrint", callUrl); } } catch (Exception ex) { Logging.LogException(ex); } } } } finally { _communicationService = null; } }
public DepartmentGroupsModel() { NewGroup = new DepartmentGroup(); NewGroup.Type = 1; ModalCssClass = "hide"; }
public static void Initialize(DepartmentsContext cntxt) { if (!cntxt.DepartmentGroups.Any()) { var dg = DepartmentGroup.Create("MIS", "Miscellaneous"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("LAU", "Laundry"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("ROR", "Room Revenue"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("F&B", "Food & Beverage"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("SAF", "SAF Group"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("ADJ", "Adjustment (+)"); cntxt.DepartmentGroups.Add(dg); dg = DepartmentGroup.Create("TAX", "Taxes "); cntxt.DepartmentGroups.Add(dg); cntxt.SaveChanges(); } if (!cntxt.Departments.Any()) { var mis = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "MIS"); var lau = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "LAU"); var ror = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "ROR"); var fb = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "F&B"); var saf = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "ADJ"); var tax = cntxt.DepartmentGroups.SingleOrDefault(l => l.Code == "TAX"); var d = Department.Create(Guid.NewGuid().ToString(), lau, DepartmentType.Debit, "Laundry", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Minibar", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Upgrade Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Collect Call", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Lunch ", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Extra Bed", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), tax, DepartmentType.Debit, "Room VAT", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "La Tasca F&B", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Pool Bar F&B", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Room Service F&B", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Dinner ", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Transfer Debit (DO NOT USE !)", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Room Discount", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Child in Bed with Parents", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room No Show", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Day Use", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Early Check-out", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Cancellation Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Upgrade Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), tax, DepartmentType.Debit, "Provincial Room Tax", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room No Show", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Day Use", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Cancellation Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Fino F&B", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Credit, "La Tasca Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Room Service Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Credit, "Pool Bar Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Early Check-out", false, 10, 0); cntxt.Departments.Add(d); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Late Check-in", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Lime Bar F&B", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Credit, "Lime Bar Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Correction ", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Tips", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Breakfast", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Halfboard Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "Fullboard Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), fb, DepartmentType.Debit, "All Inclusive Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Local Call", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Long Distance Call", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Oversea Call", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Fax", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Internet ", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Gala Dinner Christmas Eve", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Gala Dinner New Year Eve", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Special F&B Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Activities & Sport Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Wedding Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Meeting Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Spa Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Debit, "Transportation Package Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Airport Transfer", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Shuttle Bus", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Taxi Service & Transfer", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Excursion Tours", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Photocopy", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Meeting Equipment Rental", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "In Room Entertain Rental", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Gifts & Souvenir", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Spa Treatment/Service", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Outdoor Massage & Beauty", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Visitor/Joiner Register", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Doctor Visit Service", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Car/Bike Rental", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Golf Green Fee", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Missing or Broken Hotel Asset", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Pay Movie Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Other Miscellaneous Charge", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Credit, "MIS Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), saf, DepartmentType.Credit, "SAF Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Play & Chat", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Room Extra Teen (12-17 yrs)", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Minimarket", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Welcome Package", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Credit, "Minimarket Rebate", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Bambino Package", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Baby Cot", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Trolley TCNE (Weekly)", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Extra Adult (18 over)", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Trolley (Daily)", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Extra Bed", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Child in Bed", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Credit, "Rebate Room Discount", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), mis, DepartmentType.Debit, "Welcome Package", false, 10, 0); cntxt.Departments.Add(d); d = Department.Create(Guid.NewGuid().ToString(), ror, DepartmentType.Debit, "Room Extra Child (Under 12)", false, 10, 0); cntxt.Departments.Add(d); cntxt.SaveChanges(); } if (!cntxt.FolioPatterns.Any()) { var f = FolioPattern.Create("BAR", "Barter"); cntxt.FolioPatterns.Add(f); f = FolioPattern.Create("VOU", "Gift Voucher"); cntxt.FolioPatterns.Add(f); f = FolioPattern.Create("COR", "Corporate"); cntxt.FolioPatterns.Add(f); f = FolioPattern.Create("OWN", "Pay direct hotel"); cntxt.FolioPatterns.Add(f); f = FolioPattern.Create("AGT", "Agent Account"); cntxt.FolioPatterns.Add(f); cntxt.SaveChanges(); } }
public async Task <IActionResult> EditUserProfile(EditProfileModel model, IFormCollection form, CancellationToken cancellationToken) { if (!await _authorizationService.CanUserEditProfileAsync(UserId, DepartmentId, model.UserId)) { Unauthorized(); } model.User = _usersService.GetUserById(model.UserId); //model.PushUris = await _pushUriService.GetPushUrisByUserId(model.UserId); model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); model.CanEnableVoice = await _limitsService.CanDepartmentUseVoiceAsync(DepartmentId); var groups = new List <DepartmentGroup>(); var defaultGroup = new DepartmentGroup(); defaultGroup.Name = "No Group"; groups.Add(defaultGroup); groups.AddRange(await _departmentGroupsService.GetAllGroupsForDepartmentAsync(model.Department.DepartmentId)); model.Groups = new SelectList(groups, "DepartmentGroupId", "Name"); ViewBag.Carriers = model.Carrier.ToSelectList(); ViewBag.Countries = new SelectList(Countries.CountryNames); ViewBag.TimeZones = new SelectList(TimeZones.Zones, "Key", "Value"); if (!String.IsNullOrEmpty(model.Profile.MobileNumber)) { if (model.Carrier == MobileCarriers.None) { ModelState.AddModelError("Carrier", "If you entered a mobile phone, you need to select your mobile carrier. If you carrier is not listed select one and contact us to have your carrier added."); } else { if (model.Carrier == MobileCarriers.VirginMobileUk && !model.Profile.MobileNumber.StartsWith("0")) { ModelState.AddModelError("Profile.MobileNumber", "Virgin Mobile Uk requires your phone number to start with 0."); } if (model.Carrier == MobileCarriers.O2 && !model.Profile.MobileNumber.StartsWith("44")) { ModelState.AddModelError("Profile.MobileNumber", "O2 requires your phone number to start with 44."); } if (model.Carrier == MobileCarriers.Orange && !model.Profile.MobileNumber.StartsWith("0")) { ModelState.AddModelError("Profile.MobileNumber", "Orange requires your phone number to start with 0."); } if (model.Carrier == MobileCarriers.TMobileUk && !model.Profile.MobileNumber.StartsWith("0")) { ModelState.AddModelError("Profile.MobileNumber", "T-Mobile Uk requires your phone number to start with 0."); } if (model.Carrier == MobileCarriers.Vodafone && !model.Profile.MobileNumber.StartsWith("0")) { ModelState.AddModelError("Profile.MobileNumber", "Vodafone requires your phone number to start with 0."); } } } if ((model.Profile.SendSms || model.Profile.SendMessageSms || model.Profile.SendMessageSms) && String.IsNullOrEmpty(model.Profile.MobileNumber)) { ModelState.AddModelError("Profile.MobileNumber", "You have selected you want SMS/Text notifications but have not supplied a mobile number."); } // They specified a street address for physical if (!String.IsNullOrWhiteSpace(model.PhysicalAddress1)) { if (String.IsNullOrEmpty(model.PhysicalCity)) { ModelState.AddModelError("City", string.Format("The Physical City field is required")); } if (String.IsNullOrEmpty(model.PhysicalCountry)) { ModelState.AddModelError("Country", string.Format("The Physical Country field is required")); } if (String.IsNullOrEmpty(model.PhysicalPostalCode)) { ModelState.AddModelError("PostalCode", string.Format("The Physical Postal Code field is required")); } if (String.IsNullOrEmpty(model.PhysicalState)) { ModelState.AddModelError("State", string.Format("The Physical State/Provence field is required")); } } if (!String.IsNullOrWhiteSpace(model.MailingAddress1) && !model.MailingAddressSameAsPhysical) { if (String.IsNullOrEmpty(model.MailingCity)) { ModelState.AddModelError("City", string.Format("The Mailing City field is required")); } if (String.IsNullOrEmpty(model.MailingCountry)) { ModelState.AddModelError("Country", string.Format("The Mailing Country field is required")); } if (String.IsNullOrEmpty(model.MailingPostalCode)) { ModelState.AddModelError("PostalCode", string.Format("The Mailing Postal Code field is required")); } if (String.IsNullOrEmpty(model.MailingState)) { ModelState.AddModelError("State", string.Format("The Mailing State/Provence field is required")); } } if (model.User.Email != model.Email) { var currentEmail = _usersService.GetUserByEmail(model.Email); if (currentEmail != null && currentEmail.Id != model.User.UserId.ToString()) { ModelState.AddModelError("Email", "Email Address Already in Use. Please use another one."); } } if (model.Profile.VoiceForCall) { if (model.Profile.VoiceCallHome && String.IsNullOrWhiteSpace(model.Profile.HomeNumber)) { ModelState.AddModelError("VoiceForCall", "You selected to Enable Telephone alerting for your home phone number but have not supplied a home phone number. Please supply one."); } if (model.Profile.VoiceCallMobile && String.IsNullOrWhiteSpace(model.Profile.MobileNumber)) { ModelState.AddModelError("VoiceForCall", "You selected to Enable Telephone alerting for your mobile phone number but have not supplied a mobile phone number. Please supply one."); } if (!model.Profile.VoiceCallHome && !model.Profile.VoiceCallMobile) { ModelState.AddModelError("VoiceForCall", "You selected to Enable Telephone alerting, but you didn't select a number to call you at. Please select either/both home phone or mobile phone."); } } if (model.IsOwnProfile) { bool checkPasswordSuccess = false; if (string.IsNullOrEmpty(model.OldPassword) == false && string.IsNullOrEmpty(model.NewPassword) == false) { try { checkPasswordSuccess = await _userManager.CheckPasswordAsync(model.User, model.OldPassword); } catch (Exception) { checkPasswordSuccess = false; } if (!checkPasswordSuccess) { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } if (!String.IsNullOrWhiteSpace(model.NewUsername)) { var newUser = await _userManager.FindByNameAsync(model.NewUsername); if (newUser != null) { ModelState.AddModelError("", "The NEW username you have supplied is already in use, please try another one. If you didn't mean to update your username please leave that field blank."); } } } if (ModelState.IsValid) { Address homeAddress = null; Address mailingAddress = null; var auditEvent = new AuditEvent(); auditEvent.DepartmentId = DepartmentId; auditEvent.UserId = UserId; auditEvent.Type = AuditLogTypes.ProfileUpdated; var savedProfile = await _userProfileService.GetProfileByUserIdAsync(model.UserId); if (savedProfile == null) { savedProfile = new UserProfile(); } auditEvent.Before = savedProfile.CloneJson(); savedProfile.UserId = model.UserId; savedProfile.MobileCarrier = (int)model.Carrier; savedProfile.FirstName = model.FirstName; savedProfile.LastName = model.LastName; savedProfile.MobileNumber = model.Profile.MobileNumber; savedProfile.SendEmail = model.Profile.SendEmail; savedProfile.SendPush = model.Profile.SendPush; savedProfile.SendSms = model.Profile.SendSms; savedProfile.SendMessageEmail = model.Profile.SendMessageEmail; savedProfile.SendMessagePush = model.Profile.SendMessagePush; savedProfile.SendMessageSms = model.Profile.SendMessageSms; savedProfile.SendNotificationEmail = model.Profile.SendNotificationEmail; savedProfile.SendNotificationPush = model.Profile.SendNotificationPush; savedProfile.SendNotificationSms = model.Profile.SendNotificationSms; savedProfile.DoNotRecieveNewsletters = model.Profile.DoNotRecieveNewsletters; savedProfile.HomeNumber = model.Profile.HomeNumber; savedProfile.IdentificationNumber = model.Profile.IdentificationNumber; savedProfile.TimeZone = model.Profile.TimeZone; if (model.CanEnableVoice) { savedProfile.VoiceForCall = model.Profile.VoiceForCall; if (savedProfile.VoiceForCall) { savedProfile.VoiceCallHome = model.Profile.VoiceCallHome; savedProfile.VoiceCallMobile = model.Profile.VoiceCallMobile; } else { savedProfile.VoiceCallHome = false; savedProfile.VoiceCallMobile = false; } } else { savedProfile.VoiceForCall = false; savedProfile.VoiceCallHome = false; savedProfile.VoiceCallMobile = false; } if (ClaimsAuthorizationHelper.IsUserDepartmentAdmin()) { var currentGroup = await _departmentGroupsService.GetGroupForUserAsync(model.UserId, DepartmentId); if (model.UserGroup != 0 && (currentGroup == null || currentGroup.DepartmentGroupId != model.UserGroup)) { await _departmentGroupsService.MoveUserIntoGroupAsync(model.UserId, model.UserGroup, model.IsUserGroupAdmin, DepartmentId, cancellationToken); } else if (currentGroup != null && currentGroup.DepartmentGroupId == model.UserGroup) { var member = await _departmentGroupsService.GetGroupMemberForUserAsync(model.UserId, DepartmentId); if (member != null) { member.IsAdmin = model.IsUserGroupAdmin; _departmentGroupsService.SaveGroupMember(member); } } else if (model.UserGroup <= 0) { await _departmentGroupsService.DeleteUserFromGroupsAsync(model.UserId, DepartmentId, cancellationToken); } } if (form.ContainsKey("roles")) { var roles = form["roles"].ToString().Split(char.Parse(",")); if (roles.Any()) { await _personnelRolesService.SetRolesForUserAsync(DepartmentId, model.UserId, roles, cancellationToken); } } if (savedProfile.HomeAddressId.HasValue) { homeAddress = await _addressService.GetAddressByIdAsync(savedProfile.HomeAddressId.Value); } if (savedProfile.MailingAddressId.HasValue) { mailingAddress = await _addressService.GetAddressByIdAsync(savedProfile.MailingAddressId.Value); } if (!model.MailingAddressSameAsPhysical && homeAddress != null && mailingAddress != null && (homeAddress.AddressId == mailingAddress.AddressId)) { mailingAddress = new Address(); } if (!String.IsNullOrWhiteSpace(model.PhysicalAddress1)) { if (homeAddress == null) { homeAddress = new Address(); } homeAddress.Address1 = model.PhysicalAddress1; homeAddress.City = model.PhysicalCity; homeAddress.Country = model.PhysicalCountry; homeAddress.PostalCode = model.PhysicalPostalCode; homeAddress.State = model.PhysicalState; homeAddress = await _addressService.SaveAddressAsync(homeAddress, cancellationToken); savedProfile.HomeAddressId = homeAddress.AddressId; if (model.MailingAddressSameAsPhysical) { savedProfile.MailingAddressId = homeAddress.AddressId; } } if (!String.IsNullOrWhiteSpace(model.MailingAddress1) && !model.MailingAddressSameAsPhysical) { if (mailingAddress == null) { mailingAddress = new Address(); } mailingAddress.Address1 = model.MailingAddress1; mailingAddress.City = model.MailingCity; mailingAddress.Country = model.MailingCountry; mailingAddress.PostalCode = model.MailingPostalCode; mailingAddress.State = model.MailingState; mailingAddress = await _addressService.SaveAddressAsync(mailingAddress, cancellationToken); savedProfile.MailingAddressId = mailingAddress.AddressId; } savedProfile.LastUpdated = DateTime.UtcNow; await _userProfileService.SaveProfileAsync(DepartmentId, savedProfile, cancellationToken); auditEvent.After = savedProfile.CloneJson(); _eventAggregator.SendMessage <AuditEvent>(auditEvent); var depMember = await _departmentsService.GetDepartmentMemberAsync(model.UserId, DepartmentId); if (depMember != null) { // Users Department Admin status changes, invalid the department object in cache. if (model.IsDepartmentAdmin != depMember.IsAdmin) { _departmentsService.InvalidateDepartmentInCache(depMember.DepartmentId); } depMember.IsAdmin = model.IsDepartmentAdmin; depMember.IsDisabled = model.IsDisabled; depMember.IsHidden = model.IsHidden; await _departmentsService.SaveDepartmentMemberAsync(depMember, cancellationToken); } if (!model.Profile.DoNotRecieveNewsletters) { Unsubscribe(model.Email); } //var membershipUser = Membership.GetUser(model.UserId); //membershipUser.Email = model.Email; //Membership.UpdateUser(membershipUser); _usersService.UpdateEmail(model.User.Id, model.Email); if (model.IsOwnProfile) { // Change Password if (!string.IsNullOrEmpty(model.OldPassword) && !string.IsNullOrEmpty(model.NewPassword)) { var identityUser = await _userManager.FindByIdAsync(model.User.Id); var result = await _userManager.ChangePasswordAsync(identityUser, model.OldPassword, model.NewPassword); } if (!string.IsNullOrWhiteSpace(model.NewUsername)) { _usersService.UpdateUsername(model.User.UserName, model.NewUsername); } } _userProfileService.ClearUserProfileFromCache(model.UserId); _userProfileService.ClearAllUserProfilesFromCache(model.Department.DepartmentId); _departmentsService.InvalidateDepartmentUsersInCache(model.Department.DepartmentId); _departmentsService.InvalidatePersonnelNamesInCache(DepartmentId); _departmentsService.InvalidateDepartmentMembers(); _usersService.ClearCacheForDepartment(DepartmentId); return(RedirectToAction("Index", "Personnel", new { area = "User" })); } // If we got this far, something failed, redisplay form return(View(model)); }
public NewCallPayloadResult GetNewCallData() { var results = new NewCallPayloadResult(); results.Personnel = new List <PersonnelInfoResult>(); results.Groups = new List <GroupInfoResult>(); results.Units = new List <UnitInfoResult>(); results.Roles = new List <RoleInfoResult>(); results.Statuses = new List <CustomStatusesResult>(); results.UnitStatuses = new List <UnitStatusCoreResult>(); results.UnitRoles = new List <UnitRoleResult>(); results.Priorities = new List <CallPriorityResult>(); results.CallTypes = new List <CallTypeResult>(); var department = _departmentsService.GetDepartmentById(DepartmentId, false); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); var allRoles = _personnelRolesService.GetRolesForDepartment(DepartmentId); var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId); var allGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitTypes = _unitsService.GetUnitTypesForDepartment(DepartmentId); var callPriorites = _callsService.GetCallPrioritesForDepartment(DepartmentId); var callTypes = _callsService.GetCallTypesForDepartment(DepartmentId); foreach (var user in users) { //var profile = _userProfileService.GetProfileByUserId(user.UserId); //var group = _departmentGroupsService.GetGroupForUser(user.UserId); UserProfile profile = null; if (allProfiles.ContainsKey(user.UserId)) { profile = allProfiles[user.UserId]; } DepartmentGroup group = null; if (groups.ContainsKey(user.UserId)) { group = groups[user.UserId]; } //var roles = _personnelRolesService.GetRolesForUser(user.UserId); List <PersonnelRole> roles = null; if (rolesForUsersInDepartment.ContainsKey(user.UserId)) { roles = rolesForUsersInDepartment[user.UserId]; } var result = new PersonnelInfoResult(); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknown"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } result.Eml = user.Email; result.Did = DepartmentId; result.Uid = user.UserId.ToString(); if (group != null) { result.Gid = group.DepartmentGroupId; result.Gnm = group.Name; } result.Roles = new List <string>(); if (roles != null && roles.Count > 0) { foreach (var role in roles) { if (role != null) { result.Roles.Add(role.Name); } } } results.Personnel.Add(result); } foreach (var group in allGroups) { var groupInfo = new GroupInfoResult(); groupInfo.Gid = group.DepartmentGroupId; groupInfo.Nme = group.Name; if (group.Type.HasValue) { groupInfo.Typ = group.Type.Value; } if (group.Address != null) { groupInfo.Add = group.Address.FormatAddress(); } results.Groups.Add(groupInfo); } foreach (var unit in units) { var unitResult = new UnitInfoResult(); unitResult.Uid = unit.UnitId; unitResult.Did = DepartmentId; unitResult.Nme = unit.Name; unitResult.Typ = unit.Type; if (!string.IsNullOrWhiteSpace(unit.Type)) { var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type); if (unitType != null) { unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault(); } } else { unitResult.Cid = 0; } if (unit.StationGroup != null) { unitResult.Sid = unit.StationGroup.DepartmentGroupId; unitResult.Snm = unit.StationGroup.Name; } results.Units.Add(unitResult); // Add unit roles for this unit var roles = _unitsService.GetRolesForUnit(unit.UnitId); foreach (var role in roles) { var roleResult = new UnitRoleResult(); roleResult.Name = role.Name; roleResult.UnitId = role.UnitId; roleResult.UnitRoleId = role.UnitRoleId; results.UnitRoles.Add(roleResult); } } var unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); foreach (var us in unitStatuses) { var unitStatus = new UnitStatusCoreResult(); unitStatus.UnitId = us.UnitId; unitStatus.StateType = (UnitStateTypes)us.State; unitStatus.StateTypeId = us.State; unitStatus.Type = us.Unit.Type; unitStatus.Timestamp = us.Timestamp.TimeConverter(department); unitStatus.Name = us.Unit.Name; unitStatus.Note = us.Note; if (us.DestinationId.HasValue) { unitStatus.DestinationId = us.DestinationId.Value; } if (us.LocalTimestamp.HasValue) { unitStatus.LocalTimestamp = us.LocalTimestamp.Value; } if (us.Latitude.HasValue) { unitStatus.Latitude = us.Latitude.Value; } if (us.Longitude.HasValue) { unitStatus.Longitude = us.Longitude.Value; } results.UnitStatuses.Add(unitStatus); } foreach (var role in allRoles) { var roleResult = new RoleInfoResult(); roleResult.Rid = role.PersonnelRoleId; roleResult.Nme = role.Name; results.Roles.Add(roleResult); } var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(DepartmentId); foreach (var customState in customStates) { if (customState.IsDeleted) { continue; } foreach (var stateDetail in customState.GetActiveDetails()) { if (stateDetail.IsDeleted) { continue; } var customStateResult = new CustomStatusesResult(); customStateResult.Id = stateDetail.CustomStateDetailId; customStateResult.Type = customState.Type; customStateResult.StateId = stateDetail.CustomStateId; customStateResult.Text = stateDetail.ButtonText; customStateResult.BColor = stateDetail.ButtonColor; customStateResult.Color = stateDetail.TextColor; customStateResult.Gps = stateDetail.GpsRequired; customStateResult.Note = stateDetail.NoteType; customStateResult.Detail = stateDetail.DetailType; results.Statuses.Add(customStateResult); } } foreach (var priority in callPriorites) { var priorityResult = new CallPriorityResult(); priorityResult.Id = priority.DepartmentCallPriorityId; priorityResult.DepartmentId = priority.DepartmentId; priorityResult.Name = priority.Name; priorityResult.Color = priority.Color; priorityResult.Sort = priority.Sort; priorityResult.IsDeleted = priority.IsDeleted; priorityResult.IsDefault = priority.IsDefault; results.Priorities.Add(priorityResult); } if (callTypes != null && callTypes.Any()) { foreach (var callType in callTypes) { var type = new CallTypeResult(); type.Id = callType.CallTypeId; type.Name = callType.Type; results.CallTypes.Add(type); } } return(results); }
public string GetMessageForType(ProcessedNotification notification) { try { NotificationItem data = ObjectSerialization.Deserialize <NotificationItem>(notification.Data); switch (notification.Type) { case EventTypes.UnitStatusChanged: var unitEvent = _unitsService.GetUnitStateById((int)data.StateId); var unitStatus = _customStateService.GetCustomUnitState(unitEvent); if (unitEvent != null && unitEvent.Unit != null) { return(String.Format("Unit {0} is now {1}", unitEvent.Unit.Name, unitStatus.ButtonText)); } else if (unitEvent != null) { return(String.Format("A Unit's status is now {0}", unitStatus.ButtonText)); } else { return("A unit's status changed"); } case EventTypes.PersonnelStaffingChanged: var userStaffing = _userStateService.GetUserStateById((int)data.StateId); var userProfile = _userProfileService.GetProfileByUserId(userStaffing.UserId); var userStaffingText = _customStateService.GetCustomPersonnelStaffing(data.DepartmentId, userStaffing); return(String.Format("{0} staffing is now {1}", userProfile.FullName.AsFirstNameLastName, userStaffingText.ButtonText)); case EventTypes.PersonnelStatusChanged: var actionLog = _actionLogsService.GetActionlogById(data.StateId); UserProfile profile = null; if (actionLog != null) { profile = _userProfileService.GetProfileByUserId(actionLog.UserId); } else if (data.UserId != String.Empty) { profile = _userProfileService.GetProfileByUserId(data.UserId); } var userStatusText = _customStateService.GetCustomPersonnelStatus(data.DepartmentId, actionLog); if (profile != null && userStatusText != null) { return(String.Format("{0} status is now {1}", profile.FullName.AsFirstNameLastName, userStatusText.ButtonText)); } else if (profile != null) { return(String.Format("{0} status has changed", profile.FullName.AsFirstNameLastName)); } return(String.Empty); case EventTypes.UserCreated: var newUserprofile = _userProfileService.GetProfileByUserId(data.UserId); if (newUserprofile != null) { return(String.Format("{0} has been added to your department", newUserprofile.FullName.AsFirstNameLastName)); } else { return("A new user has been added to your department"); } case EventTypes.UserAssignedToGroup: UserProfile groupUserprofile = null; try { if (data.UserId != String.Empty) { groupUserprofile = _userProfileService.GetProfileByUserId(data.UserId); } } catch { } DepartmentGroup newGroup = null; try { if (data.GroupId != 0) { newGroup = _departmentGroupsService.GetGroupById((int)data.GroupId, false); } } catch { } if (groupUserprofile != null && newGroup != null) { return(String.Format("{0} has been assigned to group {1}", groupUserprofile.FullName.AsFirstNameLastName, newGroup.Name)); } else if (groupUserprofile != null && newGroup == null) { return(String.Format("{0} has been assigned to group", groupUserprofile.FullName.AsFirstNameLastName)); } else if (newGroup != null && groupUserprofile == null) { return(String.Format("A user has been assigned to group {0}", newGroup.Name)); } else { return(String.Format("A has been assigned to a group")); } case EventTypes.CalendarEventUpcoming: var calandarItem = _calendarService.GetCalendarItemById((int)data.ItemId); return(String.Format("Event {0} is upcoming", calandarItem.Title)); case EventTypes.DocumentAdded: var document = _documentsService.GetDocumentById((int)data.ItemId); return(String.Format("Document {0} has been added", document.Name)); case EventTypes.NoteAdded: var note = _notesService.GetNoteById((int)data.ItemId); if (note != null) { return(String.Format("Message {0} has been added", note.Title)); } break; case EventTypes.UnitAdded: var unit = _unitsService.GetUnitById((int)data.UnitId); return(String.Format("Unit {0} has been added", unit.Name)); case EventTypes.LogAdded: var log = _workLogsService.GetWorkLogById((int)data.ItemId); if (log != null) { var logUserProfile = _userProfileService.GetProfileByUserId(log.LoggedByUserId); return(String.Format("{0} created log {1}", logUserProfile.FullName.AsFirstNameLastName, log.LogId)); } else { return(String.Format("A new log was created")); } case EventTypes.DepartmentSettingsChanged: return(String.Format("Settings have been updated for your department")); case EventTypes.RolesInGroupAvailabilityAlert: var userStateChanged = _userStateService.GetUserStateById(int.Parse(notification.Value)); var roleForGroup = _personnelRolesService.GetRoleById(notification.PersonnelRoleTargeted); var groupForRole = _departmentGroupsService.GetGroupForUser(userStateChanged.UserId, notification.DepartmentId); return(String.Format("Availability for role {0} in group {1} is at or below the lower limit", roleForGroup.Name, groupForRole.Name)); case EventTypes.RolesInDepartmentAvailabilityAlert: if (notification != null) { var roleForDep = _personnelRolesService.GetRoleById(notification.PersonnelRoleTargeted); if (roleForDep != null) { return(String.Format("Availability for role {0} for the department is at or below the lower limit", roleForDep.Name)); } } break; case EventTypes.UnitTypesInGroupAvailabilityAlert: if (data.UnitId != 0) { var unitForGroup = _unitsService.GetUnitById(data.UnitId); if (unitForGroup != null && unitForGroup.StationGroupId.HasValue) { var groupForUnit = _departmentGroupsService.GetGroupById(unitForGroup.StationGroupId.Value); return(String.Format("Availability for unit type {0} in group {1} is at or below the lower limit", unitForGroup.Type, groupForUnit.Name)); } } return(String.Empty); case EventTypes.UnitTypesInDepartmentAvailabilityAlert: return(String.Format("Availability for unit type {0} for the department is at or below the lower limit", notification.UnitTypeTargeted)); case EventTypes.CalendarEventAdded: var calEvent = _calendarService.GetCalendarItemById(notification.ItemId); var department = _departmentsService.GetDepartmentById(calEvent.DepartmentId); if (calEvent != null) { if (calEvent.ItemType == 0) { if (calEvent.IsAllDay) { return($"New Calendar Event {calEvent.Title} on {calEvent.Start.TimeConverter(department).ToShortDateString()}"); } else { return($"New Calendar Event {calEvent.Title} on {calEvent.Start.TimeConverter(department).ToShortDateString()} at {calEvent.Start.TimeConverter(department).ToShortTimeString()}"); } } else if (calEvent.IsAllDay) { return($"New Calendar RSVP Event {calEvent.Title} on {calEvent.Start.TimeConverter(department).ToShortDateString()}"); } else { return($"New Calendar RSVP Event {calEvent.Title} on {calEvent.Start.TimeConverter(department).ToShortDateString()} at {calEvent.Start.TimeConverter(department).ToShortTimeString()}"); } } else { return(String.Empty); } case EventTypes.CalendarEventUpdated: var calUpdatedEvent = _calendarService.GetCalendarItemById(notification.ItemId); var calUpdatedEventDepartment = _departmentsService.GetDepartmentById(calUpdatedEvent.DepartmentId); if (calUpdatedEvent != null) { return($"Calendar Event {calUpdatedEvent.Title} on {calUpdatedEvent.Start.TimeConverter(calUpdatedEventDepartment).ToShortDateString()} has changed"); } else { return(String.Empty); } default: throw new ArgumentOutOfRangeException("type"); } } catch (Exception ex) { Logging.LogException(ex, extraMessage: notification.Data); return(String.Empty); } return(String.Empty); }
public UnitAppPayloadResult GetCommandAppCoreData() { var results = new UnitAppPayloadResult(); results.Personnel = new List <PersonnelInfoResult>(); results.Groups = new List <GroupInfoResult>(); results.Units = new List <UnitInfoResult>(); results.Roles = new List <RoleInfoResult>(); results.Statuses = new List <CustomStatusesResult>(); results.Calls = new List <CallResult>(); results.UnitStatuses = new List <UnitStatusCoreResult>(); results.UnitRoles = new List <UnitRoleResult>(); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); var allRoles = _personnelRolesService.GetRolesForDepartment(DepartmentId); var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId); var allGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitTypes = _unitsService.GetUnitTypesForDepartment(DepartmentId); foreach (var user in users) { //var profile = _userProfileService.GetProfileByUserId(user.UserId); //var group = _departmentGroupsService.GetGroupForUser(user.UserId); UserProfile profile = null; if (allProfiles.ContainsKey(user.UserId)) { profile = allProfiles[user.UserId]; } DepartmentGroup group = null; if (groups.ContainsKey(user.UserId)) { group = groups[user.UserId]; } //var roles = _personnelRolesService.GetRolesForUser(user.UserId); List <PersonnelRole> roles = null; if (rolesForUsersInDepartment.ContainsKey(user.UserId)) { roles = rolesForUsersInDepartment[user.UserId]; } var result = new PersonnelInfoResult(); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknown"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } result.Eml = user.Email; result.Did = DepartmentId; result.Uid = user.UserId.ToString(); if (group != null) { result.Gid = group.DepartmentGroupId; result.Gnm = group.Name; } result.Roles = new List <string>(); if (roles != null && roles.Count > 0) { foreach (var role in roles) { if (role != null) { result.Roles.Add(role.Name); } } } results.Personnel.Add(result); } results.Rights = new DepartmentRightsResult(); var currentUser = _usersService.GetUserByName(UserName); if (currentUser == null) { throw HttpStatusCode.Unauthorized.AsException(); } var department = _departmentsService.GetDepartmentById(DepartmentId, false); results.Rights.Adm = department.IsUserAnAdmin(currentUser.UserId); results.Rights.Grps = new List <GroupRight>(); var currentGroup = _departmentGroupsService.GetGroupForUser(currentUser.UserId, DepartmentId); if (currentGroup != null) { var groupRight = new GroupRight(); groupRight.Gid = currentGroup.DepartmentGroupId; groupRight.Adm = currentGroup.IsUserGroupAdmin(currentUser.UserId); results.Rights.Grps.Add(groupRight); } foreach (var group in allGroups) { var groupInfo = new GroupInfoResult(); groupInfo.Gid = group.DepartmentGroupId; groupInfo.Nme = group.Name; if (group.Type.HasValue) { groupInfo.Typ = group.Type.Value; } if (group.Address != null) { groupInfo.Add = group.Address.FormatAddress(); } results.Groups.Add(groupInfo); } foreach (var unit in units) { var unitResult = new UnitInfoResult(); unitResult.Uid = unit.UnitId; unitResult.Did = DepartmentId; unitResult.Nme = unit.Name; unitResult.Typ = unit.Type; if (!string.IsNullOrWhiteSpace(unit.Type)) { var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type); if (unitType != null) { unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault(); } } else { unitResult.Cid = 0; } if (unit.StationGroup != null) { unitResult.Sid = unit.StationGroup.DepartmentGroupId; unitResult.Snm = unit.StationGroup.Name; } results.Units.Add(unitResult); // Add unit roles for this unit var roles = _unitsService.GetRolesForUnit(unit.UnitId); foreach (var role in roles) { var roleResult = new UnitRoleResult(); roleResult.Name = role.Name; roleResult.UnitId = role.UnitId; roleResult.UnitRoleId = role.UnitRoleId; results.UnitRoles.Add(roleResult); } } var unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); foreach (var us in unitStatuses) { var unitStatus = new UnitStatusCoreResult(); unitStatus.UnitId = us.UnitId; unitStatus.StateType = (UnitStateTypes)us.State; unitStatus.StateTypeId = us.State; unitStatus.Type = us.Unit.Type; unitStatus.Timestamp = us.Timestamp.TimeConverter(department); unitStatus.Name = us.Unit.Name; if (us.DestinationId.HasValue) { unitStatus.DestinationId = us.DestinationId.Value; } results.UnitStatuses.Add(unitStatus); } foreach (var role in allRoles) { var roleResult = new RoleInfoResult(); roleResult.Rid = role.PersonnelRoleId; roleResult.Nme = role.Name; results.Roles.Add(roleResult); } var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(DepartmentId); foreach (var customState in customStates) { if (customState.IsDeleted) { continue; } foreach (var stateDetail in customState.GetActiveDetails()) { if (stateDetail.IsDeleted) { continue; } var customStateResult = new CustomStatusesResult(); customStateResult.Id = stateDetail.CustomStateDetailId; customStateResult.Type = customState.Type; customStateResult.StateId = stateDetail.CustomStateId; customStateResult.Text = stateDetail.ButtonText; customStateResult.BColor = stateDetail.ButtonColor; customStateResult.Color = stateDetail.TextColor; customStateResult.Gps = stateDetail.GpsRequired; customStateResult.Note = stateDetail.NoteType; customStateResult.Detail = stateDetail.DetailType; results.Statuses.Add(customStateResult); } } var calls = _callsService.GetActiveCallsByDepartment(DepartmentId).OrderByDescending(x => x.LoggedOn); if (calls != null && calls.Any()) { foreach (var c in calls) { var call = new CallResult(); call.Cid = c.CallId; call.Pri = c.Priority; call.Ctl = c.IsCritical; call.Nme = c.Name; call.Noc = c.NatureOfCall; call.Map = c.MapPage; call.Not = c.Notes; if (String.IsNullOrWhiteSpace(c.Address) && !String.IsNullOrWhiteSpace(c.GeoLocationData)) { var geo = c.GeoLocationData.Split(char.Parse(",")); if (geo.Length == 2) { call.Add = _geoLocationProvider.GetAddressFromLatLong(double.Parse(geo[0]), double.Parse(geo[1])); } } else { call.Add = c.Address; } call.Add = c.Address; call.Geo = c.GeoLocationData; call.Lon = c.LoggedOn.TimeConverter(department); call.Ste = c.State; call.Num = c.Number; results.Calls.Add(call); } } else { // This is a hack due to a bug in the current units app! -SJ 1-31-2016 var call = new CallResult(); call.Cid = 0; call.Pri = 0; call.Ctl = false; call.Nme = "No Call"; call.Noc = ""; call.Map = ""; call.Not = ""; call.Add = ""; call.Geo = ""; call.Lon = DateTime.UtcNow; call.Ste = 0; call.Num = ""; results.Calls.Add(call); } return(results); }
public List <PersonnelStatusResult> GetPersonnelStatuses(string activeFilter) { var results = new List <PersonnelStatusResult>(); var filter = HttpUtility.UrlDecode(activeFilter); var activeFilters = filter.Split(char.Parse("|")); var filters = GetFilterOptions(); var actionLogs = _actionLogsService.GetActionLogsForDepartment(DepartmentId); var userStates = _userStateService.GetLatestStatesForDepartment(DepartmentId); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); Department department = _departmentsService.GetDepartmentById(DepartmentId, false); var allGroups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var allRoles = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); Parallel.ForEach(users, u => { var log = (from l in actionLogs where l.UserId == u.UserId select l).FirstOrDefault(); var state = (from l in userStates where l.UserId == u.UserId select l).FirstOrDefault(); var s = new PersonnelStatusResult(); s.Uid = u.UserId.ToString(); if (log != null) { s.Atp = log.ActionTypeId; s.Atm = log.Timestamp.TimeConverter(department); if (log.DestinationId.HasValue) { if (log.ActionTypeId == (int)ActionTypes.RespondingToScene) { s.Did = log.DestinationId.Value.ToString(); } else if (log.ActionTypeId == (int)ActionTypes.RespondingToStation) { s.Did = log.DestinationId.Value.ToString(); } else if (log.ActionTypeId == (int)ActionTypes.AvailableStation) { s.Did = log.DestinationId.Value.ToString(); } } } else { s.Atp = (int)ActionTypes.StandingBy; s.Atm = DateTime.UtcNow.TimeConverter(department); } if (state != null) { s.Ste = state.State; s.Stm = state.Timestamp.TimeConverter(department); } else { s.Ste = (int)UserStateTypes.Available; s.Stm = DateTime.UtcNow.TimeConverter(department); } DepartmentGroup userGroup = null; if (allGroups.ContainsKey(u.UserId)) { userGroup = allGroups[u.UserId]; } var roles = new List <PersonnelRole>(); if (allRoles.ContainsKey(u.UserId)) { roles = allRoles[u.UserId]; } foreach (var afilter in activeFilters) { var text = GetTextValue(afilter, filters); if (afilter.Substring(0, 2) == "G:") { if (userGroup != null && text == userGroup.Name) { results.Add(s); break; } } else if (afilter.Substring(0, 2) == "R:") { if (roles.Any(x => x.Name == text)) { results.Add(s); break; } } else if (afilter.Substring(0, 2) == "U:") { if (s.Ste.ToString() == text || s.Ste.ToString() == text.Replace(" ", "")) { results.Add(s); break; } } } }); return(results); }
public NewGroupView() { NewGroup = new DepartmentGroup(); NewGroup.Address = new Address(); NewGroup.Type = 1; }
public async Task <IActionResult> EditUserProfile(string userId) { var model = new EditProfileModel(); model.ApiUrl = Config.SystemBehaviorConfig.ResgridApiBaseUrl; model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); var departmentMember = await _departmentsService.GetDepartmentMemberAsync(userId, DepartmentId); if (!await _authorizationService.CanUserEditProfileAsync(UserId, DepartmentId, userId)) { Unauthorized(); } var groups = new List <DepartmentGroup>(); var defaultGroup = new DepartmentGroup(); defaultGroup.Name = "No Group"; groups.Add(defaultGroup); groups.AddRange(await _departmentGroupsService.GetAllGroupsForDepartmentAsync(model.Department.DepartmentId)); ViewBag.Carriers = model.Carrier.ToSelectList(); ViewBag.Countries = new SelectList(Countries.CountryNames); ViewBag.TimeZones = new SelectList(TimeZones.Zones, "Key", "Value"); model.Groups = new SelectList(groups, "DepartmentGroupId", "Name"); var group = await _departmentGroupsService.GetGroupForUserAsync(userId, DepartmentId); if (group != null) { model.UserGroup = group.DepartmentGroupId; model.IsUserGroupAdmin = group.IsUserGroupAdmin(userId); } //model.UsersRoles = await _personnelRolesService.GetRolesForUser(userId); model.IsDisabled = departmentMember.IsDisabled.HasValue != false && departmentMember.IsDisabled.Value; model.IsHidden = departmentMember.IsHidden.HasValue != false && departmentMember.IsHidden.Value; model.IsDepartmentAdmin = departmentMember.IsAdmin.HasValue != false && departmentMember.IsAdmin.Value; model.CanEnableVoice = await _limitsService.CanDepartmentUseVoiceAsync(DepartmentId); if (userId == UserId) { model.IsOwnProfile = true; } model.User = _usersService.GetUserById(userId, true); model.UserId = userId; model.Email = model.User.Email; model.Profile = await _userProfileService.GetProfileByUserIdAsync(userId, true); if (model.Profile == null) { model.Profile = new UserProfile(); } if (model.Profile.Image == null) { model.HasCustomIamge = false; } else { model.HasCustomIamge = true; } if (model.Profile != null && model.Profile.HomeAddressId.HasValue) { var homeAddress = await _addressService.GetAddressByIdAsync(model.Profile.HomeAddressId.Value); model.PhysicalAddress1 = homeAddress.Address1; model.PhysicalCity = homeAddress.City; model.PhysicalCountry = homeAddress.Country; model.PhysicalPostalCode = homeAddress.PostalCode; model.PhysicalState = homeAddress.State; } if (model.Profile != null && model.Profile.MailingAddressId.HasValue && model.Profile.HomeAddressId.HasValue && (model.Profile.MailingAddressId.Value == model.Profile.HomeAddressId.Value)) { model.MailingAddressSameAsPhysical = true; } else if (model.Profile != null && model.Profile.MailingAddressId.HasValue) { var mailingAddress = await _addressService.GetAddressByIdAsync(model.Profile.MailingAddressId.Value); model.MailingAddress1 = mailingAddress.Address1; model.MailingCity = mailingAddress.City; model.MailingCountry = mailingAddress.Country; model.MailingPostalCode = mailingAddress.PostalCode; model.MailingState = mailingAddress.State; } if (model.Profile != null) { model.Carrier = (MobileCarriers)model.Profile.MobileCarrier; } if (!String.IsNullOrEmpty(model.Profile.FirstName) && !String.IsNullOrEmpty(model.Profile.LastName)) { model.FirstName = model.Profile.FirstName; model.LastName = model.Profile.LastName; } else { //MembershipUser currentUser = Membership.GetUser(model.User.UserName, userIsOnline: true); //var pfile = ProfileBase.Create(model.User.UserName, true); var userProfile = await _userProfileService.GetProfileByUserIdAsync(userId); if (userProfile != null) { model.FirstName = userProfile.FirstName; model.LastName = userProfile.LastName; } else { model.FirstName = ""; model.LastName = ""; } } model.EnableSms = model.Profile.SendSms; return(View(model)); }