示例#1
0
        public MonitorModule(ISessionProvider sessionProvider)
            : base("/monitor")
        {
            _sessionProvider = sessionProvider;
            Get["/live"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        return session.Load<MonitorSite>("MonitorSites/1").Text;
                    }
                };

            Get["/createlive"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        if (session.Load<MonitorSite>("MonitorSites/1") == null)
                        {
                            session.Store(new MonitorSite
                                {
                                    Id = "MonitorSites/1",
                                    Text = "I was fetched from the database",
                                });
                            session.SaveChanges();
                            return "Message was stored to the database.";
                        }
                        else
                        {
                            return Response.AsRedirect("/monitor/live");
                        }
                    }
                };
        }
        /// <summary>
        ///     Afters the processing.
        /// </summary>
        /// <param name="requests">The requests.</param>
        /// <param name="responses">The responses.</param>
        protected override void AfterProcessing(IEnumerable <Request> requests, IEnumerable <Response> responses)
        {
            var session = _sessionProvider.GetSession();

            responses = responses.ToList();

            base.AfterProcessing(requests, responses);

            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Responses: {0}",
                             JsonConvert.SerializeObject(responses, new JsonSerializerSettings {
                    ContractResolver = new SerializableContractResolver {
                        IgnoreSerializableAttribute = true
                    }
                }));
            }

            if (!_validationFailureOccurred && session.Transaction.IsActive)
            {
                if (!IsExceptionOccurred(responses))
                {
                    Logger.Debug("Commiting Transaction");
                    session.Transaction.Commit();
                }
            }
            else
            {
                Logger.Debug("Validation Error occured or No active Transanction.");
            }
        }
示例#3
0
        /// <summary>
        /// Befores the processing.
        /// </summary>
        /// <param name="requests">The requests.</param>
        protected override void BeforeProcessing(IEnumerable <Agatha.Common.Request> requests)
        {
            DomainEvent.Register <RuleViolationEvent> (failure => { _validationFailureOccurred = true; });

            var session = _sessionProvider.GetSession();

            session.BeginTransaction();

            base.BeforeProcessing(requests);
        }
        public ICollection <IEmailMessageParticipant> GetParticipants(ICollection <string> email)
        {
            var session = _sessionProvider.GetSession("");

            var emailsString = string.Join(",", email.Select(c => $"'{c.GetDeterministicGuid()}'"));

            // Тут будут все участники писем - контакты и наши полльзователи
            var hqlQuery =
                session.CreateQuery(
                    "select emailParticipant FROM EmailMessageParticipant emailParticipant " +
                    $"where emailParticipant.Uid in ({emailsString})");

            hqlQuery.SetMaxResults(email.Count);
            return(hqlQuery.List <IEmailMessageParticipant>());
        }
示例#5
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.Common.StaffNameDto"/></returns>
        public StaffNameDto CreateKeyedDto(long key)
        {
            var staff = _sessionProvider.GetSession().Get <Staff> (key);
            var dto   = Mapper.Map <Staff, StaffNameDto> (staff);

            return(dto);
        }
示例#6
0
        public ISession OpenSession <TSessionContext>(ISessionProvider provider) where TSessionContext : ISessionContext
        {
            var session = provider.GetSession <TSessionContext>();

            _session = session;
            return(_session);
        }
示例#7
0
        /// <summary>
        /// Gets the imap client.
        /// </summary>
        /// <returns>Imap 4 client.</returns>
        public Imap4Client GetImapClient()
        {
            string imapServer = _configurationPropertiesProvider.GetProperty(SettingKeyNames.ImapServer);
            int    imapPort   = _configurationPropertiesProvider.GetPropertyInt(SettingKeyNames.ImapPort);

            // Retrieves the Current User Context
            UserInformationDto info = _userInformationDtoFactory.CreateUserInformationDto();

            // Retrieves the corresponding Staff record for the current user
            Staff staff = _sessionProvider.GetSession().QueryOver <Staff>().Where(s => s.Key == info.StaffKey).SingleOrDefault();

            //string username = "******";
            //string password = "******";

            string username = null;
            string password = null;

            if (staff.DirectAddressCredential.DirectAddress != null)
            {
                username = staff.DirectAddressCredential.DirectAddress.Address;
                password = staff.DirectAddressCredential.DirectAddressPassword;
            }

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                throw new ApplicationException("Username/password are not provided to access IMAP mail server.");
            }

            var imap4Client = new Imap4Client();

            imap4Client.Connect(imapServer, imapPort, username, password);

            return(imap4Client);
        }
示例#8
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientEditor.PatientVeteranInformationDto"/></returns>
        public PatientVeteranInformationDto CreateKeyedDto(long key)
        {
            var patient = _sessionProvider.GetSession().Get <Patient> (key);
            var dto     = Mapper.Map <Patient, PatientVeteranInformationDto> (patient);

            return(dto);
        }
示例#9
0
        /// <summary>
        /// Creates the user information dto.
        /// </summary>
        /// <returns>A <see cref="UserInformationDto"/></returns>
        public UserInformationDto CreateUserInformationDto()
        {
            var claimsPrincipal = _currentClaimsPrincipalService.GetCurrentPrincipal();
            var permissions     = claimsPrincipal.CurrentPermissions();
            var accountKey      = claimsPrincipal.CurrentAccountKey();
            var staffKey        = claimsPrincipal.CurrentStaffKey();

            UserInformationDto userInformationDto = null;

            var session = _sessionProvider.GetSession();

            var account  = session.Get <SystemAccount> (accountKey);
            var staff    = account.StaffMembers.First(x => x.Key == staffKey);
            var agency   = staff.Agency;
            var location = staff.PrimaryLocation;

            userInformationDto = new UserInformationDto
            {
                AccountKey          = account.Key,
                AccountIdentifier   = account.Identifier,
                AgencyKey           = agency.Key,
                AgencyDisplayName   = agency.AgencyProfile.AgencyName.DisplayName,
                LocationKey         = location == null ? 0 : location.Key,
                LocationDisplayName = location == null ? string.Empty : location.LocationProfile.LocationName.DisplayName,
                StaffKey            = staff.Key,
                StaffFirstName      = staff.StaffProfile.StaffName.First,
                StaffMiddleName     = staff.StaffProfile.StaffName.Middle,
                StaffLastName       = staff.StaffProfile.StaffName.Last,
                DirectEmailAddress  = staff.DirectAddressCredential == null ? null : (staff.DirectAddressCredential.DirectAddress == null? null : staff.DirectAddressCredential.DirectAddress.Address),
                GrantedPermissions  = permissions
            };

            return(userInformationDto);
        }
示例#10
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.Common.PatientAlertDto"/></returns>
        public PatientAlertDto CreateKeyedDto(long key)
        {
            var patientAlert    = _sessionProvider.GetSession().Get <PatientAlert> (key);
            var patientAlertDto = Mapper.Map <PatientAlert, PatientAlertDto> (patientAlert);

            return(patientAlertDto);
        }
示例#11
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.LocationEditor.LocationProfileDto"/></returns>
        public LocationProfileDto CreateKeyedDto(long key)
        {
            var location = _sessionProvider.GetSession().Get <Location> (key);
            var dto      = Mapper.Map <Location, LocationProfileDto> (location);

            return(dto);
        }
示例#12
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.Common.StaffSystemRolesDto"/></returns>
        public StaffSystemRolesDto CreateKeyedDto(long key)
        {
            var staff = _sessionProvider.GetSession().Get <Staff> (key);

            var dto = new StaffSystemRolesDto();

            dto.Key = staff.Key;

            dto.JobFunctionRole =
                Mapper.Map <StaffSystemRole, StaffSystemRoleDto> (
                    staff.SystemRoles
                    .Where(p => p.SystemRole.SystemRoleType == SystemRoleType.JobFunction)
                    .FirstOrDefault());

            dto.TaskGroupRoles =
                new SoftDeleteObservableCollection <StaffSystemRoleDto> (
                    Mapper.Map <IEnumerable <StaffSystemRole>, IEnumerable <StaffSystemRoleDto> > (
                        staff.SystemRoles
                        .Where(p => p.SystemRole.SystemRoleType == SystemRoleType.TaskGroup)));

            dto.TaskRoles =
                new SoftDeleteObservableCollection <StaffSystemRoleDto> (
                    Mapper.Map <IEnumerable <StaffSystemRole>, IEnumerable <StaffSystemRoleDto> > (
                        staff.SystemRoles.Where(p => p.SystemRole.SystemRoleType == SystemRoleType.Task)));

            return(dto);
        }
