public HttpResponseMessage AddStaffInformation(string officeNumber, [FromBody] EmployeeVm staffInfo)
        {
            var companyId          = this.employeeIt2Manager.GetCompanyId(officeNumber);
            var userName           = string.Concat(staffInfo.UserName, GetUserNamePlaceHolderValue(companyId));
            var doesStaffIdExist   = CheckForExistingStaffId(staffInfo.EmployeeNum, companyId);
            var doesLoginNameExist = CheckForExistingLoginName(userName, companyId);
            var validationString   = string.Empty;

            if (doesStaffIdExist && doesLoginNameExist)
            {
                validationString = "The Staff ID already exists in the system. Enter a unique Staff ID.<br/>"
                                   + "The Login Name already exists in the system. Enter a unique Login Name.";
            }
            else if (doesStaffIdExist)
            {
                validationString = "The Staff ID already exists in the system. Enter a unique Staff ID.";
            }
            else if (doesLoginNameExist)
            {
                validationString = "The Login Name already exists in the system. Enter a unique Login Name.";
            }
            else
            {
                staffInfo.ProfessionalCredential = string.Empty;
                staffInfo.EmployeeType           = EmployeeType.Staff;
                var employee = staffInfo.ToEmployee();
                employee.User.Name = userName;

                this.employeeIt2Manager.AddStaff(officeNumber, employee);
                this._UpdateEmployeeOffices(staffInfo, employee, true);
                return(this.Request.CreateResponse(
                           HttpStatusCode.OK,
                           new
                {
                    validationmessage = "Staff Added Successfully.",
                    employeeId = employee.EmployeeId,
                    userId = employee.UserId,
                    employeeType = Convert.ToInt32(staffInfo.EmployeeType),
                    isNew = true
                }));
            }

            Logger.Error("AddStaffInformation: " + validationString);
            return(this.Request.CreateResponse(HttpStatusCode.BadRequest, new { validationmessage = validationString }));
        }
        public HttpResponseMessage UpdateProviderInformation(string officeNumber, [FromBody] EmployeeVm providerInfo)
        {
            AllowUpdate allowUpdate = delegate
            {
                ////Deactivate this provider then remove it linked to any patient
                var msg = string.Empty;
                if (providerInfo.Active == false)
                {
                    var practiceInfo = this.officeIt2Manager.GetCompanyInformation(OfficeHelper.GetCompanyId(officeNumber), officeNumber);
                    if (practiceInfo.ContactInformation.Owner != providerInfo.EmployeeId)
                    {
                        var patientIds = PatientManager.GetProvidersPatients(providerInfo.EmployeeId, officeNumber);
                        if (patientIds.Count > 0)
                        {
                            foreach (var t in patientIds)
                            {
                                this.patientIt2Manager.UpdatePatientsDoctor(t, practiceInfo.ContactInformation.Owner);
                            }
                        }
                    }
                    else
                    {
                        msg += "Unable to deactivate this provider because he/she is a current Company Owner.<br/>";
                    }
                }

                return(msg);
            };

            bool valid;
            var  companyId          = this.employeeIt2Manager.GetCompanyId(officeNumber);
            var  userName           = string.Concat(providerInfo.UserName, GetUserNamePlaceHolderValue(companyId));
            var  doesLoginNameExist = CheckForExistingLoginName(userName, companyId);
            ////var doesUserIdExist = CheckForExistingUserId(userName, companyId);
            var    doesProviderIdExist = CheckForExistingProviderId(providerInfo.EmployeeNum, companyId);
            string validationString;

            if (doesProviderIdExist || doesLoginNameExist)
            {
                providerInfo.EmployeeType = EmployeeType.Provider;
                var employee = providerInfo.ToEmployee();
                employee.User.Name = userName;
                var isLoginNameChanged  = this.employeeIt2Manager.CheckIfLoginChanged(employee);
                var isProviderIdChanged = this.employeeIt2Manager.CheckIfProviderIdChanged(employee);

                if (doesProviderIdExist && isProviderIdChanged && doesLoginNameExist && isLoginNameChanged)
                {
                    validationString = "The ID already exists in the system. Enter a unique ID.<br/>"
                                       + "The updated Login Name already exists in the system. Enter a unique Login Name.";
                }
                else if (doesProviderIdExist && isProviderIdChanged)
                {
                    validationString = "The ID already exists in the system. Enter a unique ID.";
                }
                else if (doesLoginNameExist && isLoginNameChanged)
                {
                    validationString = "The updated Login Name already exists in the system. Enter a unique Login Name.";
                }
                else
                {
                    validationString = allowUpdate();
                    valid            = validationString == string.Empty;
                    if (valid)
                    {
                        this.employeeIt2Manager.UpdateProvider(employee, officeNumber);
                        this._UpdateEmployeeOffices(providerInfo, employee, false);

                        return(this.Request.CreateResponse(
                                   HttpStatusCode.OK,
                                   new
                        {
                            validationmessage = "Provider Updated Successfully.",
                            employeeId = employee.EmployeeId,
                            userId = employee.UserId
                        }));
                    }
                }
            }
            else
            {
                validationString = allowUpdate();
                valid            = validationString == string.Empty;
                if (valid)
                {
                    providerInfo.EmployeeType = EmployeeType.Provider;
                    var employee = providerInfo.ToEmployee();
                    employee.User.Name = userName;
                    this.employeeIt2Manager.UpdateProvider(employee, officeNumber);

                    return(this.Request.CreateResponse(
                               HttpStatusCode.OK,
                               new
                    {
                        validationmessage = "Provider Updated Successfully.",
                        employeeId = employee.EmployeeId,
                        userId = employee.UserId
                    }));
                }
            }

            Logger.Error("UpdateProviderInformation: " + validationString);
            return(this.Request.CreateResponse(HttpStatusCode.BadRequest, new { validationmessage = validationString }));
        }
        public HttpResponseMessage AddProviderInformation(string officeNumber, [FromBody] EmployeeVm providerInfo)
        {
            var    companyId           = this.employeeIt2Manager.GetCompanyId(officeNumber);
            var    userName            = string.Concat(providerInfo.UserName, GetUserNamePlaceHolderValue(companyId));
            var    doesLoginNameExist  = CheckForExistingLoginName(userName, companyId);
            var    doesProviderIdExist = CheckForExistingProviderId(providerInfo.EmployeeNum, companyId);
            string validationString;
            var    pattern = string.Empty;

            pattern += doesLoginNameExist ? "1" : "0";
            pattern += doesProviderIdExist ? "1" : "0";
            pattern += "0"; //// Product management decided to remove this validation

            switch (pattern)
            {
            case "111":
                validationString = "The NPI Number already exists in the system. Enter a unique NPI Number for this provider.<br/> The Login Name already exists in the system. Enter a unique Login Name for this provider.<br/>The ID already exists in the system. Enter a unique ID for this provider.";
                break;

            case "001":
                validationString = "The NPI Number already exists in the system. Enter a unique NPI number for this provider.";
                break;

            case "101":
                validationString = "The NPI Number already exists in the system. Enter a unique NPI number for this provider.<br/>The Login Name already exists in the system. Enter a unique Login Name for this provider.";
                break;

            case "110":
                validationString = "The Login Name already exists in the system. Enter a unique Login Name for this provider.<br/>The ID already exists in the system. Enter a unique ID for this provider.";
                break;

            case "011":
                validationString = "The NPI Number already exists in the system. Enter a unique NPI number for this provider.<br/>The ID already exists in the system. Enter a unique ID for this provider.";
                break;

            case "100":
                validationString = "The Login Name already exists in the system. Enter a unique Login Name for this provider.";
                break;

            case "010":
                validationString = "The ID already exists in the system. Enter a unique ID.";
                break;

            default:
                validationString = string.Empty;
                break;
            }

            if (validationString == string.Empty)
            {
                providerInfo.EmployeeType = EmployeeType.Provider;
                var employee = providerInfo.ToEmployee();
                employee.User.Name = userName;
                this.employeeIt2Manager.AddEmployee(officeNumber, employee);
                this._UpdateEmployeeOffices(providerInfo, employee, true);
                return(this.Request.CreateResponse(
                           HttpStatusCode.OK,
                           new
                {
                    validationmessage = "Provider Added Successfully.",
                    employeeId = employee.EmployeeId,
                    userId = employee.UserId,
                    employeeType = Convert.ToInt32(providerInfo.EmployeeType),
                    isNew = true
                }));
            }

            Logger.Error("AddProviderInformation: " + validationString);
            return(this.Request.CreateResponse(HttpStatusCode.BadRequest, new { validationmessage = validationString }));
        }