estimate to client
This commit is contained in:
@ -11,6 +11,7 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
using System;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models.Messaging;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Booking;
|
||||
|
||||
@ -43,7 +44,10 @@ namespace Yavsc.Controllers
|
||||
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now).
|
||||
Select(c => new BookQueryProviderInfo
|
||||
{
|
||||
Client = new ClientProviderInfo { UserName = c.Client.UserName, UserId = c.ClientId },
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = c.Client.UserName,
|
||||
UserId = c.ClientId,
|
||||
Avatar = c.Client.Avatar },
|
||||
Location = c.Location,
|
||||
EventDate = c.EventDate,
|
||||
Id = c.Id,
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
@ -20,29 +19,10 @@ namespace Yavsc.Controllers
|
||||
}
|
||||
|
||||
// GET: api/ContactsApi
|
||||
[HttpGet]
|
||||
public IEnumerable<ClientProviderInfo> GetClientProviderInfo()
|
||||
[HttpGet("{id}")]
|
||||
public ClientProviderInfo GetClientProviderInfo(string id)
|
||||
{
|
||||
return _context.ClientProviderInfo;
|
||||
}
|
||||
|
||||
// GET: api/ContactsApi/5
|
||||
[HttpGet("{id}", Name = "GetClientProviderInfo")]
|
||||
public IActionResult GetClientProviderInfo([FromRoute] string id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
ClientProviderInfo clientProviderInfo = _context.ClientProviderInfo.Single(m => m.UserId == id);
|
||||
|
||||
if (clientProviderInfo == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return Ok(clientProviderInfo);
|
||||
return _context.ClientProviderInfo.FirstOrDefault(c=>c.UserId == id);
|
||||
}
|
||||
|
||||
// PUT: api/ContactsApi/5
|
||||
|
16
Yavsc/Helpers/EstimateHelpers.cs
Normal file
16
Yavsc/Helpers/EstimateHelpers.cs
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
public static class EstimateHelpers {
|
||||
public static decimal GetTotal(this Estimate estimate)
|
||||
{
|
||||
decimal result = 0;
|
||||
foreach (var l in estimate.Bill)
|
||||
result += l.Count*l.UnitaryCost;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Models.Booking;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
@ -12,11 +11,15 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
var yaev = new BookQueryEvent
|
||||
{
|
||||
Client = new ClientProviderInfo { UserName = query.Client.UserName , UserId = query.ClientId } ,
|
||||
Client = new ClientProviderInfo {
|
||||
UserName = query.Client.UserName ,
|
||||
UserId = query.ClientId,
|
||||
Avatar = query.Client.Avatar } ,
|
||||
Previsional = query.Previsional,
|
||||
EventDate = query.EventDate,
|
||||
Location = query.Location,
|
||||
Id = query.Id
|
||||
Id = query.Id,
|
||||
Reason = query.Reason
|
||||
};
|
||||
return yaev;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using Yavsc.Model;
|
||||
|
||||
namespace Yavsc.Interfaces
|
||||
{
|
||||
using Yavsc.Models.Messaging;
|
||||
public interface IBookQueryData
|
||||
{
|
||||
ClientProviderInfo Client { get; set; }
|
||||
|
@ -2,13 +2,18 @@
|
||||
|
||||
public interface IEvent {
|
||||
/// <summary>
|
||||
/// An acceptable topic for this event to be.
|
||||
/// Should return something like the class name
|
||||
/// of this object
|
||||
/// <c>/topic/(bookquery|estimate)</c>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string Topic { get; set ; }
|
||||
/// <summary>
|
||||
/// Should be the user's name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string Sender { get; set ; }
|
||||
|
||||
/// <summary>
|
||||
/// The message
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string Message { get; set; }
|
||||
}
|
@ -12,8 +12,8 @@ using Yavsc.Models.OAuth;
|
||||
using Yavsc.Models.Workflow;
|
||||
using Yavsc.Models.Identity;
|
||||
using Yavsc.Models.Market;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.Chat;
|
||||
using Yavsc.Models.Messaging;
|
||||
|
||||
namespace Yavsc.Models
|
||||
{
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
|
||||
namespace Yavsc.Model
|
||||
{
|
||||
using Models.Messaging;
|
||||
|
||||
public class BookQueryProviderInfo
|
||||
{
|
||||
@ -15,4 +16,5 @@ namespace Yavsc.Model
|
||||
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace Yavsc.Model
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
public class ClientProviderInfo
|
||||
{
|
||||
@ -8,10 +8,8 @@ namespace Yavsc.Model
|
||||
public string Avatar { get; set; }
|
||||
[Key]
|
||||
public string UserId { get; set; }
|
||||
public int Rate { get; set; }
|
||||
public string EMail { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public Location BillingAddress { get; set; }
|
||||
public string ChatHubConnectionId { get; set; }
|
||||
}
|
||||
}
|
||||
|
54
Yavsc/Models/Messaging/EstimationEvent.cs
Normal file
54
Yavsc/Models/Messaging/EstimationEvent.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
public class EstimationEvent: IEvent
|
||||
{
|
||||
public EstimationEvent(ApplicationDbContext context, Estimate estimate, IStringLocalizer SR)
|
||||
{
|
||||
Estimation = estimate;
|
||||
var perfer = context.Performers.FirstOrDefault(
|
||||
p => p.PerformerId == estimate.OwnerId
|
||||
);
|
||||
// Use estimate.OwnerId;
|
||||
ProviderInfo = new ProviderClientInfo {
|
||||
Rate = perfer.Rate,
|
||||
UserName = perfer.Performer.UserName,
|
||||
Avatar = perfer.Performer.Avatar,
|
||||
UserId = perfer.PerformerId
|
||||
};
|
||||
((IEvent)this).Sender = perfer.Performer.UserName;
|
||||
((IEvent)this).Message = string.Format(SR["EstimationMessageToClient"],perfer.Performer.UserName,
|
||||
estimate.Title,estimate.GetTotal());
|
||||
}
|
||||
ProviderClientInfo ProviderInfo { get; set; }
|
||||
Estimate Estimation { get; set; }
|
||||
|
||||
private string subtopic = null;
|
||||
string IEvent.Topic
|
||||
{
|
||||
get
|
||||
{
|
||||
return "/topic/estimate"+subtopic!=null?"/"+subtopic:"";
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
subtopic = value;
|
||||
}
|
||||
}
|
||||
|
||||
string IEvent.Sender
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
string IEvent.Message
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
8
Yavsc/Models/Messaging/ProviderClientInfo.cs
Normal file
8
Yavsc/Models/Messaging/ProviderClientInfo.cs
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Yavsc.Models.Messaging
|
||||
{
|
||||
public class ProviderClientInfo : ClientProviderInfo
|
||||
{
|
||||
public int Rate { get; set; }
|
||||
}
|
||||
}
|
@ -8,6 +8,15 @@ namespace Yavsc.Services
|
||||
{
|
||||
public interface IGoogleCloudMessageSender
|
||||
{
|
||||
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, BookQueryEvent ev);
|
||||
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(
|
||||
GoogleAuthSettings googlesettings,
|
||||
IEnumerable<string> registrationId,
|
||||
BookQueryEvent ev);
|
||||
|
||||
Task<MessageWithPayloadResponse> NotifyEstimateAsync(
|
||||
GoogleAuthSettings googlesettings,
|
||||
IEnumerable<string> registrationId,
|
||||
EstimationEvent ev);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ namespace Yavsc.Services
|
||||
/// <returns>a MessageWithPayloadResponse,
|
||||
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
||||
/// </returns>
|
||||
public async Task<MessageWithPayloadResponse>
|
||||
NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
|
||||
public async Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
|
||||
{
|
||||
MessageWithPayloadResponse response = null;
|
||||
await Task.Run(()=>{
|
||||
@ -37,6 +36,15 @@ namespace Yavsc.Services
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<MessageWithPayloadResponse> NotifyEstimateAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, EstimationEvent ev)
|
||||
{
|
||||
MessageWithPayloadResponse response = null;
|
||||
await Task.Run(()=>{
|
||||
response = googleSettings.NotifyEvent<EstimationEvent>(registrationIds, ev);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
|
||||
{
|
||||
try
|
||||
|
Reference in New Issue
Block a user