Esempio n. 1
0
        public async Task <IActionResult> DeleteLayout([FromRoute] DeleteLayout command)
        {
            await rules.LayoutCannotBeInUse()
            .Apply(command, ModelState);

            if (ModelState.IsValid)
            {
                await service.Execute(command);

                return(Ok());
            }

            return(BadRequest(ModelState));
        }
Esempio n. 2
0
        //TODO:  This should be a delete in sql or add cascade delete
        public async Task Execute(DeleteLayout command)
        {
            var item = writeContext.SurveyLayout.Where(l => l.UID.Equals(command)).FirstOrDefault();

            // remove tags associated
            writeContext.SurveyLayoutTag.RemoveRange(writeContext.SurveyLayoutTag.Where(l => l.UidLayout.Equals(item.UID)));

            //remove associated questions
            writeContext.SurveyLayoutQuestion.RemoveRange(writeContext.SurveyLayoutQuestion.Where(l => l.UidLayout.Equals(item.UID)));

            // remove layout
            writeContext.SurveyLayout.Remove(item);

            await writeContext.SaveChangesAsync();
        }