public HttpResponseMessage GetShift(int id) { var shift = _shiftsService.GetShiftById(id); if (shift != null) { if (shift.DepartmentId != DepartmentId) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(shift), Encoding.UTF8, "application/json") }); }
public IActionResult Compose(ComposeMessageModel model, IFormCollection collection) { var roles = new List <string>(); var groups = new List <string>(); var users = new List <string>(); var shifts = new List <string>(); if (collection.ContainsKey("roles")) { roles.AddRange(collection["roles"].ToString().Split(char.Parse(","))); } if (collection.ContainsKey("groups")) { groups.AddRange(collection["groups"].ToString().Split(char.Parse(","))); } if (collection.ContainsKey("users")) { users.AddRange(collection["users"].ToString().Split(char.Parse(","))); } if (collection.ContainsKey("exludedShifts")) { shifts.AddRange(collection["exludedShifts"].ToString().Split(char.Parse(","))); } if (!model.SendToAll && (roles.Count + groups.Count + users.Count) == 0) { ModelState.AddModelError("", "You must specify at least one Recipient."); } if (model.SendToMatchOnly && (roles.Count + groups.Count) == 0) { ModelState.AddModelError("", "You must specify at least one Group or Role to send to."); } if (ModelState.IsValid) { var excludedUsers = new List <string>(); if (shifts.Any()) { foreach (var shiftId in shifts) { var shift = _shiftsService.GetShiftById(int.Parse(shiftId)); excludedUsers.AddRange(shift.Personnel.Select(x => x.UserId)); } } model.Message.Type = (int)model.MessageType; if (model.SendToAll) { var allUsers = _departmentsService.GetAllUsersForDepartment(DepartmentId); foreach (var user in allUsers) { if (user.UserId != UserId && (!excludedUsers.Any() || !excludedUsers.Contains(user.UserId))) { model.Message.AddRecipient(user.UserId); } } } else if (model.SendToMatchOnly) { var usersInRoles = new Dictionary <int, List <string> >(); foreach (var role in roles) { var roleMembers = _personnelRolesService.GetAllMembersOfRole(int.Parse(role)); usersInRoles.Add(int.Parse(role), roleMembers.Select(x => x.UserId).ToList()); } foreach (var group in groups) { var members = _departmentGroupsService.GetAllMembersForGroup(int.Parse(group)); foreach (var member in members) { bool isInRoles = false; if (model.Message.GetRecipients().All(x => x != member.UserId) && member.UserId != UserId && (!excludedUsers.Any() || !excludedUsers.Contains(member.UserId))) { foreach (var key in usersInRoles) { if (key.Value.Any(x => x == member.UserId)) { isInRoles = true; break; } } if (isInRoles) { model.Message.AddRecipient(member.UserId); } } } } } else { foreach (var user in users) { model.Message.AddRecipient(user); } // Add all members of the group foreach (var group in groups) { var members = _departmentGroupsService.GetAllMembersForGroup(int.Parse(group)); foreach (var member in members) { if (model.Message.GetRecipients().All(x => x != member.UserId) && member.UserId != UserId && (!excludedUsers.Any() || !excludedUsers.Contains(member.UserId))) { model.Message.AddRecipient(member.UserId); } } } // Add all the users of a specific role foreach (var role in roles) { var roleMembers = _personnelRolesService.GetAllMembersOfRole(int.Parse(role)); foreach (var member in roleMembers) { if (model.Message.GetRecipients().All(x => x != member.UserId) && member.UserId != UserId && (!excludedUsers.Any() || !excludedUsers.Contains(member.UserId))) { model.Message.AddRecipient(member.UserId); } } } } model.Message.SentOn = DateTime.UtcNow; model.Message.SendingUserId = UserId; model.Message.Body = System.Net.WebUtility.HtmlDecode(model.Message.Body); model.Message.IsBroadcast = true; var savedMessage = _messageService.SaveMessage(model.Message); _messageService.SendMessage(savedMessage, "", DepartmentId, false); return(RedirectToAction("Inbox")); } model.Department = _departmentsService.GetDepartmentById(DepartmentId); model.User = _usersService.GetUserById(UserId); model.Types = model.MessageType.ToSelectList(); var savedShifts = _shiftsService.GetAllShiftsByDepartment(DepartmentId); model.Shifts = new SelectList(savedShifts, "ShiftId", "Name"); model.Message.Body = System.Net.WebUtility.HtmlDecode(model.Message.Body); return(View(FillComposeMessageModel(model))); }
public int GetDepartmentIdForType(NotificationItem ni) { switch ((EventTypes)ni.Type) { case EventTypes.PersonnelStaffingChanged: var state = _userStateService.GetUserStateById(ni.StateId); if (state != null) { var department = _departmentsService.GetDepartmentByUserId(state.UserId, true); if (department != null) { return(department.DepartmentId); } else { return(0); } } else { return(0); } case EventTypes.PersonnelStatusChanged: var status = _actionLogsService.GetActionlogById(ni.StateId); if (status != null) { var department = _departmentsService.GetDepartmentByUserId(status.UserId, true); if (department != null) { return(department.DepartmentId); } else { return(0); } } else { return(0); } case EventTypes.CalendarEventAdded: var cal = _calendarService.GetCalendarItemById(ni.ItemId); if (cal != null) { return(cal.DepartmentId); } else { return(0); } case EventTypes.CalendarEventUpcoming: var calUp = _calendarService.GetCalendarItemById(ni.ItemId); if (calUp != null) { return(calUp.DepartmentId); } else { return(0); } case EventTypes.CalendarEventUpdated: var calUpdate = _calendarService.GetCalendarItemById(ni.ItemId); if (calUpdate != null) { return(calUpdate.DepartmentId); } else { return(0); } case EventTypes.DocumentAdded: var docAdded = _documentsService.GetDocumentById(ni.ItemId); if (docAdded != null) { return(docAdded.DepartmentId); } else { return(0); } case EventTypes.LogAdded: var logAdded = _workLogsService.GetWorkLogById(ni.ItemId); if (logAdded != null) { return(logAdded.DepartmentId); } else { return(0); } case EventTypes.NoteAdded: var noteAdded = _notesService.GetNoteById(ni.ItemId); if (noteAdded != null) { return(noteAdded.DepartmentId); } else { return(0); } case EventTypes.ShiftCreated: var shiftCreated = _shiftsService.GetShiftById(ni.ItemId); if (shiftCreated != null) { return(shiftCreated.DepartmentId); } else { return(0); } case EventTypes.ShiftDaysAdded: var shiftDaysAdded = _shiftsService.GetShiftById(ni.ItemId); if (shiftDaysAdded != null) { return(shiftDaysAdded.DepartmentId); } else { return(0); } case EventTypes.ShiftUpdated: var shiftUpdated = _shiftsService.GetShiftById(ni.ItemId); if (shiftUpdated != null) { return(shiftUpdated.DepartmentId); } else { return(0); } case EventTypes.UnitAdded: var unitAdded = _unitsService.GetUnitById(ni.UnitId); if (unitAdded != null) { return(unitAdded.DepartmentId); } else { return(0); } case EventTypes.UnitStatusChanged: var unitStatusChanged = _unitsService.GetUnitStateById(ni.StateId); if (unitStatusChanged != null) { var unit = _unitsService.GetUnitById(unitStatusChanged.UnitId); if (unit != null) { return(unit.DepartmentId); } else { return(0); } } else { return(0); } } return(0); }