Example #1
0
        public ServiceResult <Guid?> UpdateHomeworkTemplate(HomeworkTemplateRequest homeworkTemplateRequest)
        {
            string validationMessage = ValidateHomeworkTemplateRequest(homeworkTemplateRequest);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                return(errorService.Error <Guid?>(validationMessage));
            }

            HomeworkTemplate homeworkTemplate = flytDexContext.HomeworkTemplates.SingleOrDefault(ht => ht.Id == homeworkTemplateRequest.Id);

            if (homeworkTemplate == null)
            {
                return(errorService.Error <Guid?>("An error occurred: Invalid HomeworkTemplate - not found"));
            }

            homeworkTemplate.Description = homeworkTemplateRequest.Description;
            homeworkTemplate.Title       = homeworkTemplateRequest.Title;

            flytDexContext.HomeworkTemplates.Update(homeworkTemplate);

            if (flytDexContext.SaveChanges() <= 0)
            {
                return(errorService.Error <Guid?>("Error updating HomeworkTemplate, see log for error message"));
            }

            return(new ServiceResult <Guid?>(homeworkTemplate.Id, ResultType.Success, "Success"));
        }
Example #2
0
        public ServiceResult <HomeworkTemplateDto> CreateHomeworkTemplate(HomeworkTemplateRequest homeworkTemplateRequest)
        {
            string validationMessage = ValidateHomeworkTemplateRequest(homeworkTemplateRequest);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                return(errorService.Error <HomeworkTemplateDto>(validationMessage));
            }

            if (flytDexContext.HomeworkTemplates.Any(ht => ht.Id == homeworkTemplateRequest.Id))
            {
                return(errorService.Error <HomeworkTemplateDto>("An error occurred: A homework template with this Id already exists"));
            }

            HomeworkTemplate homeworkTemplate = mapper.Map <HomeworkTemplateRequest, HomeworkTemplate>(homeworkTemplateRequest);

            flytDexContext.HomeworkTemplates.Add(homeworkTemplate);

            if (flytDexContext.SaveChanges() < 0)
            {
                return(errorService.Error <HomeworkTemplateDto>("An error occurred: Unable to save HomeworkTemplate"));
            }

            HomeworkTemplateDto homeworkTemplateDto = mapper.Map <HomeworkTemplate, HomeworkTemplateDto>(homeworkTemplate);

            return(new ServiceResult <HomeworkTemplateDto>(homeworkTemplateDto, ResultType.Success, "Success"));
        }