示例#13
0
        /// <summary>
        /// Handles the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void HandleRequest(GetAvailableProgramsRequest request, GetAvailableProgramsResponse response)
        {
            // Programs in current agency
            // where there exists a program offering
            // where current staff has access to a location
            var session = _sessionProvider.GetSession();

            var staff        = _staffRepository.GetByKey(request.CurrentStaffKey);
            var locationKeys = staff.StaffLocationAssignments
                               .Select(x => x.Location.Key)
                               .ToList();

            var programOfferings = session.Query <ProgramOffering> ()
                                   .Where(x => x.Program.Agency.Key == request.AgencyKey)
                                   .Fetch(x => x.Program)
                                   .ToList();

            var programDics = new Dictionary <long, Program> ();

            programOfferings.ForEach(
                programOffering =>
            {
                if (locationKeys.Contains(programOffering.Location.Key))
                {
                    if (!programDics.ContainsKey(programOffering.Program.Key))
                    {
                        programDics.Add(programOffering.Program.Key, programOffering.Program);
                    }
                }
            });

            var dtos = Mapper.Map <IList <Program>, IList <ProgramDisplayNameDto> > (programDics.Values.ToList());

            response.ProgramDisplayNames = dtos;
        }
示例#14
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.VitalSignDto"/></returns>
        public VitalSignDto CreateKeyedDto(long key)
        {
            var vitalSign = _sessionProvider.GetSession().Get <VitalSign> (key);
            var dto       = Mapper.Map <VitalSign, VitalSignDto> (vitalSign);

            return(dto);
        }
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Returns a Response object.</returns>
        public override Response Handle(SendDirectMessageRequest request)
        {
            var response = CreateTypedResponse();

            var session = _sessionProvider.GetSession();
            var info    = _userInformationDtoFactory.CreateUserInformationDto();
            var staff   = session.QueryOver <Staff>().Where(s => s.Key == info.StaffKey).SingleOrDefault();

            var fromAddress     = staff.DirectAddressCredential.DirectAddress.Address;
            var fromDisplayName = staff.StaffProfile.StaffName.Complete;

            var mailMessageBuilder = new MailMessageBuilder();

            mailMessageBuilder
            .Compose(fromAddress, fromDisplayName, request.ToDirectEmail, string.Empty, request.Subject, request.Body);

            if (request.AttachmentData != null)
            {
                mailMessageBuilder.WithAttachment(request.AttachmentData, request.AttachmentFileName);
            }

            _mailMessageSender.Send(mailMessageBuilder.MailMessage);

            return(response);
        }
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.ClinicalCaseEditor.ClinicalCaseProfileDto"/></returns>
        public ClinicalCaseProfileDto CreateKeyedDto(long key)
        {
            var clinicalCase = _sessionProvider.GetSession().Get <ClinicalCase> (key);
            var dto          = Mapper.Map <ClinicalCase, ClinicalCaseProfileDto> (clinicalCase);

            return(dto);
        }
示例#17
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.ProgramOfferingEditor.ProgramOfferingProfileDto"/></returns>
        public ProgramOfferingProfileDto CreateKeyedDto(long key)
        {
            var location = _sessionProvider.GetSession().Get <ProgramOffering> (key);
            var dto      = Mapper.Map <ProgramOffering, ProgramOfferingProfileDto> (location);

            return(dto);
        }
示例#18
0
        public WebLoginModule(ISessionProvider sessionProvider)
        {
            _sessionProvider = sessionProvider;

            Get["/weblogin"] = parameters => View["web/login.html"];

            Get["/weblogout"] = parameters => this.Logout("/");

            Post["/weblogin"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        string username = Request.Form["UserName"];
                        string password = Request.Form["Password"];

                        var login = session.Query<Login>()
                                           .SingleOrDefault(
                                               x => x.Username == username && x.Password == password);

                        if (login == null)
                            return Response.AsRedirect("/weblogin", RedirectResponse.RedirectType.SeeOther);

                        if(login.Roles.Contains(Roles.SuperAdmin))
                            return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/admin");

                        if (login.Roles.Contains(Roles.ClientAdmin))
                            return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/web/views/livedetails.html?" + login.ClientId);

                        if (login.Roles.Contains(Roles.ClientUser))
                            return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/mobile/views/startup.html");

                        return this.Login(login.AuthenticationKey, fallbackRedirectUrl: "/");
                    }
                };
        }
