This commit is contained in:
2020-12-15 01:25:55 +00:00
parent 10c168006f
commit 9c65341b49
4 changed files with 66 additions and 40 deletions

View File

@@ -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
/// <param name="apiVersion">From route path</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> PostMemo([FromBody] Memo newObject, ApiVersion apiVersion)
public async Task<IActionResult> 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<long>();
}
[Required]
public Memo Memo { get; set; }
[Required]
public List<long> Users { get; set; }
}
//------------
//NO DUPLICATING MEMOS
// /// <summary>

View File

@@ -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;

View File

@@ -396,7 +396,7 @@ namespace AyaNova.Api.Controllers
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
}
//Return the list of attachment ids and filenames
//Return nothing
return Accepted();
}

View File

@@ -60,38 +60,40 @@ namespace AyaNova.Biz
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE
//
internal async Task<Memo> 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<Memo> 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