From 9c65341b49c252984ec6769cdaf5298eb07856fe Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 15 Dec 2020 01:25:55 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/MemoController.cs | 37 +++++++++-- .../AyaNova/Controllers/NotifyController.cs | 1 - .../Controllers/TranslationController.cs | 2 +- server/AyaNova/biz/MemoBiz.cs | 66 ++++++++++--------- 4 files changed, 66 insertions(+), 40 deletions(-) diff --git a/server/AyaNova/Controllers/MemoController.cs b/server/AyaNova/Controllers/MemoController.cs index 99d31bc0..7ffa7467 100644 --- a/server/AyaNova/Controllers/MemoController.cs +++ b/server/AyaNova/Controllers/MemoController.cs @@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; @@ -43,7 +45,7 @@ namespace AyaNova.Api.Controllers /// From route path /// [HttpPost] - public async Task PostMemo([FromBody] Memo newObject, ApiVersion apiVersion) + public async Task PostMemo([FromBody] SendMemo newObject, ApiVersion apiVersion) { if (!serverState.IsOpen) return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); @@ -52,13 +54,36 @@ namespace AyaNova.Api.Controllers return StatusCode(403, new ApiNotAuthorizedResponse()); if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); - Memo o = await biz.CreateAsync(newObject); - if (o == null) - return BadRequest(new ApiErrorResponse(biz.Errors)); - else - return CreatedAtAction(nameof(MemoController.GetMemo), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o)); + var RouteUserId = UserIdFromContext.Id(HttpContext.Items); + foreach (long lUserId in newObject.Users) + { + Memo newMemo = new Memo(); + AyaNova.Util.CopyObject.Copy(newObject.Memo, newMemo); + newMemo.ToId = lUserId; + newMemo.FromId = RouteUserId; + Memo o = await biz.CreateAsync(newMemo); + if (o == null) + return BadRequest(new ApiErrorResponse(biz.Errors)); + } + + //return nothing but ok + return Accepted(); } + public class SendMemo + { + public SendMemo() + { + Users = new List(); + } + [Required] + public Memo Memo { get; set; } + + [Required] + public List Users { get; set; } + } + //------------ + //NO DUPLICATING MEMOS // /// diff --git a/server/AyaNova/Controllers/NotifyController.cs b/server/AyaNova/Controllers/NotifyController.cs index e59313ea..baa96f33 100644 --- a/server/AyaNova/Controllers/NotifyController.cs +++ b/server/AyaNova/Controllers/NotifyController.cs @@ -8,7 +8,6 @@ using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; using System.Linq; using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; diff --git a/server/AyaNova/Controllers/TranslationController.cs b/server/AyaNova/Controllers/TranslationController.cs index f9312eb7..464a5ed9 100644 --- a/server/AyaNova/Controllers/TranslationController.cs +++ b/server/AyaNova/Controllers/TranslationController.cs @@ -396,7 +396,7 @@ namespace AyaNova.Api.Controllers ApiUploadProcessor.DeleteTempUploadFile(uploadFormData); } - //Return the list of attachment ids and filenames + //Return nothing return Accepted(); } diff --git a/server/AyaNova/biz/MemoBiz.cs b/server/AyaNova/biz/MemoBiz.cs index d585cdba..5cb80d40 100644 --- a/server/AyaNova/biz/MemoBiz.cs +++ b/server/AyaNova/biz/MemoBiz.cs @@ -60,38 +60,40 @@ namespace AyaNova.Biz } } - //////////////////////////////////////////////////////////////////////////////////////////////// - //DUPLICATE - // - internal async Task DuplicateAsync(long id) - { - Memo dbObject = await GetAsync(id, false); - if (dbObject == null) - { - AddError(ApiErrorCode.NOT_FOUND, "id"); - return null; - } - Memo newObject = new Memo(); - CopyObject.Copy(dbObject, newObject, "Wiki"); - string newUniqueName = string.Empty; - bool NotUnique = true; - long l = 1; - do - { - newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255); - NotUnique = await ct.Memo.AnyAsync(m => m.Name == newUniqueName); - } while (NotUnique); - newObject.Name = newUniqueName; - newObject.Id = 0; - newObject.Concurrency = 0; - await ct.Memo.AddAsync(newObject); - await ct.SaveChangesAsync(); - await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); - await SearchIndexAsync(newObject, true); - await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); - await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject); - return newObject; - } + + + // //////////////////////////////////////////////////////////////////////////////////////////////// + // //DUPLICATE + // // + // internal async Task DuplicateAsync(long id) + // { + // Memo dbObject = await GetAsync(id, false); + // if (dbObject == null) + // { + // AddError(ApiErrorCode.NOT_FOUND, "id"); + // return null; + // } + // Memo newObject = new Memo(); + // CopyObject.Copy(dbObject, newObject, "Wiki"); + // string newUniqueName = string.Empty; + // bool NotUnique = true; + // long l = 1; + // do + // { + // newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255); + // NotUnique = await ct.Memo.AnyAsync(m => m.Name == newUniqueName); + // } while (NotUnique); + // newObject.Name = newUniqueName; + // newObject.Id = 0; + // newObject.Concurrency = 0; + // await ct.Memo.AddAsync(newObject); + // await ct.SaveChangesAsync(); + // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); + // await SearchIndexAsync(newObject, true); + // await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); + // await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject); + // return newObject; + // } //////////////////////////////////////////////////////////////////////////////////////////////// //GET