// Fill
        public string FillEmailDistributionListContactLanguageModel(EmailDistributionListContactLanguage emailDistributionListContactLanguage, EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModel, ContactOK contactOK)
        {
            try
            {
                emailDistributionListContactLanguage.DBCommand = (int)emailDistributionListContactLanguageModel.DBCommand;
                emailDistributionListContactLanguage.EmailDistributionListContactID = emailDistributionListContactLanguageModel.EmailDistributionListContactID;
                emailDistributionListContactLanguage.Language           = (int)emailDistributionListContactLanguageModel.Language;
                emailDistributionListContactLanguage.Agency             = emailDistributionListContactLanguageModel.Agency;
                emailDistributionListContactLanguage.TranslationStatus  = (int)emailDistributionListContactLanguageModel.TranslationStatus;
                emailDistributionListContactLanguage.LastUpdateDate_UTC = DateTime.UtcNow;
                if (contactOK == null)
                {
                    emailDistributionListContactLanguage.LastUpdateContactTVItemID = 2;
                }
                else
                {
                    emailDistributionListContactLanguage.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("");
        }
        public EmailDistributionListContactLanguageModel PostDeleteEmailDistributionListContactLanguageDB(int EmailDistributionListContactID, LanguageEnum Language)
        {
            ContactOK contactOK = IsContactOK();

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

            EmailDistributionListContactLanguage emailDistributionListContactLanguageToDelete = GetEmailDistributionListContactLanguageWithEmailDistributionListContactIDAndLanguageDB(EmailDistributionListContactID, Language);

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

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

                LogModel logModel = _LogService.PostAddLogForObj("EmailDistributionListContactLanguages", emailDistributionListContactLanguageToDelete.EmailDistributionListContactLanguageID, LogCommandEnum.Delete, emailDistributionListContactLanguageToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
        public EmailDistributionListContactLanguage GetEmailDistributionListContactLanguageWithEmailDistributionListContactIDAndLanguageDB(int EmailDistributionListContactID, LanguageEnum Language)
        {
            EmailDistributionListContactLanguage emailDistributionListContactLanguage = (from c in db.EmailDistributionListContactLanguages
                                                                                         where c.EmailDistributionListContactID == EmailDistributionListContactID &&
                                                                                         c.Language == (int)Language
                                                                                         select c).FirstOrDefault <EmailDistributionListContactLanguage>();

            return(emailDistributionListContactLanguage);
        }
Пример #4
0
        public void EmailDistributionListContactLanguage_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactLanguageController emailDistributionListContactLanguageController = new EmailDistributionListContactLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactLanguageController.DatabaseType);

                    EmailDistributionListContactLanguage emailDistributionListContactLanguageLast = new EmailDistributionListContactLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(query, db, ContactID);
                        emailDistributionListContactLanguageLast = (from c in db.EmailDistributionListContactLanguages select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContactLanguage info
                    IHttpActionResult jsonRet = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageWithID(emailDistributionListContactLanguageLast.EmailDistributionListContactLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> Ret         = jsonRet as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    EmailDistributionListContactLanguage emailDistributionListContactLanguageRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactLanguageLast.EmailDistributionListContactLanguageID, emailDistributionListContactLanguageRet.EmailDistributionListContactLanguageID);

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

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

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNotNull(emailDistributionListContactLanguageRet2);

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

                    // Put to return CSSPError because EmailDistributionListContactLanguageID of 0 does not exist
                    emailDistributionListContactLanguageRet.EmailDistributionListContactLanguageID = 0;
                    IHttpActionResult jsonRet3 = emailDistributionListContactLanguageController.Put(emailDistributionListContactLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNull(emailDistributionListContactLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
        // Post
        public EmailDistributionListContactLanguageModel PostAddEmailDistributionListContactLanguageDB(EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModel)
        {
            string retStr = EmailDistributionListContactLanguageModelOK(emailDistributionListContactLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModelExist = GetEmailDistributionListContactLanguageModelWithEmailDistributionListContactIDAndLanguageDB(emailDistributionListContactLanguageModel.EmailDistributionListContactID, emailDistributionListContactLanguageModel.Language);

            if (string.IsNullOrWhiteSpace(emailDistributionListContactLanguageModelExist.Error))
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.EmailDistributionListContactLanguage)));
            }

            EmailDistributionListContactLanguage emailDistributionListContactLanguageNew = new EmailDistributionListContactLanguage();

            retStr = FillEmailDistributionListContactLanguageModel(emailDistributionListContactLanguageNew, emailDistributionListContactLanguageModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.EmailDistributionListContactLanguages.Add(emailDistributionListContactLanguageNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("EmailDistributionListContactLanguages", emailDistributionListContactLanguageNew.EmailDistributionListContactLanguageID, LogCommandEnum.Add, emailDistributionListContactLanguageNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetEmailDistributionListContactLanguageModelWithEmailDistributionListContactIDAndLanguageDB(emailDistributionListContactLanguageNew.EmailDistributionListContactID, (LanguageEnum)emailDistributionListContactLanguageNew.Language));
        }
Пример #6
0
        public IHttpActionResult GetEmailDistributionListContactLanguageWithID([FromUri] int EmailDistributionListContactLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                emailDistributionListContactLanguageService.Query = emailDistributionListContactLanguageService.FillQuery(typeof(EmailDistributionListContactLanguage), lang, 0, 1, "", "", extra);

                if (emailDistributionListContactLanguageService.Query.Extra == "A")
                {
                    EmailDistributionListContactLanguageExtraA emailDistributionListContactLanguageExtraA = new EmailDistributionListContactLanguageExtraA();
                    emailDistributionListContactLanguageExtraA = emailDistributionListContactLanguageService.GetEmailDistributionListContactLanguageExtraAWithEmailDistributionListContactLanguageID(EmailDistributionListContactLanguageID);

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

                    return(Ok(emailDistributionListContactLanguageExtraA));
                }
                else if (emailDistributionListContactLanguageService.Query.Extra == "B")
                {
                    EmailDistributionListContactLanguageExtraB emailDistributionListContactLanguageExtraB = new EmailDistributionListContactLanguageExtraB();
                    emailDistributionListContactLanguageExtraB = emailDistributionListContactLanguageService.GetEmailDistributionListContactLanguageExtraBWithEmailDistributionListContactLanguageID(EmailDistributionListContactLanguageID);

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

                    return(Ok(emailDistributionListContactLanguageExtraB));
                }
                else
                {
                    EmailDistributionListContactLanguage emailDistributionListContactLanguage = new EmailDistributionListContactLanguage();
                    emailDistributionListContactLanguage = emailDistributionListContactLanguageService.GetEmailDistributionListContactLanguageWithEmailDistributionListContactLanguageID(EmailDistributionListContactLanguageID);

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

                    return(Ok(emailDistributionListContactLanguage));
                }
            }
        }
        public EmailDistributionListContactLanguageModel PostUpdateEmailDistributionListContactLanguageDB(EmailDistributionListContactLanguageModel emailDistributionListContactLanguageModel)
        {
            string retStr = EmailDistributionListContactLanguageModelOK(emailDistributionListContactLanguageModel);

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

            ContactOK contactOK = IsContactOK();

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

            EmailDistributionListContactLanguage emailDistributionListContactLanguageToUpdate = GetEmailDistributionListContactLanguageWithEmailDistributionListContactIDAndLanguageDB(emailDistributionListContactLanguageModel.EmailDistributionListContactID, emailDistributionListContactLanguageModel.Language);

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

            retStr = FillEmailDistributionListContactLanguageModel(emailDistributionListContactLanguageToUpdate, emailDistributionListContactLanguageModel, 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("EmailDistributionListContactLanguages", emailDistributionListContactLanguageToUpdate.EmailDistributionListContactLanguageID, LogCommandEnum.Change, emailDistributionListContactLanguageToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            return(GetEmailDistributionListContactLanguageModelWithEmailDistributionListContactIDAndLanguageDB(emailDistributionListContactLanguageToUpdate.EmailDistributionListContactID, (LanguageEnum)emailDistributionListContactLanguageToUpdate.Language));
        }
Пример #8
0
        /// <summary>
        /// Tries to execute the CSSPDB transaction (add/delete/update) on an [EmailDistributionListContactLanguage](CSSPModels.EmailDistributionListContactLanguage.html) item
        /// </summary>
        /// <param name="emailDistributionListContactLanguage">Is the EmailDistributionListContactLanguage item the client want to add to CSSPDB. What's important here is the EmailDistributionListContactLanguageID</param>
        /// <returns>true if EmailDistributionListContactLanguage item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        private bool TryToSave(EmailDistributionListContactLanguage emailDistributionListContactLanguage)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                emailDistributionListContactLanguage.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
Пример #9
0
        /// <summary>
        /// Updates an [EmailDistributionListContactLanguage](CSSPModels.EmailDistributionListContactLanguage.html) item in CSSPDB
        /// </summary>
        /// <param name="emailDistributionListContactLanguage">Is the EmailDistributionListContactLanguage item the client want to add to CSSPDB. What's important here is the EmailDistributionListContactLanguageID</param>
        /// <returns>true if EmailDistributionListContactLanguage item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        public bool Update(EmailDistributionListContactLanguage emailDistributionListContactLanguage)
        {
            emailDistributionListContactLanguage.ValidationResults = Validate(new ValidationContext(emailDistributionListContactLanguage), ActionDBTypeEnum.Update);
            if (emailDistributionListContactLanguage.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.EmailDistributionListContactLanguages.Update(emailDistributionListContactLanguage);

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

            return(true);
        }
Пример #10
0
        public void EmailDistributionListContactLanguage_Controller_GetEmailDistributionListContactLanguageWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactLanguageController emailDistributionListContactLanguageController = new EmailDistributionListContactLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactLanguageController.DatabaseType);

                    EmailDistributionListContactLanguage emailDistributionListContactLanguageFirst = new EmailDistributionListContactLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(new Query(), db, ContactID);
                        emailDistributionListContactLanguageFirst = (from c in db.EmailDistributionListContactLanguages select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContactLanguage info
                    IHttpActionResult jsonRet = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageWithID(emailDistributionListContactLanguageFirst.EmailDistributionListContactLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> Ret         = jsonRet as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    EmailDistributionListContactLanguage emailDistributionListContactLanguageRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactLanguageFirst.EmailDistributionListContactLanguageID, emailDistributionListContactLanguageRet.EmailDistributionListContactLanguageID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNull(emailDistributionListContactLanguageRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Пример #11
0
        public IHttpActionResult Delete([FromBody] EmailDistributionListContactLanguage emailDistributionListContactLanguage, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!emailDistributionListContactLanguageService.Delete(emailDistributionListContactLanguage))
                {
                    return(BadRequest(String.Join("|||", emailDistributionListContactLanguage.ValidationResults)));
                }
                else
                {
                    emailDistributionListContactLanguage.ValidationResults = null;
                    return(Ok(emailDistributionListContactLanguage));
                }
            }
        }
Пример #12
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 EmailDistributionListContactLanguageTest()
 {
     emailDistributionListContactLanguage       = new EmailDistributionListContactLanguage();
     emailDistributionListContactLanguageExtraA = new EmailDistributionListContactLanguageExtraA();
     emailDistributionListContactLanguageExtraB = new EmailDistributionListContactLanguageExtraB();
 }
Пример #14
0
        public void EmailDistributionListContactLanguage_Controller_GetEmailDistributionListContactLanguageList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactLanguageController emailDistributionListContactLanguageController = new EmailDistributionListContactLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactLanguageController.DatabaseType);

                    EmailDistributionListContactLanguage emailDistributionListContactLanguageFirst = new EmailDistributionListContactLanguage();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(query, db, ContactID);
                        emailDistributionListContactLanguageFirst = (from c in db.EmailDistributionListContactLanguages select c).FirstOrDefault();
                        count = (from c in db.EmailDistributionListContactLanguages select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with EmailDistributionListContactLanguage info
                    IHttpActionResult jsonRet = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageList();
                    Assert.IsNotNull(jsonRet);

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

                    List <EmailDistributionListContactLanguage> emailDistributionListContactLanguageList = new List <EmailDistributionListContactLanguage>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(query, db, ContactID);
                        emailDistributionListContactLanguageList = (from c in db.EmailDistributionListContactLanguages select c).OrderBy(c => c.EmailDistributionListContactLanguageID).Skip(0).Take(2).ToList();
                        count = (from c in db.EmailDistributionListContactLanguages select c).Count();
                    }

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

                        // ok with EmailDistributionListContactLanguage info
                        jsonRet = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <EmailDistributionListContactLanguage> >;
                        Assert.AreEqual(emailDistributionListContactLanguageList[0].EmailDistributionListContactLanguageID, ret.Content[0].EmailDistributionListContactLanguageID);
                        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 EmailDistributionListContactLanguage info
                            IHttpActionResult jsonRet2 = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <EmailDistributionListContactLanguage> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <EmailDistributionListContactLanguage> >;
                            Assert.AreEqual(emailDistributionListContactLanguageList[1].EmailDistributionListContactLanguageID, ret2.Content[0].EmailDistributionListContactLanguageID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Пример #15
0
        public void EmailDistributionListContactLanguage_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    EmailDistributionListContactLanguageController emailDistributionListContactLanguageController = new EmailDistributionListContactLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(emailDistributionListContactLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, emailDistributionListContactLanguageController.DatabaseType);

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

                        EmailDistributionListContactLanguageService emailDistributionListContactLanguageService = new EmailDistributionListContactLanguageService(query, db, ContactID);
                        emailDistributionListContactLanguageLast = (from c in db.EmailDistributionListContactLanguages select c).FirstOrDefault();
                    }

                    // ok with EmailDistributionListContactLanguage info
                    IHttpActionResult jsonRet = emailDistributionListContactLanguageController.GetEmailDistributionListContactLanguageWithID(emailDistributionListContactLanguageLast.EmailDistributionListContactLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> Ret         = jsonRet as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    EmailDistributionListContactLanguage emailDistributionListContactLanguageRet = Ret.Content;
                    Assert.AreEqual(emailDistributionListContactLanguageLast.EmailDistributionListContactLanguageID, emailDistributionListContactLanguageRet.EmailDistributionListContactLanguageID);

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

                    // Post to return CSSPError because EmailDistributionListContactLanguageID exist
                    IHttpActionResult jsonRet2 = emailDistributionListContactLanguageController.Post(emailDistributionListContactLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNull(emailDistributionListContactLanguageRet2);

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

                    // Post to return newly added EmailDistributionListContactLanguage
                    emailDistributionListContactLanguageRet.EmailDistributionListContactLanguageID = 0;
                    emailDistributionListContactLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    emailDistributionListContactLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/emailDistributionListContactLanguage");
                    IHttpActionResult jsonRet3 = emailDistributionListContactLanguageController.Post(emailDistributionListContactLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNotNull(emailDistributionListContactLanguageRet3);

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

                    IHttpActionResult jsonRet4 = emailDistributionListContactLanguageController.Delete(emailDistributionListContactLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <EmailDistributionListContactLanguage> emailDistributionListContactLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <EmailDistributionListContactLanguage>;
                    Assert.IsNotNull(emailDistributionListContactLanguageRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }