protected override object Run(CajaConsolidadoGet request) { DateTime desde = request.Desde == default(DateTime) ? DateTime.Today.AddDays(-8): request.Desde; DateTime hasta = request.Hasta == default(DateTime) ? DateTime.Today.AddDays(-2): request.Hasta; var consolidado = DbFactory.CajaConsolidado(desde, hasta); var detalles = DbFactory.DeCajasClasificacion(desde, hasta, true); var response = new CajaConsolidadoGetResponse() { Success = true, HtmlResponse = consolidado.ToHtml(desde, hasta) + "<br/>" + detalles.PagosToHtml() + "<br/>" + detalles.AnticiposToHtml() }; if (request.SendMail) { var uc = DbFactory.UsuariosCorreos("EstadoResultados.Consultar"). Where(r => !r.Correo.IsNullOrEmpty()).ToList(); if (uc.Count > 0) { Mail = new Mailer(Config); foreach (var r in uc) { Mail.Message.To.Add(r.Correo); } Mail.Message.Subject = string.Format("Estado de Resultados. Del {0} al {1}", desde.ToString("dd.MM.yyyy"), hasta.ToString("dd.MM.yyyy")); Mail.Message.IsBodyHtml = true; Mail.Message.Body = response.HtmlResponse; Mail.Send(); Mail.Message.To.Clear(); } } return(response); //return new HttpResult(response, "text/html"); }
public static void Main(string[] args) { string tipo; DateTime desde; DateTime hasta; DateTime hoy = DateTime.Today; if (args.Length > 0) { tipo = args[0].ToUpper(); } else { tipo = "SEMANAL"; } if (tipo == "SEMANAL") { desde = hoy.AddDays(-8); hasta = hoy.AddDays(-2); } else if (tipo == "MENSUAL") { int mes = hoy.Month > 1 ? hoy.Month - 1: 12; int anio = hoy.Month > 1? hoy.Year: hoy.Year - 1; desde = new DateTime(anio, mes, 1); hasta = new DateTime(anio, mes, DateTime.DaysInMonth(anio, mes)); } else { Console.WriteLine("uso mono EstadoResultados.exe SEMANAL\nuso mono EstadoResultados.exe MENSUAL"); return; } string url = "http://localhost/autenticacion"; string urlServicio = "http://localhost/servicio"; using (JsonServiceClient client = new JsonServiceClient(url)) { //var request = new LoginData { UserName="******", Password="******" }; var request = new LoginData { UserName = "******", Password = "******" }; var response = client.Send <LoginResponse>(request); if (!response.Success) { Console.WriteLine(response.ResponseStatus.Message); return; } using (JsonServiceClient cl = new JsonServiceClient(urlServicio)) { CajaConsolidadoGet er = new CajaConsolidadoGet() { Desde = desde, Hasta = hasta, SessionId = response.Id, SendMail = true, }; CajaConsolidadoGetResponse r = cl.Send <CajaConsolidadoGetResponse>(er); if (!r.Success) { Console.WriteLine(r.ResponseStatus.Message); } LogoutData lo = new LogoutData() { SessionId = response.Id }; client.Send <LogoutResponse>(lo); } } Console.WriteLine("This is The End my friend"); }