cleaning duplicated definitions

This commit is contained in:
Paul Schneider 2017-07-03 15:54:18 +02:00
commit 003651e461
20 changed files with 5816 additions and 561 deletions

View file

@ -30,10 +30,13 @@ namespace Yavsc.Controllers
protected SiteSettings _siteSettings;
protected SmtpSettings _smtpSettings;
protected ICalendarManager _calendarManager;
protected readonly ILogger _logger;
public CommandController(ApplicationDbContext context, IOptions<GoogleAuthSettings> googleSettings,
IGoogleCloudMessageSender GCMSender,
UserManager<ApplicationUser> userManager,
ICalendarManager calendarManager,
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer,
IEmailSender emailSender,
IOptions<SmtpSettings> smtpSettings,
@ -47,6 +50,7 @@ namespace Yavsc.Controllers
_userManager = userManager;
_smtpSettings = smtpSettings.Value;
_siteSettings = siteSettings.Value;
_calendarManager = calendarManager;
_localizer = localizer;
_logger = loggerFactory.CreateLogger<CommandController>();
}

View file

@ -38,14 +38,13 @@ namespace Yavsc.Controllers
IEmailSender emailSender,
IOptions<SmtpSettings> smtpSettings,
IOptions<SiteSettings> siteSettings,
ILoggerFactory loggerFactory) : base(context,googleSettings,GCMSender,userManager,
localizer,emailSender,smtpSettings,siteSettings,loggerFactory)
ICalendarManager calManager,
ILoggerFactory loggerFactory) : base(context, googleSettings, GCMSender, userManager,
calManager, localizer, emailSender, smtpSettings, siteSettings, loggerFactory)
{
this.payPalSettings = payPalSettings.Value;
}
PayPalSettings payPalSettings;
private async Task<HairCutQuery> GetQuery(long id)
{
var query = await _context.HairCutQueries
@ -288,6 +287,7 @@ Le client final: {clientFinal}
if (pro.AcceptPublicContact)
{
if (pro.AcceptNotifications) {
if (pro.Performer.Devices.Count > 0) {
var regids = model.PerformerProfile.Performer
@ -301,6 +301,19 @@ Le client final: {clientFinal}
if (grep!=null)
_logger.LogWarning($"Performer: {model.PerformerProfile.Performer.UserName} success: {grep.success} failure: {grep.failure}");
}
// TODO if pro.AllowCalendarEventInsert
if (pro.Performer.DedicatedGoogleCalendar != null && yaev.EventDate != null) {
_logger.LogInformation("Inserting an event in the calendar");
DateTime evdate = yaev.EventDate ?? new DateTime();
var result = await _calendarManager.CreateEventAsync(
pro.Performer.DedicatedGoogleCalendar,
evdate, 3600, yaev.Topic, yaev.Message,
yaev.Location?.Address, false
);
if (result.Id == null)
_logger.LogWarning("Something went wrong, calendar event not created");
}
else _logger.LogWarning($"Calendar: {pro.Performer.DedicatedGoogleCalendar != null}\nEventDate: {yaev.EventDate != null}");
await _emailSender.SendEmailAsync(
_siteSettings, _smtpSettings,
@ -432,11 +445,22 @@ Le client final: {clientFinal}
grep = await _GCMSender.NotifyHairCutQueryAsync(_googleSettings,regids,yaev);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
// both on mailbox and mobile, and to allow calendar event insertion.
// if (grep==null || grep.success<=0 || grep.failure>0)
ViewBag.GooglePayload=grep;
if (grep!=null)
_logger.LogWarning($"Performer: {command.PerformerProfile.Performer.UserName} success: {grep.success} failure: {grep.failure}");
if (pro.Performer.DedicatedGoogleCalendar != null && yaev.EventDate != null) {
DateTime evdate = yaev.EventDate ?? new DateTime();
await _calendarManager.CreateEventAsync(
pro.Performer.DedicatedGoogleCalendar,
evdate, 3600, yaev.Topic, yaev.Message,
yaev.Location?.ToString(), false
);
}
await _emailSender.SendEmailAsync(
_siteSettings, _smtpSettings,

View file

@ -24,7 +24,6 @@ namespace Yavsc.Controllers
using Yavsc.Models;
using Yavsc.Services;
using Yavsc.ViewModels.Manage;
using Yavsc.Models.Calendar;
using System.IO;
[Authorize]
@ -123,7 +122,7 @@ namespace Yavsc.Controllers
model.HaveProfessionalSettings = _dbContext.Performers.Any(x => x.PerformerId == user.Id);
var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id);
model.HaveActivityToConfigure = usrActs.Any( a=> a.Settings == null && a.Does.SettingsClassName!=null );
model.HaveActivityToConfigure = usrActs.Where( a => ( a.Does.SettingsClassName != null )).Count( a => a.Settings == null)>0;
model.Activity = _dbContext.UserActivities.Include(a=>a.Does).Where(u=>u.UserId == user.Id).ToList();
return View(model);
}
@ -282,11 +281,9 @@ namespace Yavsc.Controllers
catch (WebException ex)
{
// a bug
_logger.LogError("Google token, an Forbidden calendar");
if (ex.HResult == (int)HttpStatusCode.Forbidden)
{
return RedirectToAction("LinkLogin", new { provider = "Google" });
}
_logger.LogError("Google Api error");
_logger.LogError("Code: "+ex.HResult+"\n"+ ex.Message);
return RedirectToAction("LinkLogin", new { provider = "Google" });
}
return View(new SetGoogleCalendarViewModel { ReturnUrl = returnUrl });
}