From bf09fe4a9186a1197068035aace7ac91e1a0c9a0 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 12 Dec 2016 18:37:54 +0100 Subject: [PATCH] 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; + } + } +}