estimate to client
This commit is contained in:
parent
b7c9e93669
commit
3acb5bc922
13 changed files with 127 additions and 40 deletions
|
|
@ -11,6 +11,7 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using Yavsc.Model;
|
using Yavsc.Model;
|
||||||
|
using Yavsc.Models.Messaging;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Booking;
|
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).
|
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now).
|
||||||
Select(c => new BookQueryProviderInfo
|
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,
|
Location = c.Location,
|
||||||
EventDate = c.EventDate,
|
EventDate = c.EventDate,
|
||||||
Id = c.Id,
|
Id = c.Id,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.Data.Entity;
|
using Microsoft.Data.Entity;
|
||||||
using Yavsc.Model;
|
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Messaging;
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -20,29 +19,10 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/ContactsApi
|
// GET: api/ContactsApi
|
||||||
[HttpGet]
|
[HttpGet("{id}")]
|
||||||
public IEnumerable<ClientProviderInfo> GetClientProviderInfo()
|
public ClientProviderInfo GetClientProviderInfo(string id)
|
||||||
{
|
{
|
||||||
return _context.ClientProviderInfo;
|
return _context.ClientProviderInfo.FirstOrDefault(c=>c.UserId == id);
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT: api/ContactsApi/5
|
// 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 Microsoft.Extensions.Localization;
|
||||||
using Yavsc.Model;
|
|
||||||
using Yavsc.Models.Booking;
|
using Yavsc.Models.Booking;
|
||||||
using Yavsc.Models.Messaging;
|
using Yavsc.Models.Messaging;
|
||||||
|
|
||||||
|
|
@ -12,11 +11,15 @@ namespace Yavsc.Helpers
|
||||||
{
|
{
|
||||||
var yaev = new BookQueryEvent
|
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,
|
Previsional = query.Previsional,
|
||||||
EventDate = query.EventDate,
|
EventDate = query.EventDate,
|
||||||
Location = query.Location,
|
Location = query.Location,
|
||||||
Id = query.Id
|
Id = query.Id,
|
||||||
|
Reason = query.Reason
|
||||||
};
|
};
|
||||||
return yaev;
|
return yaev;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using Yavsc.Model;
|
|
||||||
|
|
||||||
namespace Yavsc.Interfaces
|
namespace Yavsc.Interfaces
|
||||||
{
|
{
|
||||||
|
using Yavsc.Models.Messaging;
|
||||||
public interface IBookQueryData
|
public interface IBookQueryData
|
||||||
{
|
{
|
||||||
ClientProviderInfo Client { get; set; }
|
ClientProviderInfo Client { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@
|
||||||
|
|
||||||
public interface IEvent {
|
public interface IEvent {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An acceptable topic for this event to be.
|
/// <c>/topic/(bookquery|estimate)</c>
|
||||||
/// Should return something like the class name
|
|
||||||
/// of this object
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
string Topic { get; set ; }
|
string Topic { get; set ; }
|
||||||
|
/// <summary>
|
||||||
|
/// Should be the user's name
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
string Sender { get; set ; }
|
string Sender { get; set ; }
|
||||||
|
/// <summary>
|
||||||
|
/// The message
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
string Message { get; set; }
|
string Message { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ using Yavsc.Models.OAuth;
|
||||||
using Yavsc.Models.Workflow;
|
using Yavsc.Models.Workflow;
|
||||||
using Yavsc.Models.Identity;
|
using Yavsc.Models.Identity;
|
||||||
using Yavsc.Models.Market;
|
using Yavsc.Models.Market;
|
||||||
using Yavsc.Model;
|
|
||||||
using Yavsc.Model.Chat;
|
using Yavsc.Model.Chat;
|
||||||
|
using Yavsc.Models.Messaging;
|
||||||
|
|
||||||
namespace Yavsc.Models
|
namespace Yavsc.Models
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
|
|
||||||
namespace Yavsc.Model
|
namespace Yavsc.Model
|
||||||
{
|
{
|
||||||
|
using Models.Messaging;
|
||||||
|
|
||||||
public class BookQueryProviderInfo
|
public class BookQueryProviderInfo
|
||||||
{
|
{
|
||||||
|
|
@ -15,4 +16,5 @@ namespace Yavsc.Model
|
||||||
|
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
namespace Yavsc.Model
|
namespace Yavsc.Models.Messaging
|
||||||
{
|
{
|
||||||
public class ClientProviderInfo
|
public class ClientProviderInfo
|
||||||
{
|
{
|
||||||
|
|
@ -8,10 +8,8 @@ namespace Yavsc.Model
|
||||||
public string Avatar { get; set; }
|
public string Avatar { get; set; }
|
||||||
[Key]
|
[Key]
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
public int Rate { get; set; }
|
|
||||||
public string EMail { get; set; }
|
public string EMail { get; set; }
|
||||||
public string Phone { get; set; }
|
public string Phone { get; set; }
|
||||||
public Location BillingAddress { 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
|
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,
|
/// <returns>a MessageWithPayloadResponse,
|
||||||
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<MessageWithPayloadResponse>
|
public async Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
|
||||||
NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
|
|
||||||
{
|
{
|
||||||
MessageWithPayloadResponse response = null;
|
MessageWithPayloadResponse response = null;
|
||||||
await Task.Run(()=>{
|
await Task.Run(()=>{
|
||||||
|
|
@ -37,6 +36,15 @@ namespace Yavsc.Services
|
||||||
return response;
|
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)
|
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue