// Creates the specified form in the database
        public async Task <FormsInfo> Add(FormsInfo formInfo)
        {
            _context.FormsInfo.Add(formInfo);
            await _context.SaveChangesAsync();

            return(formInfo);
        }
        public async void MailBuilder(short FormId, int submissionId, string userEmail, bool anonymous)
        {
            subList = await GetAnswers(submissionId);

            formsInfo = await GetForm(FormId);

            string newLine = Environment.NewLine;

            if (anonymous == false)
            {
                emailBody += "Sendandi: " + userEmail + newLine + newLine;
            }
            else
            {
                emailBody += "Sendandi óskaði eftir nafnleynd" + newLine + newLine;
            }

            //Answers added to email body
            foreach (var submissionLine in subList)
            {
                emailBody += submissionLine.QuestionOrderNum + 1 + ". " + submissionLine.QuestionName + newLine;
                emailBody += "Svar: " + submissionLine.Answer + newLine + newLine;
            }
            emailBody += "Auðkenni innsendingar: " + submissionId;
            SendMail();
        }
        // Updates the specified form
        public async Task <FormsInfo> Update(FormsInfo editedForm)
        {
            var form = await _context.FormsInfo.FindAsync(editedForm.FormId);

            form.FormName              = editedForm.FormName;
            form.DestinationEmail      = editedForm.DestinationEmail;
            form.IsAnonymous           = editedForm.IsAnonymous;
            _context.Entry(form).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(form);
        }
        public async Task AddFormInfoAsync_FormInfoIsAdded()
        {
            // Arrange
            var recId         = 5;
            var addedFormInfo = new FormsInfo()
            {
                FormId = 5, FormName = "FormInfo 5", DestinationEmail = "*****@*****.**"
            };

            // Act
            await service.Add(addedFormInfo);

            // Assert
            var actualFormInfo = await db.FormsInfo.FindAsync(recId);

            Assert.Equal(actualFormInfo, addedFormInfo);
        }
        public async Task UpdateFormInfoAsync_FormInfoIsUpdated()
        {
            // Arrange
            var recId         = 3;
            var addedFormInfo = new FormsInfo()
            {
                FormId = 3, FormName = "UpdatedForm 3", DestinationEmail = "*****@*****.**"
            };
            await db.AddRangeAsync(addedFormInfo);

            await db.SaveChangesAsync();

            // Act
            await service.Update(addedFormInfo);

            // Assert
            var actualFormInfo = await db.FormsInfo.FindAsync(recId);

            Assert.Equal(actualFormInfo, addedFormInfo);
        }
        public async Task GetFormInfoAsync_FormInfoIsReturned()
        {
            var recId            = 2;
            var expectedFormInfo = new FormsInfo()
            {
                FormId = recId, FormName = "Form 2", DestinationEmail = "*****@*****.**"
            };

            // Arrange
            await db.AddRangeAsync(seedFormsInfo);

            await db.SaveChangesAsync();

            // Act
            var result = await service.GetForm(recId);

            // Assert
            var actualFormInfo = await db.FormsInfo.FindAsync(recId);

            Assert.Equal(actualFormInfo, result);
        }