diff --git a/server/AyaNova/Controllers/ScheduleController.cs b/server/AyaNova/Controllers/ScheduleController.cs index 7c947a31..9ceb2dfc 100644 --- a/server/AyaNova/Controllers/ScheduleController.cs +++ b/server/AyaNova/Controllers/ScheduleController.cs @@ -143,6 +143,19 @@ namespace AyaNova.Api.Controllers } } break; + case AyaType.Review: + { + ReviewBiz biz = ReviewBiz.GetBiz(ct, HttpContext); + var o = await biz.PutNewScheduleTimeAsync(ad); + if (o == false) + { + if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT)) + return StatusCode(409, new ApiErrorResponse(biz.Errors)); + else + return BadRequest(new ApiErrorResponse(biz.Errors)); + } + } + break; default: return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, "Type", "Type not supported for adjustment")); } diff --git a/server/AyaNova/biz/ReviewBiz.cs b/server/AyaNova/biz/ReviewBiz.cs index 15efc252..9da85452 100644 --- a/server/AyaNova/biz/ReviewBiz.cs +++ b/server/AyaNova/biz/ReviewBiz.cs @@ -60,38 +60,7 @@ namespace AyaNova.Biz } } - // //////////////////////////////////////////////////////////////////////////////////////////////// - // //DUPLICATE - // // - // internal async Task DuplicateAsync(long id) - // { - // var dbObject = await GetAsync(id, false); - // if (dbObject == null) - // { - // AddError(ApiErrorCode.NOT_FOUND, "id"); - // return null; - // } - // var newObject = new Review(); - // 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.Review.AnyAsync(m => m.Name == newUniqueName); - // } while (NotUnique); - // newObject.Name = newUniqueName; - // newObject.Id = 0; - // newObject.Concurrency = 0; - // await ct.Review.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 HandlePotentialNotificationEvent(AyaEvent.Created, newObject); - // return newObject; - // } + //////////////////////////////////////////////////////////////////////////////////////////////// //GET @@ -145,6 +114,42 @@ namespace AyaNova.Biz return putObject; } + + //////////////////////////////////////////////////////////////////////////////////////////////// + //UPDATE schedule only + // + internal async Task PutNewScheduleTimeAsync(ScheduleItemAdjustParams p) + { + Review dbObject = await ct.Review.SingleOrDefaultAsync(z => z.Id == p.Id); + if (dbObject == null) + { + AddError(ApiErrorCode.NOT_FOUND, "id"); + return false; + } + + dbObject.ReviewDate = p.Start; + + await ValidateAsync(dbObject, dbObject); + if (HasErrors) return false; + try + { + await ct.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!await ExistsAsync(dbObject.Id)) + AddError(ApiErrorCode.NOT_FOUND); + else + AddError(ApiErrorCode.CONCURRENCY_CONFLICT); + return false; + } + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, dbObject.AyaType, AyaEvent.Modified), ct); + + await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, dbObject); + return true; + } + + //////////////////////////////////////////////////////////////////////////////////////////////// //DELETE // @@ -275,6 +280,17 @@ namespace AyaNova.Biz } } + //Can't change Review date after completed + //user must set empty completed before changing start date if they really want to do this + if (!isNew && proposedObj.CompletedDate != null) + { + if (proposedObj.ReviewDate != currentObj.ReviewDate) + { + AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "ReviewDate"); + return; + } + } + //Does the object of this Review actually exist? if (!await BizObjectExistsInDatabase.ExistsAsync(proposedObj.AType, proposedObj.ObjectId, ct)) { @@ -481,7 +497,7 @@ namespace AyaNova.Biz public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null) { ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger(); - if(ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return; + if (ServerBootConfig.SEEDING || ServerBootConfig.MIGRATING) return; log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{this.BizType}, AyaEvent:{ayaEvent}]"); bool isNew = currentObj == null;