示例#19
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.Common.StaffCredentialsDto"/></returns>
        public StaffCredentialsDto CreateKeyedDto(long key)
        {
            var staff = _sessionProvider.GetSession().Get <Staff> (key);

            var dto = Mapper.Map <Staff, StaffCredentialsDto> (staff);

            //var staffCollegeDegreeDtos =
            //    Mapper.Map<IList<StaffCollegeDegree>, IList<StaffCollegeDegreeDto>> ( new List<StaffCollegeDegree> ( staff.CollegeDegrees ) );
            //var responseCollegeDegrees = new SoftDeleteObservableCollection<StaffCollegeDegreeDto> ( staffCollegeDegreeDtos );

            //var staffLicenseDtos =
            //    Mapper.Map<IList<StaffLicense>, IList<StaffLicenseDto>>(new List<StaffLicense>(staff.Licenses));
            //var responseLicenses = new SoftDeleteObservableCollection<StaffLicenseDto> ( staffLicenseDtos );

            //var staffCertificationDtos =
            //    Mapper.Map<IList<StaffCertification>, IList<StaffCertificationDto>>(new List<StaffCertification>(staff.Certifications));
            //var responseCertifications = new SoftDeleteObservableCollection<StaffCertificationDto> ( staffCertificationDtos );

            //var staffTrainingCourseDtos =
            //    Mapper.Map<IList<StaffTrainingCourse>, IList<StaffTrainingCourseDto>>(new List<StaffTrainingCourse>(staff.TrainingCourses));
            //var responseTrainingCourses = new SoftDeleteObservableCollection<StaffTrainingCourseDto> ( staffTrainingCourseDtos );

            //var dto = new StaffCredentialsDto
            //              {
            //                  Key = key,
            //                  AgencyKey = staff.Agency.Key,
            //                  CollegeDegrees = responseCollegeDegrees,
            //                  Licenses = responseLicenses,
            //                  Certifications = responseCertifications,
            //                  TrainingCourses = responseTrainingCourses
            //              };

            return(dto);
        }
示例#20
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.NidaDrugQuestionnaireDto"/></returns>
        public NidaDrugQuestionnaireDto CreateKeyedDto(long key)
        {
            var NidaDrugQuestionnaire = _sessionProvider.GetSession().Get <NidaDrugQuestionnaire> (key);

            var dto = Mapper.Map <NidaDrugQuestionnaire, NidaDrugQuestionnaireDto> (NidaDrugQuestionnaire);

            return(dto);
        }
示例#21
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.AgencyModule.Web.Common.StaffProfileDto"/></returns>
        public StaffProfileDto CreateKeyedDto(long key)
        {
            var patient = _sessionProvider.GetSession().Get <Staff> (key);

            var dto = Mapper.Map <Staff, StaffProfileDto> (patient);

            return(dto);
        }
示例#22
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key to create.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.ClinicalCaseEditor.ClinicalCaseDischargeDto"/></returns>
        public ClinicalCaseDischargeDto CreateKeyedDto(long key)
        {
            var clinicalCase = _sessionProvider.GetSession().Get <ClinicalCase> (key);
            var dto          = Mapper.Map <ClinicalCaseDischarge, ClinicalCaseDischargeDto> (clinicalCase.ClinicalCaseDischarge);

            dto.Key = clinicalCase.Key;
            return(dto);
        }
示例#23
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.RadiologyOrderDto"/></returns>
        public RadiologyOrderDto CreateKeyedDto(long key)
        {
            var entity = _sessionProvider.GetSession().Get <RadiologyOrder> (key);

            var dto = Mapper.Map <RadiologyOrder, RadiologyOrderDto> (entity);

            return(dto);
        }
示例#24
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.Dast10Dto"/></returns>
        public Dast10Dto CreateKeyedDto(long key)
        {
            var dast10 = _sessionProvider.GetSession().Get <Dast10> (key);

            var dto = Mapper.Map <Dast10, Dast10Dto> (dast10);

            return(dto);
        }
示例#25
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.BriefInterventionDto"/></returns>
        public BriefInterventionDto CreateKeyedDto(long key)
        {
            var briefIntervention = _sessionProvider.GetSession().Get <BriefIntervention> (key);

            var dto = Mapper.Map <BriefIntervention, BriefInterventionDto> (briefIntervention);

            return(dto);
        }
示例#26
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.BillingModule.Web.Common.BillingOfficeSummaryDto"/></returns>
        public BillingOfficeSummaryDto CreateKeyedDto(long key)
        {
            var entity = _sessionProvider.GetSession().Get <BillingOffice> (key);

            var dto = Mapper.Map <BillingOffice, BillingOfficeSummaryDto> (entity);

            return(dto);
        }
示例#27
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.IndividualCounselingDto"/></returns>
        public IndividualCounselingDto CreateKeyedDto(long key)
        {
            var individualCounseling = _sessionProvider.GetSession().Get <IndividualCounseling> (key);

            var dto = Mapper.Map <IndividualCounseling, IndividualCounselingDto> (individualCounseling);

            return(dto);
        }
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.Common.PatientLegalStatusDto"/></returns>
        public PatientLegalStatusDto CreateKeyedDto(long key)
        {
            var patient = _sessionProvider.GetSession().Get <Patient> (key);

            var dto = Mapper.Map <Patient, PatientLegalStatusDto> (patient);

            return(dto);
        }
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.FrontDeskDashboard.AppointmentDetailsDto"/></returns>
        public AppointmentDetailsDto CreateKeyedDto(long key)
        {
            var entity = _sessionProvider.GetSession().Get <Visit> (key);

            var dto = Mapper.Map <Visit, AppointmentDetailsDto> (entity);

            return(dto);
        }
示例#30
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>A data transfer object.</returns>
        public TDto CreateKeyedDto(long key)
        {
            var entity = _sessionProvider.GetSession().Get <TEntity> (key);

            TDto dto = HandleMapping(entity);

            return(dto);
        }
示例#31
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.PatientDashboard.AuditCDto"/></returns>
        public AuditCDto CreateKeyedDto(long key)
        {
            var auditC = _sessionProvider.GetSession().Get <AuditC> (key);

            var dto = Mapper.Map <AuditC, AuditCDto> (auditC);

            return(dto);
        }
示例#32
0
        /// <summary>
        /// Creates the keyed dto.
        /// </summary>
        /// <param name="key">The key of the object.</param>
        /// <returns>A <see cref="Rem.Ria.PatientModule.Web.Common.PatientDemographicDetailsDto"/></returns>
        public PatientDemographicDetailsDto CreateKeyedDto(long key)
        {
            var patient = _sessionProvider.GetSession().Get <Patient> (key);

            var dto = Mapper.Map <Patient, PatientDemographicDetailsDto> (patient);

            return(dto);
        }
示例#33
0
        /// <summary>
        /// Initializes the unit of work.
        /// </summary>
        protected UnitOfWorkBase(bool createTransaction, ISessionProvider sessionProvider)
        {
            _session = sessionProvider.GetSession();

            if (createTransaction)
            {
                Session.BeginTransaction();
                _transactionStarted = true;
            }
        }
示例#34
0
        protected RavenModule(ISessionProvider sessionProvider, IDispatchEvents eventDispatcher, string modulePath)
            : base(modulePath)
        {
            _eventDispatcher = eventDispatcher;
            this.RequiresAuthentication();
            this.RequiresAnyClaim(new[] { "SuperAdmin", "ClientAdmin", "ClientUser" });

            Before += ctx =>
                {
                    ClientId = string.Format("clients/{0}", ctx.Parameters["id"]);
                    UncommitedEvents = new List<EventBase>();

                    if (ctx.CurrentUser.Claims.Any(x => x == "ClientAdmin"))
                    {
                        var seerefineIdentity = ctx.CurrentUser as SeerefineIdentity;
                        if (seerefineIdentity == null)
                            return HttpStatusCode.Unauthorized;

                        if (seerefineIdentity.ClientId != ClientId)
                            return HttpStatusCode.Unauthorized;

                    }

                    RavenSession = sessionProvider.GetSession();
                    return null;
                };

            After += ctx =>
                {
                    if (RavenSession != null)
                    {
                        if(RavenSession.Advanced.HasChanges)
                            RavenSession.SaveChanges();

                        RavenSession.Dispose();

                        if (UncommitedEvents.Any())
                            _eventDispatcher.Dispatch(UncommitedEvents.ToArray());
                    }
                };

            OnError += (ctx, ex) =>
                {
                    Trace.TraceError(ex.ToString());

                    if (ex is ConcurrencyException)
                    {
                        return Response.Conflict(ex.Message);
                    }

                    return HttpStatusCode.InternalServerError;
                };
        }
        public DefinitionCreatorFactory(ISessionProvider sessionProvider)
        {
            if (sessionProvider == null) throw new ArgumentNullException(nameof(sessionProvider));
            _session = sessionProvider.GetSession();
            _transaction = _session.BeginTransaction();

            var definitionCreator = new DefinitionCreator(_session);
            var productDefinitionCreator = new ProductDefinitionCreator(_session);
            var dataTypeCreator = new DataTypeCreator(_session);

            _definitionCreators = new Dictionary<BuiltInDefinitionType, ICreator>
            {
                { BuiltInDefinitionType.CampaignItem, definitionCreator },
                { BuiltInDefinitionType.Category, definitionCreator },
                { BuiltInDefinitionType.PaymentMethod, definitionCreator },
                { BuiltInDefinitionType.Product, productDefinitionCreator },
                { BuiltInDefinitionType.DataType, dataTypeCreator }
            };
        }
示例#36
0
        public LoginsModule(ISessionProvider sessionProvider)
            : base("/admin/logins")
        {
            _sessionProvider = sessionProvider;

            this.RequiresAuthentication();
            this.RequiresClaims(new[] { "SuperAdmin" });

            Get["/create"] = parameters => View["views/admin/_createLogin.html"];

            Get["/list"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        var accounts = session.Query<Login>()
                                              .Where(x => x.Roles.Contains(Roles.SuperAdmin))
                                              .ToList();

                        return Response.AsJson(accounts);
                    }
                };

            Post["/create"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        session.Advanced.UseOptimisticConcurrency = true;

                        var command = this.Bind<CreateLoginCommand>();

                        if (command.AuthenticationKey == Guid.Empty)
                            command.AuthenticationKey = Guid.NewGuid();

                        session.Store(new Login
                            {
                                AuthenticationKey = command.AuthenticationKey,
                                Username = command.UserName,
                                Password = command.Password,
                                Roles = new List<Roles> {Roles.SuperAdmin},
                            });

                        session.Store(new UserNameAndPasswordIsUnique
                            {
                                Id = command.ToUniqueString(),
                                AuthenticationKey = command.AuthenticationKey,
                            });

                        session.SaveChanges();
                    }
                    return HttpStatusCode.NoContent;
                };
        }
示例#37
0
        public AdminClientModule(ISessionProvider sessionProvider)
            : base("/admin/clients")
        {
            this.RequiresAuthentication();
            this.RequiresClaims(new[] { "SuperAdmin" });

            _sessionProvider = sessionProvider;

            Get["/create"] = parameters => View["views/admin/_createClient.html"];

            Get["/{id}"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        var client = session.Load<Client>(int.Parse(parameters.id));
                        if (client == null)
                            return HttpStatusCode.NotFound;

                        return View["views/admin/showclient.html", client];
                    }
                };

            Get["/{id}/admins/list"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        string clientId = string.Format("clients/{0}", parameters.id);

                        var logins = session.Query<Login>()
                                            .Where(x => x.Roles.Contains(Roles.ClientAdmin) && x.ClientId == clientId)
                                            .ToList();

                        return Response.AsJson(logins);
                    }
                };

            Get["/{id}/createadmin"] = parameters => View["views/admin/_createClientAdmin.html", new {ClientId = parameters.id}];

            Post["/{id}/createadmin"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        session.Advanced.UseOptimisticConcurrency = true;

                        var command = this.Bind<CreateLoginCommand>();

                        if (command.AuthenticationKey == Guid.Empty)
                            command.AuthenticationKey = Guid.NewGuid();

                        session.Store(new Login
                            {
                                AuthenticationKey = command.AuthenticationKey,
                                ClientId = string.Format("clients/{0}", parameters.id),
                                Username = command.UserName,
                                Password = command.Password,
                                Roles = new List<Roles> {Roles.ClientAdmin},
                            });

                        session.Store(new UserNameAndPasswordIsUnique
                            {
                                Id = command.ToUniqueString(),
                                AuthenticationKey = command.AuthenticationKey,
                            });

                        session.SaveChanges();
                    }
                    return HttpStatusCode.NoContent;
                };

            Get["/list"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        var clients = session.Query<Client>().ToArray();
                        return Response.AsJson(clients);
                    }
                };

            Post["/create"] = parameters =>
                {
                    using (var session = _sessionProvider.GetSession())
                    {
                        session.Store(new Client
                            {
                                Name = Request.Form["ClientName"],
                            });
                        session.SaveChanges();
                    }
                    return HttpStatusCode.NoContent;
                };
        }
示例#38
0
        public DefaultSession(ISessionProvider sessionProvider, ISessionIdProvider sessionIdProvider)
        {
            sessionId = sessionIdProvider.Get();

            entries = sessionProvider.GetSession(sessionId);
        }
示例#39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NcsCriptBuilder"/> class.
 /// </summary>
 /// <param name="configProvider">The config provider.</param>
 /// <param name="sessionProvider">The session provider.</param>
 public NcsCriptBuilder( IConfigurationPropertiesProvider configProvider, ISessionProvider sessionProvider )
 {
     _configProvider = configProvider;
     _session = sessionProvider.GetSession ();
 }