events refactoring
This commit is contained in:
@ -60,7 +60,6 @@ namespace Yavsc.Controllers
|
||||
.Include(x => x.PerformerProfile)
|
||||
.Include(x => x.PerformerProfile.Performer)
|
||||
.Include(x => x.Location)
|
||||
.Include(x => x.Bill)
|
||||
.Where(x=> x.ClientId == uid || x.PerformerId == uid)
|
||||
.ToList());
|
||||
}
|
||||
@ -135,6 +134,7 @@ namespace Yavsc.Controllers
|
||||
.FirstOrDefault(
|
||||
x => x.PerformerId == command.PerformerId
|
||||
);
|
||||
_logger.LogDebug($"Pro: {pro}");
|
||||
command.PerformerProfile = pro;
|
||||
var user = await _userManager.FindByIdAsync(
|
||||
User.GetUserId()
|
||||
@ -162,7 +162,7 @@ namespace Yavsc.Controllers
|
||||
var regids = command.PerformerProfile.Performer
|
||||
.Devices.Select(d => d.GCMRegistrationId);
|
||||
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
|
||||
// both on mailbox and mobile
|
||||
@ -174,8 +174,8 @@ namespace Yavsc.Controllers
|
||||
await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
yaev.Title,
|
||||
$"{yaev.Description}\r\n-- \r\n{yaev.Comment}\r\n"
|
||||
yaev.Topic+" "+yaev.Client.UserName,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n"
|
||||
);
|
||||
}
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models.Booking;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
@ -11,17 +12,14 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
var yaev = new BookQueryEvent
|
||||
{
|
||||
Title = query.Client.UserName + " "+ SR["is asking you for a date"]+".",
|
||||
Comment = (query.Previsional != null) ?
|
||||
SR["Deposit"] + string.Format(": {0:00}",
|
||||
query.Previsional) : SR["No deposit."],
|
||||
Description = SR["Address"] + ": " + query.Location.Address + "\n" +
|
||||
SR["Date"] + ": " + query.EventDate.ToString("D"),
|
||||
StartDate = query.EventDate,
|
||||
Client = new ClientProviderView { UserName = query.Client.UserName , UserId = query.ClientId } ,
|
||||
Previsional = query.Previsional,
|
||||
EventDate = query.EventDate,
|
||||
Location = query.Location,
|
||||
CommandId = query.Id
|
||||
Id = query.Id
|
||||
};
|
||||
return yaev;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Auth;
|
||||
using Yavsc.Models.Google.Messaging;
|
||||
@ -37,7 +34,7 @@ namespace Yavsc.Helpers
|
||||
/// </summary>
|
||||
public static class GoogleHelpers
|
||||
{
|
||||
|
||||
/* WAZA
|
||||
/// <summary>
|
||||
/// Notifies the event.
|
||||
/// </summary>
|
||||
@ -70,18 +67,17 @@ namespace Yavsc.Helpers
|
||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
return payload.Value<MessageWithPayloadResponse>();
|
||||
}
|
||||
|
||||
*/
|
||||
public static MessageWithPayloadResponse NotifyEvent<Event>
|
||||
(this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
|
||||
where Event : YaEvent
|
||||
where Event : IEvent
|
||||
{
|
||||
var msg = new MessageWithPayload<Event>()
|
||||
{
|
||||
notification = new Notification()
|
||||
{
|
||||
title = ev.Title,
|
||||
body = ev.Description + ev.Comment == null ?
|
||||
"" : "(" + ev.Comment + ")",
|
||||
title = ev.Topic+" "+ev.Sender,
|
||||
body = ev.Message,
|
||||
icon = "icon"
|
||||
},
|
||||
data = ev,
|
||||
|
14
Yavsc/Interfaces/IEvent.cs
Normal file
14
Yavsc/Interfaces/IEvent.cs
Normal 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; }
|
||||
}
|
@ -18,29 +18,22 @@ namespace Yavsc.Models.Booking
|
||||
|
||||
[Display(Name="Event date")]
|
||||
public DateTime EventDate{
|
||||
get
|
||||
{ return ((RendezVous)Bill[0]).EventDate; }
|
||||
set { ((RendezVous)Bill[0]).EventDate = value; }
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Location Location {
|
||||
get
|
||||
{ return ((RendezVous)Bill[0]).Location; }
|
||||
set { ((RendezVous)Bill[0]).Location = value; }}
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public BookQuery()
|
||||
{
|
||||
this.Bill.Add(new RendezVous());
|
||||
}
|
||||
|
||||
public BookQuery(Location eventLocation, DateTime eventDate)
|
||||
{
|
||||
this.Bill.Add(new RendezVous{
|
||||
Location = eventLocation,
|
||||
EventDate = eventDate
|
||||
});
|
||||
}
|
||||
public string GetDescription() {
|
||||
return $"{Location?.Address} {EventDate.ToString()}";
|
||||
Location = eventLocation;
|
||||
EventDate = eventDate;
|
||||
}
|
||||
}
|
||||
}
|
@ -30,13 +30,6 @@ namespace Yavsc.Models.Calendar
|
||||
/// Provided event.
|
||||
/// </summary>
|
||||
public class ProvidedEvent : YaEvent {
|
||||
|
||||
public ProvidedEvent(string topic) : base(topic)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The privacy.
|
||||
/// </summary>
|
||||
|
@ -27,7 +27,23 @@ namespace Yavsc.Models.Messaging
|
||||
/// <summary>
|
||||
/// Base event.
|
||||
/// </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>
|
||||
/// The title.
|
||||
|
@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
using Yavsc.Model;
|
||||
|
||||
//
|
||||
// BookQueryEvent.cs
|
||||
@ -25,31 +24,27 @@ namespace Yavsc.Models.Messaging
|
||||
// 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/>.
|
||||
|
||||
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>
|
||||
/// Gets or sets the end date.
|
||||
/// </summary>
|
||||
/// <value>The end date.</value>
|
||||
[Display(Name="EndDate")]
|
||||
public DateTime EndDate { get; set; }
|
||||
public string Message
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public long CommandId { get; set; }
|
||||
}
|
||||
public string Sender
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Topic
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,11 +29,6 @@ namespace Yavsc.Models.Messaging
|
||||
/// </summary>
|
||||
public class CircleEvent: YaEvent
|
||||
{
|
||||
public CircleEvent(string topic) : base(topic)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the circles.
|
||||
/// </summary>
|
||||
|
21
Yavsc/Model/Messaging/ClientProviderInfo.cs
Normal file
21
Yavsc/Model/Messaging/ClientProviderInfo.cs
Normal 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; }
|
||||
}
|
||||
|
||||
}
|
@ -28,24 +28,12 @@ namespace Yavsc.Models.Messaging
|
||||
/// </summary>
|
||||
public class YaEvent : BaseEvent
|
||||
{
|
||||
public YaEvent(string topic)
|
||||
{
|
||||
Topic = topic;
|
||||
}
|
||||
/// <summary>
|
||||
/// The topic.
|
||||
/// </summary>
|
||||
public string Topic { get; set; }
|
||||
/// <summary>
|
||||
/// The NF provider identifier.
|
||||
/// </summary>
|
||||
[Display(Name="ProviderId")]
|
||||
public string ProviderId { get; set; }
|
||||
/// <summary>
|
||||
/// The promotion code.
|
||||
/// </summary>
|
||||
[Display(Name="Comment")]
|
||||
public string Comment { get; set; }
|
||||
[Display(Name="From")]
|
||||
public string FromUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The event web page.
|
||||
/// </summary>
|
||||
|
@ -8,6 +8,6 @@ namespace Yavsc.Services
|
||||
{
|
||||
public interface IGoogleCloudMessageSender
|
||||
{
|
||||
Task<MessageWithPayloadResponse> NotifyAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, YaEvent ev);
|
||||
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, BookQueryEvent ev);
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ namespace Yavsc.Services
|
||||
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
||||
/// </returns>
|
||||
public async Task<MessageWithPayloadResponse>
|
||||
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
|
||||
NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
|
||||
{
|
||||
MessageWithPayloadResponse response = null;
|
||||
await Task.Run(()=>{
|
||||
response = googleSettings.NotifyEvent(registrationIds, ev);
|
||||
response = googleSettings.NotifyEvent<BookQueryEvent>(registrationIds, ev);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
Reference in New Issue
Block a user