Esempio n. 1
0
        // Olga, Change:
        public async Task <MailingsGeneratorDomain.Models.Mailing> CreateMailingAsync(
            MailingsGeneratorDomain.Models.Mailing mail)
        {
            if (mail == null)
            {
                throw new ExceptionTypes.NullValueException();
            }
            if (mail.CourseName == null)
            {
                throw new ExceptionTypes.IncorrectNameException();
            }

            CheckDate(mail.StartDate);

            if (mail.TextId != null)
            {
                GetElements <Text> getTexts = _textRepository.GetTextsAsyncById;
                await AddElement(mail.MailText, mail.TextId, getTexts, new ExceptionTypes.TextNotExistException());
            }

            if (mail.WorksId != null)
            {
                GetElements <ControlEvent> getElements = _eventRepository.GetControlEventsAsyncById;
                await AddElement(mail.Works, mail.WorksId, getElements, new ExceptionTypes.ControlEventNotExistException());

                foreach (var work in mail.Works)
                {
                    var text = await _textRepository.CreateTextAsync(new Text()
                    {
                        RememberAboutDeadline = "Контрольное мероприятие " + work.ControlEventId,
                        InfomationPart        = "Дедлайн:  " + work.Date
                    });

                    mail.MailText.Add(text);
                }
            }

            if (mail.FinishWorkId != 0)
            {
                var finishWork = await _eventRepository.GetControlEventAsync(mail.FinishWorkId);

                if (finishWork == null)
                {
                    throw new ExceptionTypes.ControlEventNotExistException();
                }

                mail.FinishWork = finishWork;
            }

            return(await _repository.CreateMailingAsync(mail));
        }
Esempio n. 2
0
        public async Task <Text> CreateTextAsync(Text text)
        {
            if (text == null)
            {
                throw new ExceptionTypes.NullValueException();
            }

            if (text.InfomationPart == null)
            {
                throw  new ExceptionTypes.IncorrectNameException();
            }

            if (text.MailId > 1)
            {
                var mail = await _repositoryMailing.GetCourseAsync(text.MailId);

                if (mail == null)
                {
                    throw new ExceptionTypes.MailingNotExistException();
                }

                text.Mail = mail;
            }

            return(await _repository.CreateTextAsync(text));
        }