refactoring messages
This commit is contained in:
parent
6066497a67
commit
13bdf7463d
44 changed files with 602 additions and 303 deletions
|
|
@ -47,23 +47,25 @@ namespace Yavsc.Controllers
|
|||
long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid))
|
||||
.Select(c=>c.Id).ToArray();
|
||||
IQueryable<BlogPost> posts ;
|
||||
if (usercircles != null) {
|
||||
posts = _context.Blogspot.Include(b => b.Author)
|
||||
var allposts = _context.Blogspot
|
||||
.Include(b => b.Author)
|
||||
.Include(p=>p.ACL)
|
||||
.Include(p=>p.Tags)
|
||||
.Include(p=>p.Comments)
|
||||
.Include(p=>p.ACL)
|
||||
.Where(p=> p.AuthorId == uid || p.Visible &&
|
||||
(p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId))))
|
||||
;
|
||||
.Where(p=>p.AuthorId == uid || p.Visible);
|
||||
|
||||
if (usercircles != null) {
|
||||
posts = allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId)))
|
||||
;
|
||||
}
|
||||
else {
|
||||
posts = _context.Blogspot.Include(b => b.Author)
|
||||
.Include(p=>p.ACL).Where(p=>p.AuthorId == uid || p.Visible && p.ACL.Count == 0);
|
||||
posts = allposts.Where(p => p.ACL.Count == 0);
|
||||
}
|
||||
|
||||
return View(posts.OrderByDescending( p=> p.DateCreated)
|
||||
|
||||
.GroupBy(p=> p.Title).Skip(skip).Take(maxLen));
|
||||
var data = posts.OrderByDescending( p=> p.DateCreated).ToArray();
|
||||
var grouped = data.GroupBy(p=> p.Title).Skip(skip).Take(maxLen);
|
||||
|
||||
return View(grouped);
|
||||
}
|
||||
|
||||
[Route("/Title/{id?}")]
|
||||
|
|
|
|||
|
|
@ -174,17 +174,18 @@ namespace Yavsc.Controllers
|
|||
.Devices.Select(d => d.GCMRegistrationId);
|
||||
grep = await _GCMSender.NotifyBookQueryAsync(_googleSettings,regids,yaev);
|
||||
}
|
||||
|
||||
// TODO setup a profile choice to allow notifications
|
||||
// both on mailbox and mobile
|
||||
// if (grep==null || grep.success<=0 || grep.failure>0)
|
||||
ViewBag.GooglePayload=grep;
|
||||
|
||||
await _emailSender.SendEmailAsync(
|
||||
ViewBag.EmailSent = await _emailSender.SendEmailAsync(
|
||||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.UserName,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
$"{command.Client.UserName} (un client) vous demande un rendez-vous",
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
$"{yaev.CreateBody()}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a=>a.Code == command.ActivityCode);
|
||||
|
|
|
|||
78
Yavsc/Controllers/GCMDevicesController.cs
Normal file
78
Yavsc/Controllers/GCMDevicesController.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Models;
|
||||
using Models.Identity;
|
||||
|
||||
public class GCMDevicesController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public GCMDevicesController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: GCMDevices
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
|
||||
var applicationDbContext = _context.GCMDevices.Include(g => g.DeviceOwner).Where(d=>d.DeviceOwnerId == uid);
|
||||
return View(await applicationDbContext.ToListAsync());
|
||||
}
|
||||
|
||||
// GET: GCMDevices/Details/5
|
||||
public async Task<IActionResult> Details(string id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
|
||||
if (googleCloudMobileDeclaration == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return View(googleCloudMobileDeclaration);
|
||||
}
|
||||
|
||||
// GET: GCMDevices/Delete/5
|
||||
[ActionName("Delete")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
|
||||
if (googleCloudMobileDeclaration == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
return View(googleCloudMobileDeclaration);
|
||||
}
|
||||
|
||||
// POST: GCMDevices/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||
{
|
||||
GoogleCloudMobileDeclaration googleCloudMobileDeclaration = await _context.GCMDevices.SingleAsync(m => m.DeviceId == id);
|
||||
_context.GCMDevices.Remove(googleCloudMobileDeclaration);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,60 +79,30 @@ namespace Yavsc.Controllers
|
|||
ViewData["paymentinfo"] = paymentInfo;
|
||||
command.Regularisation = paymentInfo.DbContent;
|
||||
command.PaymentId = token;
|
||||
if (paymentInfo != null)
|
||||
if (paymentInfo.DetailsFromPayPal != null)
|
||||
if (paymentInfo.DetailsFromPayPal.Ack == AckCodeType.SUCCESS)
|
||||
if (command.ValidationDate == null)
|
||||
command.ValidationDate = DateTime.Now;
|
||||
bool paymentOk = false;
|
||||
if (paymentInfo.DetailsFromPayPal != null)
|
||||
if (paymentInfo.DetailsFromPayPal.Ack == AckCodeType.SUCCESS)
|
||||
{
|
||||
// FIXME Assert (command.ValidationDate == null)
|
||||
if (command.ValidationDate == null) {
|
||||
paymentOk = true;
|
||||
command.ValidationDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
SetViewBagPaymentUrls(id);
|
||||
if (command.PerformerProfile.AcceptPublicContact)
|
||||
if (command.PerformerProfile.AcceptPublicContact && paymentOk)
|
||||
{
|
||||
var invoiceId = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.InvoiceID;
|
||||
var payerName = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Name;
|
||||
var phone = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Phone;
|
||||
var payerEmail = paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
|
||||
var amount = string.Join(", ",
|
||||
paymentInfo.DetailsFromPayPal.GetExpressCheckoutDetailsResponseDetails.PaymentDetails.Select(
|
||||
p => $"{p.OrderTotal.value} {p.OrderTotal.currencyID}"));
|
||||
var gender = command.Prestation.Gender;
|
||||
var date = command.EventDate?.ToString("dd MM yyyy hh:mm");
|
||||
var lieu = command.Location.Address;
|
||||
string clientFinal = (gender == HairCutGenders.Women) ? _localizer["Women"] +
|
||||
" " + _localizer[command.Prestation.Length.ToString()] : _localizer[gender.ToString()];
|
||||
MessageWithPayloadResponse grep = null;
|
||||
var yaev = command.CreateEvent("PaymentConfirmation",
|
||||
this._localizer["PaymentConfirmation"],
|
||||
command.Client.GetSender(),
|
||||
$@"# Paiment confirmé: {amount}
|
||||
|
||||
Effectué par : {payerName} [{payerEmail}]
|
||||
Identifiant PayPal du paiment: {token}
|
||||
Identifiant PayPal du payeur: {PayerID}
|
||||
Identifiant de la facture sur site: {invoiceId}
|
||||
|
||||
|
||||
# La prestation concernée:
|
||||
|
||||
Demandeur: {command.Client.UserName}
|
||||
|
||||
Date: {date}
|
||||
|
||||
Lieu: {lieu}
|
||||
|
||||
Le client final: {clientFinal}
|
||||
|
||||
{command.GetBillText()}
|
||||
|
||||
");
|
||||
|
||||
var yaev = command.CreatePaymentEvent(paymentInfo, _localizer);
|
||||
if (command.PerformerProfile.AcceptNotifications)
|
||||
{
|
||||
if (command.PerformerProfile.Performer.Devices.Count > 0)
|
||||
{
|
||||
var regids = command.PerformerProfile.Performer
|
||||
.Devices.Select(d => d.GCMRegistrationId);
|
||||
grep = await _GCMSender.NotifyHairCutQueryAsync(_googleSettings, regids, yaev);
|
||||
|
||||
grep = await _GCMSender.NotifyAsync(_googleSettings, regids, yaev);
|
||||
}
|
||||
// TODO setup a profile choice to allow notifications
|
||||
// both on mailbox and mobile
|
||||
|
|
@ -144,8 +114,8 @@ Le client final: {clientFinal}
|
|||
_siteSettings, _smtpSettings,
|
||||
command.PerformerProfile.Performer.UserName,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
yaev.Reason,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
yaev.Topic,
|
||||
yaev.CreateBody()
|
||||
);
|
||||
}
|
||||
else
|
||||
|
|
@ -321,7 +291,7 @@ Le client final: {clientFinal}
|
|||
DateTime evdate = yaev.EventDate ?? new DateTime();
|
||||
var result = await _calendarManager.CreateEventAsync(pro.Performer.Id,
|
||||
pro.Performer.DedicatedGoogleCalendar,
|
||||
evdate, 3600, yaev.Topic, yaev.Message,
|
||||
evdate, 3600, yaev.Topic, yaev.Client.UserName + " : " + yaev.Reason,
|
||||
yaev.Location?.Address, false
|
||||
);
|
||||
if (result.Id == null)
|
||||
|
|
@ -333,8 +303,8 @@ Le client final: {clientFinal}
|
|||
_siteSettings, _smtpSettings,
|
||||
pro.Performer.UserName,
|
||||
pro.Performer.Email,
|
||||
yaev.Reason,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
$"{yaev.Client.UserName}: {yaev.Reason}",
|
||||
$"{yaev.Reason}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
else
|
||||
|
|
@ -456,6 +426,7 @@ Le client final: {clientFinal}
|
|||
bp => bp.UserId == command.PerformerId
|
||||
);
|
||||
var yaev = command.CreateEvent(_localizer, brSettings);
|
||||
string msg = yaev.CreateBoby();
|
||||
MessageWithPayloadResponse grep = null;
|
||||
|
||||
if (pro.AcceptNotifications
|
||||
|
|
@ -481,7 +452,7 @@ Le client final: {clientFinal}
|
|||
await _calendarManager.CreateEventAsync(
|
||||
pro.Performer.Id,
|
||||
pro.Performer.DedicatedGoogleCalendar,
|
||||
evdate, 3600, yaev.Topic, yaev.Message,
|
||||
evdate, 3600, yaev.Topic, msg,
|
||||
yaev.Location?.ToString(), false
|
||||
);
|
||||
}
|
||||
|
|
@ -491,7 +462,7 @@ Le client final: {clientFinal}
|
|||
command.PerformerProfile.Performer.UserName,
|
||||
command.PerformerProfile.Performer.Email,
|
||||
yaev.Topic + " " + yaev.Sender,
|
||||
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
$"{msg}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
|
||||
);
|
||||
}
|
||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == command.ActivityCode);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
else clicked = DbContext.DimissClicked.Where(d=>d.UserId == uid).Select(d=>d.NotificationId).ToArray();
|
||||
var notes = DbContext.Notification.Where(
|
||||
n=> !clicked.Any(c=>n.Id==c)
|
||||
n=> !clicked.Contains(n.Id)
|
||||
);
|
||||
this.Notify(notes);
|
||||
ViewData["HaircutCommandCount"] = DbContext.HairCutQueries.Where(
|
||||
|
|
|
|||
|
|
@ -122,9 +122,10 @@ namespace Yavsc.Controllers
|
|||
EmailConfirmed = await _userManager.IsEmailConfirmedAsync(user)
|
||||
};
|
||||
model.HaveProfessionalSettings = _dbContext.Performers.Any(x => x.PerformerId == user.Id);
|
||||
var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id);
|
||||
var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id).ToArray();
|
||||
|
||||
model.HaveActivityToConfigure = usrActs.Where( a => ( a.Does.SettingsClassName != null )).Count( a => a.Settings == null)>0;
|
||||
var usrActToSet = usrActs.Where( a => ( a.Settings == null && a.Does.SettingsClassName != null )).ToArray();
|
||||
model.HaveActivityToConfigure = usrActToSet .Count()>0;
|
||||
model.Activity = _dbContext.UserActivities.Include(a=>a.Does).Where(u=>u.UserId == user.Id).ToList();
|
||||
return View(model);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue