public void UpdatePurpose(object administratorId, PurposeUpdateModel model)
        {
            if (administratorId is null)
            {
                throw new ArgumentNullException(nameof(administratorId));
            }

            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            lock (dataAccessLock)
            {
                CheckAdministratorId(administratorId);
                CheckPurposeId(model.ID);

                IEnumerable <IAgreement> agreements = dataProvider.ListAgreementsByPurpose(model.ID);
                if (agreements.Any())
                {
                    throw new PersonalDataDBException($"Unable to update purpose ID \"{model.ID}\" because there are agreements referencing it.");
                }

                dataProvider.UpdatePurpose(model);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdatePurpose(PurposeUpdateModel purposeUpdateModel)
        {
            var board = await _applicationDbContext.Boards.SingleOrDefaultAsync(b => b.ID == purposeUpdateModel.BoardID);

            if (board == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Error board not found!"));
            }

            var purpose = await _applicationDbContext.Purpose.SingleOrDefaultAsync(p => p.BoardID == purposeUpdateModel.BoardID);

            purpose.Text = HttpUtility.HtmlEncode(purposeUpdateModel.Text);

            await _applicationDbContext.SaveChangesAsync();

            return(Json("Updated."));
        }