dimiss notifications
This commit is contained in:
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
@ -11,7 +12,7 @@ using Yavsc.Models.Messaging;
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/DimissClicksApi")]
|
||||
[Route("api/dimiss")]
|
||||
public class DimissClicksApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
@ -29,12 +30,24 @@ namespace Yavsc.Controllers
|
||||
return _context.DimissClicked.Where(d=>d.UserId == uid);
|
||||
}
|
||||
|
||||
[HttpGet("click/{noteid}"),AllowAnonymous]
|
||||
public async Task<IActionResult> Click(long noteid )
|
||||
{
|
||||
if (User.IsSignedIn())
|
||||
return await PostDimissClicked(new DimissClicked { NotificationId= noteid, UserId = User.GetUserId()});
|
||||
await HttpContext.Session.LoadAsync();
|
||||
var clicked = HttpContext.Session.GetString("clicked");
|
||||
if (clicked == null) {
|
||||
HttpContext.Session.SetString("clicked",noteid.ToString());
|
||||
} else HttpContext.Session.SetString("clicked",$"{clicked}:{noteid}");
|
||||
await HttpContext.Session.CommitAsync();
|
||||
return Ok();
|
||||
}
|
||||
// GET: api/DimissClicksApi/5
|
||||
[HttpGet("{id}", Name = "GetDimissClicked")]
|
||||
public async Task<IActionResult> GetDimissClicked([FromRoute] string id)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (!User.IsInRole("Administrator"))
|
||||
if (uid != id) return new ChallengeResult();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
@ -57,10 +70,8 @@ namespace Yavsc.Controllers
|
||||
public async Task<IActionResult> PutDimissClicked([FromRoute] string id, [FromBody] DimissClicked dimissClicked)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (!User.IsInRole("Administrator"))
|
||||
if (uid != id || uid != dimissClicked.UserId) return new ChallengeResult();
|
||||
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
@ -97,7 +108,6 @@ namespace Yavsc.Controllers
|
||||
public async Task<IActionResult> PostDimissClicked([FromBody] DimissClicked dimissClicked)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (!User.IsInRole("Administrator"))
|
||||
if (uid != dimissClicked.UserId) return new ChallengeResult();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
|
@ -9,6 +9,9 @@ using Microsoft.AspNet.Identity;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.Data.Entity;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
@ -29,9 +32,22 @@ namespace Yavsc.Controllers
|
||||
DbContext = context;
|
||||
}
|
||||
|
||||
public IActionResult Index(string id)
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
// TDOD ViewData["Notify"] =
|
||||
|
||||
var uid = User.GetUserId();
|
||||
long [] clicked=null;
|
||||
if (uid==null) {
|
||||
await HttpContext.Session.LoadAsync();
|
||||
var strclicked = HttpContext.Session.GetString("clicked");
|
||||
if (strclicked!=null) clicked = strclicked.Split(':').Select(c=>long.Parse(c)).ToArray();
|
||||
if (clicked==null) clicked = new long [0];
|
||||
}
|
||||
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)
|
||||
);
|
||||
ViewData["Notify"] = notes;
|
||||
return View(DbContext.Activities.Where(a=>a.ParentCode==id && !a.Hidden).Include(a=>a.Forms).Include(a=>a.Children)
|
||||
.OrderByDescending(a=>a.Rate));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ using Microsoft.AspNet.Localization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Filters;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Http.Extensions;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -184,7 +185,7 @@ namespace Yavsc
|
||||
services.AddSingleton<IAuthorizationHandler, PostUserFileHandler>();
|
||||
services.AddSingleton<IAuthorizationHandler, EstimateViewHandler>();
|
||||
services.AddSingleton<IAuthorizationHandler, ViewFileHandler>();
|
||||
|
||||
|
||||
services.AddMvc(config =>
|
||||
{
|
||||
var policy = new AuthorizationPolicyBuilder()
|
||||
@ -337,7 +338,8 @@ namespace Yavsc
|
||||
ConfigureWebSocketsApp(app, SiteSetup, env);
|
||||
ConfigureWorkflow(app, SiteSetup);
|
||||
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture) new RequestCulture((string)"fr"));
|
||||
|
||||
app.UseSession();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
|
@ -38,12 +38,9 @@
|
||||
@if (ViewData ["Notify"] != null) {
|
||||
foreach (Notification n in ViewData ["Notify"] as IEnumerable<Notification>) {
|
||||
<div class="alert alert-info alert-dismissable">
|
||||
<strong>@n.title</strong> @n.body
|
||||
@if (n.click_action!=null) {
|
||||
<a class="close" data-dismiss="alert" aria-label="close" onclick="notifClick(@n.Id)">@SR[n.click_action]</a>
|
||||
} else {
|
||||
<a class="close" data-dismiss="alert" aria-label="close" >@SR[n.click_action]</a>
|
||||
}
|
||||
<em><strong>@n.title</strong></em><br>
|
||||
@n.body
|
||||
<a class="close" data-dismiss="alert" aria-label="close" onclick="notifClick(@n.Id)">@((n.click_action==null)?SR["Fermer"]:SR[n.click_action])</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,8 @@
|
||||
"System.Json": "4.0.20126.16343",
|
||||
"YavscLib": "1.0.0-*",
|
||||
"Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713",
|
||||
"PayPalMerchantSDK": "2.16.204"
|
||||
"PayPalMerchantSDK": "2.16.204",
|
||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -27,3 +27,14 @@ $('input.Blogcirle[type=checkbox]').on('change',allowCircleToBlog);
|
||||
}
|
||||
);
|
||||
|
||||
var notifClick = function(nid) { $.get('/api/dimiss/click/'+nid).done(function(data) {
|
||||
console.log( "second success" );
|
||||
console.log(data);
|
||||
|
||||
})
|
||||
.fail(function() {
|
||||
console.log( "error" );
|
||||
})
|
||||
.always(function() {
|
||||
console.log( "finished" );
|
||||
}); };
|
||||
|
@ -8,4 +8,8 @@
|
||||
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false"/>
|
||||
|
||||
</system.webServer>
|
||||
<system.web>
|
||||
<sessionState cookieless="true"
|
||||
regenerateExpiredSessionId="true" />
|
||||
</system.web>
|
||||
</configuration>
|
||||
|
Reference in New Issue
Block a user