示例#1
0
        // Fill
        public string FillEmailDistributionListContact(EmailDistributionListContact emailDistributionListContactNew, EmailDistributionListContactModel emailDistributionListContactModel, ContactOK contactOK)
        {
            emailDistributionListContactNew.DBCommand = (int)emailDistributionListContactModel.DBCommand;
            emailDistributionListContactNew.EmailDistributionListID = emailDistributionListContactModel.EmailDistributionListID;
            emailDistributionListContactNew.IsCC = emailDistributionListContactModel.IsCC;
            //emailDistributionListContactNew.Agency = emailDistributionListContactModel.Agency;
            emailDistributionListContactNew.Name  = emailDistributionListContactModel.Name;
            emailDistributionListContactNew.Email = emailDistributionListContactModel.Email;
            emailDistributionListContactNew.CMPRainfallSeasonal = emailDistributionListContactModel.CMPRainfallSeasonal;
            emailDistributionListContactNew.CMPWastewater       = emailDistributionListContactModel.CMPWastewater;
            emailDistributionListContactNew.EmergencyWeather    = emailDistributionListContactModel.EmergencyWeather;
            emailDistributionListContactNew.EmergencyWastewater = emailDistributionListContactModel.EmergencyWastewater;
            emailDistributionListContactNew.ReopeningAllTypes   = emailDistributionListContactModel.ReopeningAllTypes;
            emailDistributionListContactNew.LastUpdateDate_UTC  = DateTime.UtcNow;
            if (contactOK == null)
            {
                emailDistributionListContactNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                emailDistributionListContactNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
示例#2
0
        public EmailDistributionListContactModel PostDeleteEmailDistributionListContactDB(int emailDistributionListContactID)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            EmailDistributionListContact emailDistributionListContactToDelete = GetEmailDistributionListContactWithEmailDistributionListContactIDDB(emailDistributionListContactID);

            if (emailDistributionListContactToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.EmailDistributionListContact)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.EmailDistributionListContacts.Remove(emailDistributionListContactToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("EmailDistributionListContacts", emailDistributionListContactToDelete.EmailDistributionListContactID, LogCommandEnum.Delete, emailDistributionListContactToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
示例#3
0
        public EmailDistributionListContact GetEmailDistributionListContactWithEmailDistributionListContactIDDB(int EmailDistributionListContactID)
        {
            EmailDistributionListContact emailDistributionListContact = (from c in db.EmailDistributionListContacts
                                                                         where c.EmailDistributionListContactID == EmailDistributionListContactID
                                                                         select c).FirstOrDefault <EmailDistributionListContact>();

            return(emailDistributionListContact);
        }
        public void EmailDistributionListContact_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactController emailDistributionListContactController = new EmailDistributionListContactController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactController.DatabaseType);

                    EmailDistributionListContact emailDistributionListContactLast = new EmailDistributionListContact();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(query, db, ContactID);
                        emailDistributionListContactLast = (from c in db.EmailDistributionListContacts select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContact info
                    IHttpActionResult jsonRet = emailDistributionListContactController.GetEmailDistributionListContactWithID(emailDistributionListContactLast.EmailDistributionListContactID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContact> Ret = jsonRet as OkNegotiatedContentResult <EmailDistributionListContact>;
                    EmailDistributionListContact emailDistributionListContactRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactLast.EmailDistributionListContactID, emailDistributionListContactRet.EmailDistributionListContactID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = emailDistributionListContactController.Put(emailDistributionListContactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNotNull(emailDistributionListContactRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because EmailDistributionListContactID of 0 does not exist
                    emailDistributionListContactRet.EmailDistributionListContactID = 0;
                    IHttpActionResult jsonRet3 = emailDistributionListContactController.Put(emailDistributionListContactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet3 = jsonRet3 as OkNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNull(emailDistributionListContactRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
示例#5
0
        public void EmailDistributionListContact_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    EmailDistributionListContact emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

                    count = emailDistributionListContactService.GetEmailDistributionListContactList().Count();

                    Assert.AreEqual(count, (from c in dbTestDB.EmailDistributionListContacts select c).Count());

                    emailDistributionListContactService.Add(emailDistributionListContact);
                    if (emailDistributionListContact.HasErrors)
                    {
                        Assert.AreEqual("", emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, emailDistributionListContactService.GetEmailDistributionListContactList().Where(c => c == emailDistributionListContact).Any());
                    emailDistributionListContactService.Update(emailDistributionListContact);
                    if (emailDistributionListContact.HasErrors)
                    {
                        Assert.AreEqual("", emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, emailDistributionListContactService.GetEmailDistributionListContactList().Count());
                    emailDistributionListContactService.Delete(emailDistributionListContact);
                    if (emailDistributionListContact.HasErrors)
                    {
                        Assert.AreEqual("", emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, emailDistributionListContactService.GetEmailDistributionListContactList().Count());
                }
            }
        }
示例#6
0
        private EmailDistributionListContact GetFilledRandomEmailDistributionListContact(string OmitPropName)
        {
            EmailDistributionListContact emailDistributionListContact = new EmailDistributionListContact();

            if (OmitPropName != "EmailDistributionListID")
            {
                emailDistributionListContact.EmailDistributionListID = 1;
            }
            if (OmitPropName != "IsCC")
            {
                emailDistributionListContact.IsCC = true;
            }
            if (OmitPropName != "Name")
            {
                emailDistributionListContact.Name = GetRandomString("", 5);
            }
            if (OmitPropName != "Email")
            {
                emailDistributionListContact.Email = GetRandomEmail();
            }
            if (OmitPropName != "CMPRainfallSeasonal")
            {
                emailDistributionListContact.CMPRainfallSeasonal = true;
            }
            if (OmitPropName != "CMPWastewater")
            {
                emailDistributionListContact.CMPWastewater = true;
            }
            if (OmitPropName != "EmergencyWeather")
            {
                emailDistributionListContact.EmergencyWeather = true;
            }
            if (OmitPropName != "EmergencyWastewater")
            {
                emailDistributionListContact.EmergencyWastewater = true;
            }
            if (OmitPropName != "ReopeningAllTypes")
            {
                emailDistributionListContact.ReopeningAllTypes = true;
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                emailDistributionListContact.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                emailDistributionListContact.LastUpdateContactTVItemID = 2;
            }

            return(emailDistributionListContact);
        }
示例#7
0
        public IHttpActionResult GetEmailDistributionListContactWithID([FromUri] int EmailDistributionListContactID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                emailDistributionListContactService.Query = emailDistributionListContactService.FillQuery(typeof(EmailDistributionListContact), lang, 0, 1, "", "", extra);

                if (emailDistributionListContactService.Query.Extra == "A")
                {
                    EmailDistributionListContactExtraA emailDistributionListContactExtraA = new EmailDistributionListContactExtraA();
                    emailDistributionListContactExtraA = emailDistributionListContactService.GetEmailDistributionListContactExtraAWithEmailDistributionListContactID(EmailDistributionListContactID);

                    if (emailDistributionListContactExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(emailDistributionListContactExtraA));
                }
                else if (emailDistributionListContactService.Query.Extra == "B")
                {
                    EmailDistributionListContactExtraB emailDistributionListContactExtraB = new EmailDistributionListContactExtraB();
                    emailDistributionListContactExtraB = emailDistributionListContactService.GetEmailDistributionListContactExtraBWithEmailDistributionListContactID(EmailDistributionListContactID);

                    if (emailDistributionListContactExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(emailDistributionListContactExtraB));
                }
                else
                {
                    EmailDistributionListContact emailDistributionListContact = new EmailDistributionListContact();
                    emailDistributionListContact = emailDistributionListContactService.GetEmailDistributionListContactWithEmailDistributionListContactID(EmailDistributionListContactID);

                    if (emailDistributionListContact == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(emailDistributionListContact));
                }
            }
        }
示例#8
0
        public bool Update(EmailDistributionListContact emailDistributionListContact)
        {
            emailDistributionListContact.ValidationResults = Validate(new ValidationContext(emailDistributionListContact), ActionDBTypeEnum.Update);
            if (emailDistributionListContact.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.EmailDistributionListContacts.Update(emailDistributionListContact);

            if (!TryToSave(emailDistributionListContact))
            {
                return(false);
            }

            return(true);
        }
示例#9
0
        private bool TryToSave(EmailDistributionListContact emailDistributionListContact)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                emailDistributionListContact.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
        public void EmailDistributionListContact_Controller_GetEmailDistributionListContactWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactController emailDistributionListContactController = new EmailDistributionListContactController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactController.DatabaseType);

                    EmailDistributionListContact emailDistributionListContactFirst = new EmailDistributionListContact();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query(), db, ContactID);
                        emailDistributionListContactFirst = (from c in db.EmailDistributionListContacts select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContact info
                    IHttpActionResult jsonRet = emailDistributionListContactController.GetEmailDistributionListContactWithID(emailDistributionListContactFirst.EmailDistributionListContactID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContact> Ret = jsonRet as OkNegotiatedContentResult <EmailDistributionListContact>;
                    EmailDistributionListContact emailDistributionListContactRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactFirst.EmailDistributionListContactID, emailDistributionListContactRet.EmailDistributionListContactID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = emailDistributionListContactController.GetEmailDistributionListContactWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNull(emailDistributionListContactRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
示例#11
0
        public IHttpActionResult Delete([FromBody] EmailDistributionListContact emailDistributionListContact, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!emailDistributionListContactService.Delete(emailDistributionListContact))
                {
                    return(BadRequest(String.Join("|||", emailDistributionListContact.ValidationResults)));
                }
                else
                {
                    emailDistributionListContact.ValidationResults = null;
                    return(Ok(emailDistributionListContact));
                }
            }
        }
示例#12
0
        public void GetEmailDistributionListContactList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    EmailDistributionListContact emailDistributionListContact = (from c in dbTestDB.EmailDistributionListContacts select c).FirstOrDefault();
                    Assert.IsNotNull(emailDistributionListContact);

                    List <EmailDistributionListContact> emailDistributionListContactDirectQueryList = new List <EmailDistributionListContact>();
                    emailDistributionListContactDirectQueryList = (from c in dbTestDB.EmailDistributionListContacts select c).Take(200).ToList();

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        emailDistributionListContactService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <EmailDistributionListContact> emailDistributionListContactList = new List <EmailDistributionListContact>();
                            emailDistributionListContactList = emailDistributionListContactService.GetEmailDistributionListContactList().ToList();
                            CheckEmailDistributionListContactFields(emailDistributionListContactList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
示例#13
0
 public EmailDistributionListContactTest()
 {
     emailDistributionListContact       = new EmailDistributionListContact();
     emailDistributionListContactExtraA = new EmailDistributionListContactExtraA();
     emailDistributionListContactExtraB = new EmailDistributionListContactExtraB();
 }
示例#14
0
        /// <summary>
        /// Validate function for all EmailDistributionListContactLanguageService commands
        /// </summary>
        /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param>
        /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param>
        /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns>
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string retStr = "";
            Enums  enums  = new Enums(LanguageRequest);
            EmailDistributionListContactLanguage emailDistributionListContactLanguage = validationContext.ObjectInstance as EmailDistributionListContactLanguage;

            emailDistributionListContactLanguage.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (emailDistributionListContactLanguage.EmailDistributionListContactLanguageID == 0)
                {
                    emailDistributionListContactLanguage.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "EmailDistributionListContactLanguageID"), new[] { "EmailDistributionListContactLanguageID" }));
                }

                if (!(from c in db.EmailDistributionListContactLanguages select c).Where(c => c.EmailDistributionListContactLanguageID == emailDistributionListContactLanguage.EmailDistributionListContactLanguageID).Any())
                {
                    emailDistributionListContactLanguage.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionListContactLanguage", "EmailDistributionListContactLanguageID", emailDistributionListContactLanguage.EmailDistributionListContactLanguageID.ToString()), new[] { "EmailDistributionListContactLanguageID" }));
                }
            }

            EmailDistributionListContact EmailDistributionListContactEmailDistributionListContactID = (from c in db.EmailDistributionListContacts where c.EmailDistributionListContactID == emailDistributionListContactLanguage.EmailDistributionListContactID select c).FirstOrDefault();

            if (EmailDistributionListContactEmailDistributionListContactID == null)
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionListContact", "EmailDistributionListContactID", emailDistributionListContactLanguage.EmailDistributionListContactID.ToString()), new[] { "EmailDistributionListContactID" }));
            }

            retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)emailDistributionListContactLanguage.Language);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" }));
            }

            if (string.IsNullOrWhiteSpace(emailDistributionListContactLanguage.Agency))
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Agency"), new[] { "Agency" }));
            }

            if (!string.IsNullOrWhiteSpace(emailDistributionListContactLanguage.Agency) && (emailDistributionListContactLanguage.Agency.Length < 1 || emailDistributionListContactLanguage.Agency.Length > 100))
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Agency", "1", "100"), new[] { "Agency" }));
            }

            retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)emailDistributionListContactLanguage.TranslationStatus);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), new[] { "TranslationStatus" }));
            }

            if (emailDistributionListContactLanguage.LastUpdateDate_UTC.Year == 1)
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (emailDistributionListContactLanguage.LastUpdateDate_UTC.Year < 1980)
                {
                    emailDistributionListContactLanguage.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == emailDistributionListContactLanguage.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", emailDistributionListContactLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    emailDistributionListContactLanguage.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                emailDistributionListContactLanguage.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
        public void EmailDistributionListContact_Controller_GetEmailDistributionListContactList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactController emailDistributionListContactController = new EmailDistributionListContactController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactController.DatabaseType);

                    EmailDistributionListContact emailDistributionListContactFirst = new EmailDistributionListContact();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(query, db, ContactID);
                        emailDistributionListContactFirst = (from c in db.EmailDistributionListContacts select c).FirstOrDefault();
                        count = (from c in db.EmailDistributionListContacts select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with EmailDistributionListContact info
                    IHttpActionResult jsonRet = emailDistributionListContactController.GetEmailDistributionListContactList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <EmailDistributionListContact> > ret = jsonRet as OkNegotiatedContentResult <List <EmailDistributionListContact> >;
                    Assert.AreEqual(emailDistributionListContactFirst.EmailDistributionListContactID, ret.Content[0].EmailDistributionListContactID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <EmailDistributionListContact> emailDistributionListContactList = new List <EmailDistributionListContact>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(query, db, ContactID);
                        emailDistributionListContactList = (from c in db.EmailDistributionListContacts select c).OrderBy(c => c.EmailDistributionListContactID).Skip(0).Take(2).ToList();
                        count = (from c in db.EmailDistributionListContacts select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with EmailDistributionListContact info
                        jsonRet = emailDistributionListContactController.GetEmailDistributionListContactList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <EmailDistributionListContact> >;
                        Assert.AreEqual(emailDistributionListContactList[0].EmailDistributionListContactID, ret.Content[0].EmailDistributionListContactID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with EmailDistributionListContact info
                            IHttpActionResult jsonRet2 = emailDistributionListContactController.GetEmailDistributionListContactList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <EmailDistributionListContact> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <EmailDistributionListContact> >;
                            Assert.AreEqual(emailDistributionListContactList[1].EmailDistributionListContactID, ret2.Content[0].EmailDistributionListContactID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
示例#16
0
        public EmailDistributionListContactModel PostUpdateEmailDistributionListContactDB(EmailDistributionListContactModel emailDistributionListContactModel)
        {
            string retStr = EmailDistributionListContactModelOK(emailDistributionListContactModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            EmailDistributionListContact emailDistributionListContactToUpdate = GetEmailDistributionListContactWithEmailDistributionListContactIDDB(emailDistributionListContactModel.EmailDistributionListContactID);

            if (emailDistributionListContactToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.EmailDistributionListContact)));
            }

            retStr = FillEmailDistributionListContact(emailDistributionListContactToUpdate, emailDistributionListContactModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("EmailDistributionListContacts", emailDistributionListContactToUpdate.EmailDistributionListContactID, LogCommandEnum.Change, emailDistributionListContactToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                foreach (LanguageEnum Lang in LanguageListAllowable)
                {
                    if (Lang == LanguageRequest)
                    {
                        EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModel = new EmailDistributionListContactLanguageModel()
                        {
                            DBCommand = DBCommandEnum.Original,
                            EmailDistributionListContactID = emailDistributionListContactToUpdate.EmailDistributionListContactID,
                            Language          = Lang,
                            Agency            = emailDistributionListContactModel.Agency,
                            TranslationStatus = TranslationStatusEnum.Translated,
                        };

                        EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModelRet = _EmailDistributionListContactLanguageService.PostUpdateEmailDistributionListContactLanguageDB(emailDistributionListContactLanguageModel);
                        if (!string.IsNullOrEmpty(emailDistributionListContactLanguageModelRet.Error))
                        {
                            return(ReturnError(string.Format(ServiceRes.CouldNotAddError_, emailDistributionListContactLanguageModelRet.Error)));
                        }
                    }
                }

                ts.Complete();
            }
            return(GetEmailDistributionListContactModelWithEmailDistributionListContactIDDB(emailDistributionListContactToUpdate.EmailDistributionListContactID));
        }
示例#17
0
        public void EmailDistributionListContact_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    count = emailDistributionListContactService.GetEmailDistributionListContactList().Count();

                    EmailDistributionListContact emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");

                    // -------------------------------
                    // -------------------------------
                    // Properties testing
                    // -------------------------------
                    // -------------------------------


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // emailDistributionListContact.EmailDistributionListContactID   (Int32)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.EmailDistributionListContactID = 0;
                    emailDistributionListContactService.Update(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "EmailDistributionListContactID"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.EmailDistributionListContactID = 10000000;
                    emailDistributionListContactService.Update(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionListContact", "EmailDistributionListContactID", emailDistributionListContact.EmailDistributionListContactID.ToString()), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "EmailDistributionList", ExistPlurial = "s", ExistFieldID = "EmailDistributionListID", AllowableTVtypeList = )]
                    // emailDistributionListContact.EmailDistributionListID   (Int32)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.EmailDistributionListID = 0;
                    emailDistributionListContactService.Add(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionList", "EmailDistributionListID", emailDistributionListContact.EmailDistributionListID.ToString()), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.IsCC   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(100))]
                    // emailDistributionListContact.Name   (String)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("Name");
                    Assert.AreEqual(false, emailDistributionListContactService.Add(emailDistributionListContact));
                    Assert.AreEqual(1, emailDistributionListContact.ValidationResults.Count());
                    Assert.IsTrue(emailDistributionListContact.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Name")).Any());
                    Assert.AreEqual(null, emailDistributionListContact.Name);
                    Assert.AreEqual(count, emailDistributionListContactService.GetEmailDistributionListContactList().Count());

                    emailDistributionListContact      = null;
                    emailDistributionListContact      = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.Name = GetRandomString("", 101);
                    Assert.AreEqual(false, emailDistributionListContactService.Add(emailDistributionListContact));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Name", "100"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, emailDistributionListContactService.GetEmailDistributionListContactList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [DataType(DataType.EmailAddress)]
                    // [StringLength(200))]
                    // emailDistributionListContact.Email   (String)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("Email");
                    Assert.AreEqual(false, emailDistributionListContactService.Add(emailDistributionListContact));
                    Assert.AreEqual(1, emailDistributionListContact.ValidationResults.Count());
                    Assert.IsTrue(emailDistributionListContact.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Email")).Any());
                    Assert.AreEqual(null, emailDistributionListContact.Email);
                    Assert.AreEqual(count, emailDistributionListContactService.GetEmailDistributionListContactList().Count());

                    emailDistributionListContact       = null;
                    emailDistributionListContact       = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.Email = GetRandomString("", 201);
                    Assert.AreEqual(false, emailDistributionListContactService.Add(emailDistributionListContact));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Email", "200"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, emailDistributionListContactService.GetEmailDistributionListContactList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.CMPRainfallSeasonal   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.CMPWastewater   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.EmergencyWeather   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.EmergencyWastewater   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // emailDistributionListContact.ReopeningAllTypes   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // emailDistributionListContact.LastUpdateDate_UTC   (DateTime)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.LastUpdateDate_UTC = new DateTime();
                    emailDistributionListContactService.Add(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);
                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.LastUpdateDate_UTC = new DateTime(1979, 1, 1);
                    emailDistributionListContactService.Add(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)]
                    // emailDistributionListContact.LastUpdateContactTVItemID   (Int32)
                    // -----------------------------------

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.LastUpdateContactTVItemID = 0;
                    emailDistributionListContactService.Add(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", emailDistributionListContact.LastUpdateContactTVItemID.ToString()), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);

                    emailDistributionListContact = null;
                    emailDistributionListContact = GetFilledRandomEmailDistributionListContact("");
                    emailDistributionListContact.LastUpdateContactTVItemID = 1;
                    emailDistributionListContactService.Add(emailDistributionListContact);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), emailDistributionListContact.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // emailDistributionListContact.HasErrors   (Boolean)
                    // -----------------------------------

                    // No testing requied

                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // emailDistributionListContact.ValidationResults   (IEnumerable`1)
                    // -----------------------------------

                    // No testing requied
                }
            }
        }
        public void EmailDistributionListContact_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactController emailDistributionListContactController = new EmailDistributionListContactController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactController.DatabaseType);

                    EmailDistributionListContact emailDistributionListContactLast = new EmailDistributionListContact();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        EmailDistributionListContactService emailDistributionListContactService = new EmailDistributionListContactService(query, db, ContactID);
                        emailDistributionListContactLast = (from c in db.EmailDistributionListContacts select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContact info
                    IHttpActionResult jsonRet = emailDistributionListContactController.GetEmailDistributionListContactWithID(emailDistributionListContactLast.EmailDistributionListContactID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContact> Ret = jsonRet as OkNegotiatedContentResult <EmailDistributionListContact>;
                    EmailDistributionListContact emailDistributionListContactRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactLast.EmailDistributionListContactID, emailDistributionListContactRet.EmailDistributionListContactID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because EmailDistributionListContactID exist
                    IHttpActionResult jsonRet2 = emailDistributionListContactController.Post(emailDistributionListContactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNull(emailDistributionListContactRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added EmailDistributionListContact
                    emailDistributionListContactRet.EmailDistributionListContactID = 0;
                    emailDistributionListContactController.Request            = new System.Net.Http.HttpRequestMessage();
                    emailDistributionListContactController.Request.RequestUri = new System.Uri("http://localhost:5000/api/emailDistributionListContact");
                    IHttpActionResult jsonRet3 = emailDistributionListContactController.Post(emailDistributionListContactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet3 = jsonRet3 as CreatedNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNotNull(emailDistributionListContactRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = emailDistributionListContactController.Delete(emailDistributionListContactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <EmailDistributionListContact> emailDistributionListContactRet4 = jsonRet4 as OkNegotiatedContentResult <EmailDistributionListContact>;
                    Assert.IsNotNull(emailDistributionListContactRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
示例#19
0
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string retStr = "";
            Enums  enums  = new Enums(LanguageRequest);
            EmailDistributionListContact emailDistributionListContact = validationContext.ObjectInstance as EmailDistributionListContact;

            emailDistributionListContact.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (emailDistributionListContact.EmailDistributionListContactID == 0)
                {
                    emailDistributionListContact.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "EmailDistributionListContactID"), new[] { "EmailDistributionListContactID" }));
                }

                if (!(from c in db.EmailDistributionListContacts select c).Where(c => c.EmailDistributionListContactID == emailDistributionListContact.EmailDistributionListContactID).Any())
                {
                    emailDistributionListContact.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionListContact", "EmailDistributionListContactID", emailDistributionListContact.EmailDistributionListContactID.ToString()), new[] { "EmailDistributionListContactID" }));
                }
            }

            EmailDistributionList EmailDistributionListEmailDistributionListID = (from c in db.EmailDistributionLists where c.EmailDistributionListID == emailDistributionListContact.EmailDistributionListID select c).FirstOrDefault();

            if (EmailDistributionListEmailDistributionListID == null)
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "EmailDistributionList", "EmailDistributionListID", emailDistributionListContact.EmailDistributionListID.ToString()), new[] { "EmailDistributionListID" }));
            }

            if (string.IsNullOrWhiteSpace(emailDistributionListContact.Name))
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Name"), new[] { "Name" }));
            }

            if (!string.IsNullOrWhiteSpace(emailDistributionListContact.Name) && emailDistributionListContact.Name.Length > 100)
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Name", "100"), new[] { "Name" }));
            }

            if (string.IsNullOrWhiteSpace(emailDistributionListContact.Email))
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Email"), new[] { "Email" }));
            }

            if (!string.IsNullOrWhiteSpace(emailDistributionListContact.Email) && emailDistributionListContact.Email.Length > 200)
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Email", "200"), new[] { "Email" }));
            }

            if (!string.IsNullOrWhiteSpace(emailDistributionListContact.Email))
            {
                Regex regex = new Regex(@"^([\w\!\#$\%\&\'*\+\-\/\=\?\^`{\|\}\~]+\.)*[\w\!\#$\%\&\'‌​*\+\-\/\=\?\^`{\|\}\~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9\-]{0,62}[a-zA-Z0-9]{1})|[‌​a-zA-Z])\.)+[a-zA-Z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$");
                if (!regex.IsMatch(emailDistributionListContact.Email))
                {
                    emailDistributionListContact.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotAValidEmail, "Email"), new[] { "Email" }));
                }
            }

            if (emailDistributionListContact.LastUpdateDate_UTC.Year == 1)
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (emailDistributionListContact.LastUpdateDate_UTC.Year < 1980)
                {
                    emailDistributionListContact.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == emailDistributionListContact.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", emailDistributionListContact.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    emailDistributionListContact.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                emailDistributionListContact.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }