events refactoring

This commit is contained in:
2016-09-17 03:36:34 +02:00
parent 1882138e61
commit 83b3d2d2ae
13 changed files with 98 additions and 89 deletions

View File

@ -60,7 +60,6 @@ namespace Yavsc.Controllers
.Include(x => x.PerformerProfile) .Include(x => x.PerformerProfile)
.Include(x => x.PerformerProfile.Performer) .Include(x => x.PerformerProfile.Performer)
.Include(x => x.Location) .Include(x => x.Location)
.Include(x => x.Bill)
.Where(x=> x.ClientId == uid || x.PerformerId == uid) .Where(x=> x.ClientId == uid || x.PerformerId == uid)
.ToList()); .ToList());
} }
@ -135,6 +134,7 @@ namespace Yavsc.Controllers
.FirstOrDefault( .FirstOrDefault(
x => x.PerformerId == command.PerformerId x => x.PerformerId == command.PerformerId
); );
_logger.LogDebug($"Pro: {pro}");
command.PerformerProfile = pro; command.PerformerProfile = pro;
var user = await _userManager.FindByIdAsync( var user = await _userManager.FindByIdAsync(
User.GetUserId() User.GetUserId()
@ -162,7 +162,7 @@ namespace Yavsc.Controllers
var regids = command.PerformerProfile.Performer var regids = command.PerformerProfile.Performer
.Devices.Select(d => d.GCMRegistrationId); .Devices.Select(d => d.GCMRegistrationId);
var sregids = string.Join(",",regids); var sregids = string.Join(",",regids);
grep = await _GCMSender.NotifyAsync(_googleSettings,regids,yaev); grep = await _GCMSender.NotifyBookQueryAsync(_googleSettings,regids,yaev);
} }
// TODO setup a profile choice to allow notifications // TODO setup a profile choice to allow notifications
// both on mailbox and mobile // both on mailbox and mobile
@ -174,8 +174,8 @@ namespace Yavsc.Controllers
await _emailSender.SendEmailAsync( await _emailSender.SendEmailAsync(
_siteSettings, _smtpSettings, _siteSettings, _smtpSettings,
command.PerformerProfile.Performer.Email, command.PerformerProfile.Performer.Email,
yaev.Title, yaev.Topic+" "+yaev.Client.UserName,
$"{yaev.Description}\r\n-- \r\n{yaev.Comment}\r\n" $"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n"
); );
} }
ViewBag.GoogleSettings = _googleSettings; ViewBag.GoogleSettings = _googleSettings;

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Yavsc.Model;
using Yavsc.Models.Booking; using Yavsc.Models.Booking;
using Yavsc.Models.Messaging; using Yavsc.Models.Messaging;
@ -11,17 +12,14 @@ namespace Yavsc.Helpers
{ {
var yaev = new BookQueryEvent var yaev = new BookQueryEvent
{ {
Title = query.Client.UserName + " "+ SR["is asking you for a date"]+".", Client = new ClientProviderView { UserName = query.Client.UserName , UserId = query.ClientId } ,
Comment = (query.Previsional != null) ? Previsional = query.Previsional,
SR["Deposit"] + string.Format(": {0:00}", EventDate = query.EventDate,
query.Previsional) : SR["No deposit."],
Description = SR["Address"] + ": " + query.Location.Address + "\n" +
SR["Date"] + ": " + query.EventDate.ToString("D"),
StartDate = query.EventDate,
Location = query.Location, Location = query.Location,
CommandId = query.Id Id = query.Id
}; };
return yaev; return yaev;
} }
} }
} }

View File

@ -21,11 +21,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Newtonsoft.Json.Linq;
using Yavsc.Models; using Yavsc.Models;
using Yavsc.Models.Auth; using Yavsc.Models.Auth;
using Yavsc.Models.Google.Messaging; using Yavsc.Models.Google.Messaging;
@ -37,7 +34,7 @@ namespace Yavsc.Helpers
/// </summary> /// </summary>
public static class GoogleHelpers public static class GoogleHelpers
{ {
/* WAZA
/// <summary> /// <summary>
/// Notifies the event. /// Notifies the event.
/// </summary> /// </summary>
@ -70,18 +67,17 @@ namespace Yavsc.Helpers
var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
return payload.Value<MessageWithPayloadResponse>(); return payload.Value<MessageWithPayloadResponse>();
} }
*/
public static MessageWithPayloadResponse NotifyEvent<Event> public static MessageWithPayloadResponse NotifyEvent<Event>
(this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev) (this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
where Event : YaEvent where Event : IEvent
{ {
var msg = new MessageWithPayload<Event>() var msg = new MessageWithPayload<Event>()
{ {
notification = new Notification() notification = new Notification()
{ {
title = ev.Title, title = ev.Topic+" "+ev.Sender,
body = ev.Description + ev.Comment == null ? body = ev.Message,
"" : "(" + ev.Comment + ")",
icon = "icon" icon = "icon"
}, },
data = ev, data = ev,

View File

@ -0,0 +1,14 @@
public interface IEvent {
/// <summary>
/// An acceptable topic for this event to be.
/// Should return something like the class name
/// of this object
/// </summary>
/// <returns></returns>
string Topic { get; set ; }
string Sender { get; set ; }
string Message { get; set; }
}

View File

@ -18,29 +18,22 @@ namespace Yavsc.Models.Booking
[Display(Name="Event date")] [Display(Name="Event date")]
public DateTime EventDate{ public DateTime EventDate{
get get;
{ return ((RendezVous)Bill[0]).EventDate; } set;
set { ((RendezVous)Bill[0]).EventDate = value; }
} }
public Location Location { public Location Location {
get get;
{ return ((RendezVous)Bill[0]).Location; } set;
set { ((RendezVous)Bill[0]).Location = value; }} }
public BookQuery() public BookQuery()
{ {
this.Bill.Add(new RendezVous());
} }
public BookQuery(Location eventLocation, DateTime eventDate) public BookQuery(Location eventLocation, DateTime eventDate)
{ {
this.Bill.Add(new RendezVous{ Location = eventLocation;
Location = eventLocation, EventDate = eventDate;
EventDate = eventDate
});
}
public string GetDescription() {
return $"{Location?.Address} {EventDate.ToString()}";
} }
} }
} }

View File

@ -30,13 +30,6 @@ namespace Yavsc.Models.Calendar
/// Provided event. /// Provided event.
/// </summary> /// </summary>
public class ProvidedEvent : YaEvent { public class ProvidedEvent : YaEvent {
public ProvidedEvent(string topic) : base(topic)
{
}
/// <summary> /// <summary>
/// The privacy. /// The privacy.
/// </summary> /// </summary>

View File

@ -27,7 +27,23 @@ namespace Yavsc.Models.Messaging
/// <summary> /// <summary>
/// Base event. /// Base event.
/// </summary> /// </summary>
public class BaseEvent: ITitle
public class BaseEvent : IEvent {
public BaseEvent()
{
Topic = GetType().Name;
}
public BaseEvent(string topic)
{
Topic = topic;
}
public string Topic { get; set; }
public string Sender { get; set; }
public string Message { get; set; }
}
public class GeneralEvent: BaseEvent, ITitle
{ {
/// <summary> /// <summary>
/// The title. /// The title.

View File

@ -1,8 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Yavsc.Models.Messaging namespace Yavsc.Models.Messaging
{ {
using Yavsc.Model;
// //
// BookQueryEvent.cs // BookQueryEvent.cs
@ -25,31 +24,27 @@ namespace Yavsc.Models.Messaging
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
public class BookQueryEvent: YaEvent public class BookQueryEvent: BookQueryProviderView, IEvent
{ {
public BookQueryEvent() : base("BookQuery") public BookQueryEvent()
{ {
Topic = "BookQuery";
} }
/// <summary>
/// The location.
/// </summary>
[Display(Name="Location")]
public Location Location { get; set; }
/// <summary>
/// The start date.
/// </summary>
[Display(Name="StartDate")]
public DateTime StartDate { get; set; }
/// <summary> public string Message
/// Gets or sets the end date. {
/// </summary> get; set;
/// <value>The end date.</value> }
[Display(Name="EndDate")]
public DateTime EndDate { get; set; }
public long CommandId { get; set; } public string Sender
{
get; set;
}
public string Topic
{
get; set;
}
} }
} }

View File

@ -29,11 +29,6 @@ namespace Yavsc.Models.Messaging
/// </summary> /// </summary>
public class CircleEvent: YaEvent public class CircleEvent: YaEvent
{ {
public CircleEvent(string topic) : base(topic)
{
}
/// <summary> /// <summary>
/// Gets or sets the circles. /// Gets or sets the circles.
/// </summary> /// </summary>

View File

@ -0,0 +1,21 @@
using System;
namespace Yavsc.Model
{
public class BookQueryProviderView { 
public ClientProviderView Client { get; set; }
public Location Location { get; set; }
public long Id { get; set; }
public DateTime EventDate { get ; set; }
public decimal? Previsional { get; set; }
}
public class ClientProviderView { 
public string UserName { get; set; }
public string UserId { get; set; }
public int Rate { get; set; }
}
}

View File

@ -28,24 +28,12 @@ namespace Yavsc.Models.Messaging
/// </summary> /// </summary>
public class YaEvent : BaseEvent public class YaEvent : BaseEvent
{ {
public YaEvent(string topic)
{
Topic = topic;
}
/// <summary>
/// The topic.
/// </summary>
public string Topic { get; set; }
/// <summary> /// <summary>
/// The NF provider identifier. /// The NF provider identifier.
/// </summary> /// </summary>
[Display(Name="ProviderId")] [Display(Name="From")]
public string ProviderId { get; set; } public string FromUserName { get; set; }
/// <summary>
/// The promotion code.
/// </summary>
[Display(Name="Comment")]
public string Comment { get; set; }
/// <summary> /// <summary>
/// The event web page. /// The event web page.
/// </summary> /// </summary>

View File

@ -8,6 +8,6 @@ namespace Yavsc.Services
{ {
public interface IGoogleCloudMessageSender public interface IGoogleCloudMessageSender
{ {
Task<MessageWithPayloadResponse> NotifyAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, YaEvent ev); Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, BookQueryEvent ev);
} }
} }

View File

@ -28,11 +28,11 @@ namespace Yavsc.Services
/// <c>bool somethingsent = (response.failure == 0 &amp;&amp; response.success > 0)</c> /// <c>bool somethingsent = (response.failure == 0 &amp;&amp; response.success > 0)</c>
/// </returns> /// </returns>
public async Task<MessageWithPayloadResponse> public async Task<MessageWithPayloadResponse>
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev) NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
{ {
MessageWithPayloadResponse response = null; MessageWithPayloadResponse response = null;
await Task.Run(()=>{ await Task.Run(()=>{
response = googleSettings.NotifyEvent(registrationIds, ev); response = googleSettings.NotifyEvent<BookQueryEvent>(registrationIds, ev);
}); });
return response; return response;
} }