예제 #1
0
        public HttpResponseMessage SetStatusForUser(StatusInput statusInput)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    var userToSetStatusFor = _departmentsService.GetDepartmentMember(statusInput.Uid, DepartmentId);

                    if (userToSetStatusFor == null)
                    {
                        throw HttpStatusCode.NotFound.AsException();
                    }

                    if (!_authorizationService.IsUserValidWithinLimits(statusInput.Uid, DepartmentId))
                    {
                        throw HttpStatusCode.Unauthorized.AsException();
                    }

                    if (!_authorizationService.IsUserValidWithinLimits(userToSetStatusFor.UserId, DepartmentId))
                    {
                        throw HttpStatusCode.Unauthorized.AsException();
                    }

                    if (DepartmentId != userToSetStatusFor.DepartmentId)
                    {
                        throw HttpStatusCode.Unauthorized.AsException();
                    }

                    // TODO: We need to check here if the user is a department admin, or the admin that the user is a part of

                    ActionLog log = null;
                    if (statusInput.Rto == 0)
                    {
                        log = _actionLogsService.SetUserAction(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo);
                    }
                    else if (statusInput.Dtp == 0)
                    {
                        log = _actionLogsService.SetUserAction(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo, statusInput.Rto, statusInput.Not);
                    }
                    else
                    {
                        log = _actionLogsService.SetUserAction(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo, statusInput.Rto);
                    }

                    OutboundEventProvider.PersonnelStatusChangedTopicHandler handler = new OutboundEventProvider.PersonnelStatusChangedTopicHandler();
                    handler.Handle(new UserStatusEvent()
                    {
                        DepartmentId = DepartmentId, Status = log
                    });

                    var response = Request.CreateResponse(HttpStatusCode.Created);
                    response.Headers.Add("Access-Control-Allow-Origin", "*");
                    response.Headers.Add("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
                    return(response);
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    throw HttpStatusCode.InternalServerError.AsException();
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }
예제 #2
0
        /// <summary>
        /// Gets the Resgrid user profile for the user
        /// </summary>
        /// <returns>ProfileResult object with the users profile data</returns>
        public ProfileResult GetProfile()
        {
            var profile = _userProfileService.GetProfileByUserId(UserId.ToUpper(), true);

            if (profile == null)
            {
                throw HttpStatusCode.NotFound.AsException();
            }

            var department = _departmentsService.GetDepartmentById(DepartmentId);
            var dm         = _departmentsService.GetDepartmentMember(UserId.ToUpper(), DepartmentId);
            var membership = _usersService.GetMembershipByUserId(UserId.ToUpper());

            var result = new ProfileResult
            {
                Uid = UserId.ToUpper().ToString(),
                Adm = department.IsUserAnAdmin(UserId.ToUpper()),
                Hid = dm.IsHidden.GetValueOrDefault(),
                Dis = dm.IsDisabled.GetValueOrDefault(),
                Fnm = profile.FirstName,
                Lnm = profile.LastName,
                Eml = membership.Email,
                Tz  = profile.TimeZone,
                Mob = profile.MobileNumber,
                Moc = profile.MobileCarrier,
                Hmn = profile.HomeNumber,
                Sce = profile.SendEmail,
                Scp = profile.SendPush,
                Scs = profile.SendSms,
                Sme = profile.SendMessageEmail,
                Smp = profile.SendMessagePush,
                Sms = profile.SendMessageSms,
                Sne = profile.SendNotificationEmail,
                Snp = profile.SendNotificationPush,
                Sns = profile.SendNotificationSms,
                Id  = profile.IdentificationNumber,
                Val = _limitsService.CanDepartmentUseVoice(DepartmentId),
                Voc = profile.VoiceForCall,
                Vcm = profile.VoiceCallMobile,
                Vch = profile.VoiceCallHome,
                Lup = profile.LastUpdated
            };

            if (membership.LockoutEnd.HasValue)
            {
                result.Lkd = true;
            }
            else
            {
                result.Lkd = false;
            }

            if (profile.HomeAddressId.HasValue)
            {
                var address = _addressService.GetAddressById(profile.HomeAddressId.Value);

                if (address != null)
                {
                    result.Hme = new AddressResult()
                    {
                        Aid = address.AddressId,
                        Str = address.Address1,
                        Cty = address.City,
                        Ste = address.State,
                        Zip = address.PostalCode,
                        Cnt = address.Country
                    };
                }
            }

            if (profile.MailingAddressId.HasValue)
            {
                var address = _addressService.GetAddressById(profile.MailingAddressId.Value);

                if (address != null)
                {
                    result.Mal = new AddressResult()
                    {
                        Aid = address.AddressId,
                        Str = address.Address1,
                        Cty = address.City,
                        Ste = address.State,
                        Zip = address.PostalCode,
                        Cnt = address.Country
                    };
                }
            }

            return(result);
        }