From 232097f1d466aec230593ed2a674c5c829093e79 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2016 14:45:51 +0100 Subject: [PATCH 1/8] estimate to client --- .../ApiControllers/BookQueryApiController.cs | 6 ++- Yavsc/ApiControllers/ContactsApiController.cs | 28 ++-------- Yavsc/Helpers/EstimateHelpers.cs | 16 ++++++ Yavsc/Helpers/EventHelpers.cs | 9 ++-- Yavsc/Interfaces/IBookQueryData.cs | 2 +- Yavsc/Interfaces/Workflow/IEvent.cs | 13 +++-- Yavsc/Models/ApplicationDbContext.cs | 2 +- .../Models/Messaging/BookQueryProviderInfo.cs | 2 + Yavsc/Models/Messaging/ClientProviderInfo.cs | 4 +- Yavsc/Models/Messaging/EstimationEvent.cs | 54 +++++++++++++++++++ Yavsc/Models/Messaging/ProviderClientInfo.cs | 8 +++ Yavsc/Services/IGoogleCloudMessageSender.cs | 11 +++- Yavsc/Services/MessageServices.cs | 12 ++++- 13 files changed, 127 insertions(+), 40 deletions(-) create mode 100644 Yavsc/Helpers/EstimateHelpers.cs create mode 100644 Yavsc/Models/Messaging/EstimationEvent.cs create mode 100644 Yavsc/Models/Messaging/ProviderClientInfo.cs diff --git a/Yavsc/ApiControllers/BookQueryApiController.cs b/Yavsc/ApiControllers/BookQueryApiController.cs index 7c8c76d5..8094f74d 100644 --- a/Yavsc/ApiControllers/BookQueryApiController.cs +++ b/Yavsc/ApiControllers/BookQueryApiController.cs @@ -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, diff --git a/Yavsc/ApiControllers/ContactsApiController.cs b/Yavsc/ApiControllers/ContactsApiController.cs index d031c485..6e217d26 100644 --- a/Yavsc/ApiControllers/ContactsApiController.cs +++ b/Yavsc/ApiControllers/ContactsApiController.cs @@ -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 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 diff --git a/Yavsc/Helpers/EstimateHelpers.cs b/Yavsc/Helpers/EstimateHelpers.cs new file mode 100644 index 00000000..5976cff4 --- /dev/null +++ b/Yavsc/Helpers/EstimateHelpers.cs @@ -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; + } + } + +} \ No newline at end of file diff --git a/Yavsc/Helpers/EventHelpers.cs b/Yavsc/Helpers/EventHelpers.cs index 610b1e47..1461c495 100644 --- a/Yavsc/Helpers/EventHelpers.cs +++ b/Yavsc/Helpers/EventHelpers.cs @@ -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; } diff --git a/Yavsc/Interfaces/IBookQueryData.cs b/Yavsc/Interfaces/IBookQueryData.cs index ab156929..49f8aa03 100644 --- a/Yavsc/Interfaces/IBookQueryData.cs +++ b/Yavsc/Interfaces/IBookQueryData.cs @@ -1,8 +1,8 @@ using System; -using Yavsc.Model; namespace Yavsc.Interfaces { + using Yavsc.Models.Messaging; public interface IBookQueryData { ClientProviderInfo Client { get; set; } diff --git a/Yavsc/Interfaces/Workflow/IEvent.cs b/Yavsc/Interfaces/Workflow/IEvent.cs index 6ee109e7..df7a8714 100644 --- a/Yavsc/Interfaces/Workflow/IEvent.cs +++ b/Yavsc/Interfaces/Workflow/IEvent.cs @@ -2,13 +2,18 @@ public interface IEvent { /// - /// An acceptable topic for this event to be. - /// Should return something like the class name - /// of this object + /// /topic/(bookquery|estimate) /// /// string Topic { get; set ; } + /// + /// Should be the user's name + /// + /// string Sender { get; set ; } - + /// + /// The message + /// + /// string Message { get; set; } } \ No newline at end of file diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index 63f81615..e02c08a0 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -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 { diff --git a/Yavsc/Models/Messaging/BookQueryProviderInfo.cs b/Yavsc/Models/Messaging/BookQueryProviderInfo.cs index 3e60d194..b34cf5f6 100644 --- a/Yavsc/Models/Messaging/BookQueryProviderInfo.cs +++ b/Yavsc/Models/Messaging/BookQueryProviderInfo.cs @@ -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; } } + } diff --git a/Yavsc/Models/Messaging/ClientProviderInfo.cs b/Yavsc/Models/Messaging/ClientProviderInfo.cs index cec01e02..3f9aebec 100644 --- a/Yavsc/Models/Messaging/ClientProviderInfo.cs +++ b/Yavsc/Models/Messaging/ClientProviderInfo.cs @@ -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; } } } diff --git a/Yavsc/Models/Messaging/EstimationEvent.cs b/Yavsc/Models/Messaging/EstimationEvent.cs new file mode 100644 index 00000000..31c24c15 --- /dev/null +++ b/Yavsc/Models/Messaging/EstimationEvent.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Yavsc/Models/Messaging/ProviderClientInfo.cs b/Yavsc/Models/Messaging/ProviderClientInfo.cs new file mode 100644 index 00000000..6e4ae6db --- /dev/null +++ b/Yavsc/Models/Messaging/ProviderClientInfo.cs @@ -0,0 +1,8 @@ + +namespace Yavsc.Models.Messaging +{ + public class ProviderClientInfo : ClientProviderInfo + { + public int Rate { get; set; } + } +} \ No newline at end of file diff --git a/Yavsc/Services/IGoogleCloudMessageSender.cs b/Yavsc/Services/IGoogleCloudMessageSender.cs index 033759c7..662be685 100644 --- a/Yavsc/Services/IGoogleCloudMessageSender.cs +++ b/Yavsc/Services/IGoogleCloudMessageSender.cs @@ -8,6 +8,15 @@ namespace Yavsc.Services { public interface IGoogleCloudMessageSender { - Task NotifyBookQueryAsync(GoogleAuthSettings googlesettings, IEnumerable registrationId, BookQueryEvent ev); + Task NotifyBookQueryAsync( + GoogleAuthSettings googlesettings, + IEnumerable registrationId, + BookQueryEvent ev); + + Task NotifyEstimateAsync( + GoogleAuthSettings googlesettings, + IEnumerable registrationId, + EstimationEvent ev); + } } diff --git a/Yavsc/Services/MessageServices.cs b/Yavsc/Services/MessageServices.cs index 33f54fd1..d0a0b44c 100755 --- a/Yavsc/Services/MessageServices.cs +++ b/Yavsc/Services/MessageServices.cs @@ -27,8 +27,7 @@ namespace Yavsc.Services /// a MessageWithPayloadResponse, /// bool somethingsent = (response.failure == 0 && response.success > 0) /// - public async Task - NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable registrationIds, BookQueryEvent ev) + public async Task NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable registrationIds, BookQueryEvent ev) { MessageWithPayloadResponse response = null; await Task.Run(()=>{ @@ -37,6 +36,15 @@ namespace Yavsc.Services return response; } + public async Task NotifyEstimateAsync(GoogleAuthSettings googleSettings, IEnumerable registrationIds, EstimationEvent ev) + { + MessageWithPayloadResponse response = null; + await Task.Run(()=>{ + response = googleSettings.NotifyEvent(registrationIds, ev); + }); + return response; + } + public Task SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message) { try From ad238a878fef0b5c5928a78d903d1b5d2e0db203 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2016 15:35:19 +0100 Subject: [PATCH 2/8] fix the exception message --- Yavsc/ViewModels/UserFiles/UserDirectoryInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yavsc/ViewModels/UserFiles/UserDirectoryInfo.cs b/Yavsc/ViewModels/UserFiles/UserDirectoryInfo.cs index 0c7dbafb..ff1237c3 100644 --- a/Yavsc/ViewModels/UserFiles/UserDirectoryInfo.cs +++ b/Yavsc/ViewModels/UserFiles/UserDirectoryInfo.cs @@ -22,7 +22,7 @@ namespace Yavsc.ViewModels.UserFiles var finalPath = (path==null) ? username : username + Path.DirectorySeparatorChar + path; if ( !finalPath.IsValidPath() ) throw new InvalidOperationException( - $"File name contains invalid chars, using path {SubPath}"); + $"File name contains invalid chars, using path {finalPath}"); dInfo = new DirectoryInfo( Path.Combine(Startup.UserFilesDirName,finalPath)); From 3f8d4350064aa9ed14aff17229d7c234f9086f3b Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2016 15:35:52 +0100 Subject: [PATCH 3/8] fix the space usage in a user name, at file creation --- Yavsc/Helpers/FileSystemHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yavsc/Helpers/FileSystemHelpers.cs b/Yavsc/Helpers/FileSystemHelpers.cs index 8ef9cd40..f4ec2aa2 100644 --- a/Yavsc/Helpers/FileSystemHelpers.cs +++ b/Yavsc/Helpers/FileSystemHelpers.cs @@ -26,7 +26,7 @@ namespace Yavsc.Helpers return di; } - static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~.".ToCharArray(); + static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~. ".ToCharArray(); public static bool IsValidDirectoryName(this string name) { From a510458d11925de22cc7b7d62523e09f291ca733 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2016 15:36:16 +0100 Subject: [PATCH 4/8] show the event date in the email --- Yavsc/Controllers/CommandController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yavsc/Controllers/CommandController.cs b/Yavsc/Controllers/CommandController.cs index 23f93442..77b14420 100644 --- a/Yavsc/Controllers/CommandController.cs +++ b/Yavsc/Controllers/CommandController.cs @@ -175,7 +175,7 @@ namespace Yavsc.Controllers _siteSettings, _smtpSettings, command.PerformerProfile.Performer.Email, yaev.Topic+" "+yaev.Client.UserName, - $"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n" + $"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n" ); } ViewBag.GoogleSettings = _googleSettings; From eaea3f6600ed7db89de7089788f3ce3008b501e6 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2016 15:36:38 +0100 Subject: [PATCH 5/8] implementes a message part --- Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx index 08f9bce8..bd600733 100644 --- a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx +++ b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx @@ -203,6 +203,8 @@ entrées Estimer Devis non trouvé + {0} a validé un devis pour vous : {1}\nAu total : {2} € + Il attend maintenant votre signature. Demande de devis Date de l'évennement Page web de l'événement From 3d3d38e0234306fc9cd2ee2cab7e0760d8315f89 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 12 Dec 2016 18:37:54 +0100 Subject: [PATCH 6/8] Validated book queries are obsolete --- .../ApiControllers/BookQueryApiController.cs | 3 +- Yavsc/ApiControllers/EstimateApiController.cs | 10 ++++- Yavsc/Models/Access/BlackList.cs | 37 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Yavsc/Models/Access/BlackList.cs diff --git a/Yavsc/ApiControllers/BookQueryApiController.cs b/Yavsc/ApiControllers/BookQueryApiController.cs index 8094f74d..4452f058 100644 --- a/Yavsc/ApiControllers/BookQueryApiController.cs +++ b/Yavsc/ApiControllers/BookQueryApiController.cs @@ -41,7 +41,8 @@ namespace Yavsc.Controllers var now = DateTime.Now; var result = _context.Commands.Include(c => c.Location). - 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 + && c.ValidationDate == null). Select(c => new BookQueryProviderInfo { Client = new ClientProviderInfo { diff --git a/Yavsc/ApiControllers/EstimateApiController.cs b/Yavsc/ApiControllers/EstimateApiController.cs index 400a2633..59e601ab 100644 --- a/Yavsc/ApiControllers/EstimateApiController.cs +++ b/Yavsc/ApiControllers/EstimateApiController.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Security.Claims; using Microsoft.AspNet.Authorization; @@ -124,8 +125,15 @@ namespace Yavsc.Controllers return HttpBadRequest(ModelState); } } - + if (estimate.CommandId!=null) { + var query = _context.BookQueries.FirstOrDefault(q => q.Id == estimate.CommandId); + if (query == null || query.PerformerId!= uid) + throw new InvalidOperationException(); + query.ValidationDate = DateTime.Now; + } _context.Estimates.Add(estimate); + + /* _context.AttachRange(estimate.Bill); _context.Attach(estimate); _context.Entry(estimate).State = EntityState.Added; diff --git a/Yavsc/Models/Access/BlackList.cs b/Yavsc/Models/Access/BlackList.cs new file mode 100644 index 00000000..8784eb5c --- /dev/null +++ b/Yavsc/Models/Access/BlackList.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Yavsc.Models.Access +{ + public class BlackListed + { + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + public string UserId { get; set; } + public long ListId { get; set; } + + [ForeignKey("ListId")] + public virtual BlackList BlackList { get; set; } + } + public class BlackList + { + public BlackList(long id, string target) + { + this.Id = id; + this.Target = target; + + } + + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + + public string Target { get; set; } + + [InverseProperty("BlackList")] + public virtual List Items + { + get; set; + } + } +} From 4be2da1afb817755830bac43895f4aba0d7f2b60 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 12 Dec 2016 18:48:48 +0100 Subject: [PATCH 7/8] refactoring --- Yavsc/Models/Access/BlackList.cs | 28 ++++-------------------- Yavsc/Models/Identity/ApplicationUser.cs | 3 +++ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Yavsc/Models/Access/BlackList.cs b/Yavsc/Models/Access/BlackList.cs index 8784eb5c..5bbb3b42 100644 --- a/Yavsc/Models/Access/BlackList.cs +++ b/Yavsc/Models/Access/BlackList.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -9,29 +8,10 @@ namespace Yavsc.Models.Access [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } public string UserId { get; set; } - public long ListId { get; set; } + public long OwnerId { get; set; } - [ForeignKey("ListId")] - public virtual BlackList BlackList { get; set; } - } - public class BlackList - { - public BlackList(long id, string target) - { - this.Id = id; - this.Target = target; - - } - - [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public long Id { get; set; } - - public string Target { get; set; } - - [InverseProperty("BlackList")] - public virtual List Items - { - get; set; - } + [ForeignKey("OwnerId")] + public virtual ApplicationUser Owner { get; set; } } + } diff --git a/Yavsc/Models/Identity/ApplicationUser.cs b/Yavsc/Models/Identity/ApplicationUser.cs index 263c50bb..2d8fb602 100644 --- a/Yavsc/Models/Identity/ApplicationUser.cs +++ b/Yavsc/Models/Identity/ApplicationUser.cs @@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema; using Yavsc.Models.Identity; using Yavsc.Model.Chat; using Yavsc.Model.Bank; +using Yavsc.Models.Access; namespace Yavsc.Models { @@ -87,5 +88,7 @@ namespace Yavsc.Models public long DiskQuota { get; set; } = 512*1024*1024; public long DiskUsage { get; set; } = 0; + + public virtual List BlackList { get; set; } } } From 161d47ad1359f01f8d174268044292837777b2af Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 13 Dec 2016 10:57:25 +0100 Subject: [PATCH 8/8] blacklisting + refactoring --- .../ApiControllers/BlackListApiController.cs | 165 ++++++++++++++++++ Yavsc/Models/Access/BlackList.cs | 5 +- Yavsc/Models/ApplicationDbContext.cs | 3 + Yavsc/Models/Bank/AccountBalance.cs | 1 - Yavsc/Models/Blog/Blog.cs | 1 - Yavsc/project.json | 3 +- Yavsc/project.lock.json | 19 +- Yavsc/tasks.todo | 6 + YavscLib/IAccountBalance.cs | 1 - YavscLib/IBlackListed.cs | 9 + YavscLib/IBlog.cs | 15 +- YavscLib/Properties/AssemblyInfo.cs | 2 - YavscLib/YavscLib.csproj | 1 + YavscLib/YavscLib.sln | 2 +- YavscLib/project.json | 9 +- YavscLib/project.lock.json | 17 +- 16 files changed, 235 insertions(+), 24 deletions(-) create mode 100644 Yavsc/ApiControllers/BlackListApiController.cs create mode 100644 YavscLib/IBlackListed.cs diff --git a/Yavsc/ApiControllers/BlackListApiController.cs b/Yavsc/ApiControllers/BlackListApiController.cs new file mode 100644 index 00000000..379eea9a --- /dev/null +++ b/Yavsc/ApiControllers/BlackListApiController.cs @@ -0,0 +1,165 @@ +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNet.Authorization; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Mvc; +using Microsoft.Data.Entity; +using Yavsc.Models; +using Yavsc.Models.Access; + +namespace Yavsc.Controllers +{ + [Produces("application/json")] + [Route("api/blacklist"), Authorize] + public class BlackListApiController : Controller + { + private ApplicationDbContext _context; + + public BlackListApiController(ApplicationDbContext context) + { + _context = context; + } + + // GET: api/BlackListApi + [HttpGet] + public IEnumerable GetBlackListed() + { + return _context.BlackListed; + } + + // GET: api/BlackListApi/5 + [HttpGet("{id}", Name = "GetBlackListed")] + public IActionResult GetBlackListed([FromRoute] long id) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id); + if (blackListed == null) + { + return HttpNotFound(); + } + if (!CheckPermission(blackListed)) + return HttpBadRequest(); + + return Ok(blackListed); + } + + private bool CheckPermission(BlackListed blackListed) + { + var uid = User.GetUserId(); + if (uid != blackListed.OwnerId) + if (!User.IsInRole(Constants.AdminGroupName)) + if (!User.IsInRole(Constants.FrontOfficeGroupName)) + return false; + return true; + } + // PUT: api/BlackListApi/5 + [HttpPut("{id}")] + public IActionResult PutBlackListed(long id, [FromBody] BlackListed blackListed) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + if (id != blackListed.Id) + { + return HttpBadRequest(); + } + if (!CheckPermission(blackListed)) + return HttpBadRequest(); + _context.Entry(blackListed).State = EntityState.Modified; + + try + { + _context.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!BlackListedExists(id)) + { + return HttpNotFound(); + } + else + { + throw; + } + } + + return new HttpStatusCodeResult(StatusCodes.Status204NoContent); + } + + // POST: api/BlackListApi + [HttpPost] + public IActionResult PostBlackListed([FromBody] BlackListed blackListed) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + if (!CheckPermission(blackListed)) + return HttpBadRequest(); + + _context.BlackListed.Add(blackListed); + try + { + _context.SaveChanges(); + } + catch (DbUpdateException) + { + if (BlackListedExists(blackListed.Id)) + { + return new HttpStatusCodeResult(StatusCodes.Status409Conflict); + } + else + { + throw; + } + } + + return CreatedAtRoute("GetBlackListed", new { id = blackListed.Id }, blackListed); + } + + // DELETE: api/BlackListApi/5 + [HttpDelete("{id}")] + public IActionResult DeleteBlackListed(long id) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id); + if (blackListed == null) + { + return HttpNotFound(); + } + + if (!CheckPermission(blackListed)) + return HttpBadRequest(); + + _context.BlackListed.Remove(blackListed); + _context.SaveChanges(); + + return Ok(blackListed); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _context.Dispose(); + } + base.Dispose(disposing); + } + + private bool BlackListedExists(long id) + { + return _context.BlackListed.Count(e => e.Id == id) > 0; + } + } +} \ No newline at end of file diff --git a/Yavsc/Models/Access/BlackList.cs b/Yavsc/Models/Access/BlackList.cs index 5bbb3b42..1d3fc354 100644 --- a/Yavsc/Models/Access/BlackList.cs +++ b/Yavsc/Models/Access/BlackList.cs @@ -1,14 +1,15 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using YavscLib; namespace Yavsc.Models.Access { - public class BlackListed + public class BlackListed: IBlackListed { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } public string UserId { get; set; } - public long OwnerId { get; set; } + public string OwnerId { get; set; } [ForeignKey("OwnerId")] public virtual ApplicationUser Owner { get; set; } diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index e02c08a0..ba6eb571 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -14,6 +14,7 @@ using Yavsc.Models.Identity; using Yavsc.Models.Market; using Yavsc.Model.Chat; using Yavsc.Models.Messaging; +using Yavsc.Models.Access; namespace Yavsc.Models { @@ -189,6 +190,8 @@ namespace Yavsc.Models public DbSet ClientProviderInfo { get; set; } public DbSet Connections { get; set; } + + public DbSet BlackListed { get; set; } } } diff --git a/Yavsc/Models/Bank/AccountBalance.cs b/Yavsc/Models/Bank/AccountBalance.cs index 29f19a02..8dc95a6e 100644 --- a/Yavsc/Models/Bank/AccountBalance.cs +++ b/Yavsc/Models/Bank/AccountBalance.cs @@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Yavsc.Models { - using Interfaces; public partial class AccountBalance: IAccountBalance { [Key] diff --git a/Yavsc/Models/Blog/Blog.cs b/Yavsc/Models/Blog/Blog.cs index 4982819e..136ad6db 100644 --- a/Yavsc/Models/Blog/Blog.cs +++ b/Yavsc/Models/Blog/Blog.cs @@ -2,7 +2,6 @@ using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; -using Yavsc.Interfaces; namespace Yavsc.Models { diff --git a/Yavsc/project.json b/Yavsc/project.json index d4aeaeb5..89a917ff 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -105,7 +105,8 @@ "Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", "Microsoft.AspNet.OWin": "1.0.0-rc1-final", - "System.Json": "4.0.20126.16343" + "System.Json": "4.0.20126.16343", + "YavscLib": "1.0.0-*" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", diff --git a/Yavsc/project.lock.json b/Yavsc/project.lock.json index 2924b4e0..05501016 100644 --- a/Yavsc/project.lock.json +++ b/Yavsc/project.lock.json @@ -2809,6 +2809,10 @@ "lib/WebGrease.dll": {} } }, + "YavscLib/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1" + }, "Zlib.Portable.Signed/1.11.0": { "type": "package", "compile": { @@ -5626,6 +5630,10 @@ "lib/WebGrease.dll": {} } }, + "YavscLib/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1" + }, "Zlib.Portable.Signed/1.11.0": { "type": "package", "compile": { @@ -8443,6 +8451,10 @@ "lib/WebGrease.dll": {} } }, + "YavscLib/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1" + }, "Zlib.Portable.Signed/1.11.0": { "type": "package", "compile": { @@ -8455,6 +8467,10 @@ } }, "libraries": { + "YavscLib/1.0.0": { + "type": "project", + "path": "../YavscLib/project.json" + }, "Antlr/3.4.1.9004": { "type": "package", "sha512": "c1S+HBE+KYA5EBxtn25LEK02hHPH/tDQ6RviUTTCJpZIPoputtn8ArsQJy9lVJWZOnw37ufByO2Fmf1M8wpr8Q==", @@ -11421,7 +11437,8 @@ "Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final", "Microsoft.AspNet.OWin >= 1.0.0-rc1-final", - "System.Json >= 4.0.20126.16343" + "System.Json >= 4.0.20126.16343", + "YavscLib >= 1.0.0-*" ], "DNX,Version=v4.5.1": [ "fx/System.Drawing >= 4.0.0" diff --git a/Yavsc/tasks.todo b/Yavsc/tasks.todo index b221794f..7cc32ba8 100644 --- a/Yavsc/tasks.todo +++ b/Yavsc/tasks.todo @@ -77,6 +77,12 @@ Ceci est une grosse liste de fonctionnalités, existantes, ou à implémenter, o ☐ Podcasts. ☐ Personalisation des blogs. ☐ Monétarisations. + ☐ Distribution de gold card (illimité), de carte vertes (à durée fixe), + de la part d'un prestataire, donnant accès au destinataire au chat privé. + ☐ La carte blanche: en la confiant, le prestataire délègue la gestion de son agenda à un autre utilisateur, + elle implique le droit au chat privé + ☐ de badges temporaires, donnant accès à un téléchargement unique et limité dans le temps, d'un seul fichier, + sans autre forme d'autorisation. ### Réécritures prévues : diff --git a/YavscLib/IAccountBalance.cs b/YavscLib/IAccountBalance.cs index 35a0c1fe..437e6020 100644 --- a/YavscLib/IAccountBalance.cs +++ b/YavscLib/IAccountBalance.cs @@ -4,7 +4,6 @@ { long ContactCredits { get; set; } decimal Credits { get; set; } - IApplicationUser Owner { get; set; } string UserId { get; set; } } } \ No newline at end of file diff --git a/YavscLib/IBlackListed.cs b/YavscLib/IBlackListed.cs new file mode 100644 index 00000000..3d898a4b --- /dev/null +++ b/YavscLib/IBlackListed.cs @@ -0,0 +1,9 @@ +namespace YavscLib +{ + public interface IBlackListed + { + long Id { get; set; } + string UserId { get; set; } + string OwnerId { get; set; } + } +} \ No newline at end of file diff --git a/YavscLib/IBlog.cs b/YavscLib/IBlog.cs index 6fcfab1b..d6500168 100644 --- a/YavscLib/IBlog.cs +++ b/YavscLib/IBlog.cs @@ -4,15 +4,14 @@ namespace Yavsc.Models { public interface IBlog { - IApplicationUser Author { get; set; } string AuthorId { get; set; } - string bcontent { get; set; } + string Content { get; set; } long Id { get; set; } - DateTime modified { get; set; } - string photo { get; set; } - DateTime posted { get; set; } - int rate { get; set; } - string title { get; set; } - bool visible { get; set; } + DateTime Modified { get; set; } + string Photo { get; set; } + DateTime Posted { get; set; } + int Rate { get; set; } + string Title { get; set; } + bool Visible { get; set; } } } \ No newline at end of file diff --git a/YavscLib/Properties/AssemblyInfo.cs b/YavscLib/Properties/AssemblyInfo.cs index fb9baf41..fadca10f 100644 --- a/YavscLib/Properties/AssemblyInfo.cs +++ b/YavscLib/Properties/AssemblyInfo.cs @@ -1,7 +1,5 @@ using System.Resources; using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/YavscLib/YavscLib.csproj b/YavscLib/YavscLib.csproj index 85b13f6e..0305d7aa 100644 --- a/YavscLib/YavscLib.csproj +++ b/YavscLib/YavscLib.csproj @@ -57,6 +57,7 @@ + diff --git a/YavscLib/YavscLib.sln b/YavscLib/YavscLib.sln index 88788b1f..1f586d05 100644 --- a/YavscLib/YavscLib.sln +++ b/YavscLib/YavscLib.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Client", "Yavsc.Client.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YavscLib", "YavscLib.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/YavscLib/project.json b/YavscLib/project.json index 6204fd2a..7700f259 100644 --- a/YavscLib/project.json +++ b/YavscLib/project.json @@ -15,6 +15,13 @@ "dependencies": {}, "frameworks": { "net451": {}, - ".NETPortable,Version=v4.5,Profile=Profile111": {} + ".NETPortable,Version=v4.5,Profile=Profile111": { + "frameworkAssemblies": { + "System.Runtime": "4.0.0", + "System.Globalization": "4.0.0", + "System.Resources.ResourceManager": "4.0.0", + "System.Resources.Reader": "4.0.0" + } + } } } \ No newline at end of file diff --git a/YavscLib/project.lock.json b/YavscLib/project.lock.json index a7ebab43..29807b00 100644 --- a/YavscLib/project.lock.json +++ b/YavscLib/project.lock.json @@ -3,14 +3,21 @@ "version": 2, "targets": { ".NETFramework,Version=v4.5.1": {}, - ".NETPortable,Version=v4.5,Profile=Profile111": {} + ".NETPortable,Version=v4.5,Profile=Profile111": {}, + ".NETFramework,Version=v4.5.1/debian.8-x86": {}, + ".NETFramework,Version=v4.5.1/debian.8-x64": {}, + ".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x86": {}, + ".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x64": {} }, "libraries": {}, "projectFileDependencyGroups": { "": [], ".NETFramework,Version=v4.5.1": [], - ".NETPortable,Version=v4.5,Profile=Profile111": [] - }, - "tools": {}, - "projectFileToolGroups": {} + ".NETPortable,Version=v4.5,Profile=Profile111": [ + "fx/System.Runtime >= 4.0.0", + "fx/System.Globalization >= 4.0.0", + "fx/System.Resources.ResourceManager >= 4.0.0", + "fx/System.Resources.Reader >= 4.0.0" + ] + } } \ No newline at end of file