Пример #1
0
		void ConfigureApp(Container container){

			var appSettings = new ConfigurationResourceManager();
                    
            double se= appSettings.Get("DefaultSessionExpiry", 480);
            AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);         
                                   
            string cacheHost= appSettings.Get("REDISTOGO_URL","localhost:6379").Replace("redis://redistogo-appharbor:","").Replace("/","");

            var redisClientManager = new BasicRedisClientManager(new string[]{cacheHost});
            
			OrmLiteConfig.DialectProvider= MySqlDialectProvider.Instance;
            
            IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(
                ConfigUtils.GetConnectionString("ApplicationDb"));
            
			var factory = new Factory(){
                DbFactory=dbFactory,
                RedisClientsManager = redisClientManager
			};

			var empresa = factory.Execute(proxy=>{
				return proxy.GetEmpresa();
			});

			var mailer = new Mailer(empresa);

			Channel channel = new Channel(empresa.PublishKey,
			                              empresa.SubscribeKey, empresa.SecretKey,"",false);

				
			container.Register(channel);
            container.Register(new AppConfig(appSettings){MailLogToken=empresa.MailLogToken});
            container.Register<Factory>(factory);
			container.Register(mailer);
            //container.Register<ICacheClient>(new MemoryCacheClient { FlushOnDispose = false });
            container.Register<IRedisClientsManager>(c => redisClientManager);
                        
            Plugins.Add(new AuthFeature(
                 () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                new IAuthProvider[]
            {
                new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}

            })
            {
                IncludeAssignRoleServices=false, 
            });
                            
            
            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(
                dbFactory
            );
            
            container.Register<IUserAuthRepository>(
                c => authRepo
            ); 

            
            if(appSettings.Get("EnableRegistrationFeature", false))
                Plugins.Add( new  RegistrationFeature());
						
		}
Пример #2
0
        public static Response<PedidoMail> Get(this PedidoMail request,
		                                     Factory factory,
		                                     IHttpRequest httpRequest,
		                                     Mailer mailService,
		                                     User user)
        {

			return factory.Execute(proxy=>{
				Pedido pedido= proxy.FirstOrDefault<Pedido>(q=>q.Consecutivo==request.Consecutivo);
				if (pedido==default(Pedido))
				{
					throw HttpError.NotFound(string.Format("No existe Oferta con Consecutivo: '{0}'", request.Consecutivo));
				}

				if(!pedido.FechaEnvio.HasValue)
				{
					throw HttpError.Unauthorized(
						string.Format("Oferta con Consecutivo:'{0}' No esta en estado ENVIADA", request.Consecutivo));
				}

				List<PedidoItem> items=
					proxy.Get<PedidoItem>(q=>q.IdPedido==pedido.Id).OrderBy(f=>f.Id).ToList();
					//proxy.Get<PedidoItem>(q=>q.IdPedido==pedido.Id).OrderBy(f=>f.IdServicio).ToList();


				var oferta = new OfertaHtml();
				User sendBy= new User();  // el que lo envio !!!

				if(user.Id !=pedido.IdEnviadoPor){
					sendBy= proxy.FirstOrDefault<User>(q=>q.Id==pedido.IdEnviadoPor);
					if(sendBy==default(User)){
						user = new User(){
							FirstName="indefinido",
							LastName="indefinido"
						};

					}
				}
				else{
					sendBy.PopulateWith(user);
				}
				var empresa = proxy.GetEmpresa(); 

				var html = oferta.ConstruirHtmlReport(empresa,
				                                      user,
				                                      pedido,
				                                      items,
				                                      request.TextoInicial);

				MailMessage message = new MailMessage();
				message.Subject=  !request.Asunto.IsNullOrEmpty()?
					request.Asunto:
						string.Format("Envio Oferta No:{0}", pedido.Consecutivo.ToString().PadLeft(8,'0'));

				message.ReplyToList.Add(user.Email);
				message.From= new MailAddress(user.Email);

				var mc= !pedido.MailContacto.IsNullOrEmpty()?pedido.MailContacto:user.Email;

				message.To.Add(mc);

				if(! pedido.MailDestinatario.IsNullOrEmpty() &&

				   (mc.Trim().ToUpper()!=pedido.MailDestinatario.Trim().ToUpper()) ){
					message.CC.Add(pedido.MailDestinatario);
				}

				message.Bcc.Add(user.Email);

				if(!empresa.ApplicationMailBox.IsNullOrEmpty()){
					message.Bcc.Add(empresa.ApplicationMailBox);
				}

				message.Body= html;
				message.IsBodyHtml=true;

				OfertaPdf pdf = new OfertaPdf(httpRequest.ApplicationFilePath);

				string logo = Path.Combine(Path.Combine(httpRequest.ApplicationFilePath, "resources"), "logo.png");

				using (var stream =  new MemoryStream() ){
					pdf.CreatePDF(empresa,user,pedido,items,logo,"CMK-S", 
			              stream, new OfertaMargin(5,5,90,15));
					stream.Position=0;
					message.Attachments.Add(new Attachment(stream,string.Format("oferta-{0}.pdf",pedido.Consecutivo)));
					mailService.Send(message);
				}


				return new Response<PedidoMail>(); 

			});


		}