Exemplo n.º 1
0
        public IHttpActionResult GetBoxModelWithID([FromUri] int BoxModelID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                BoxModelService boxModelService = new BoxModelService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                boxModelService.Query = boxModelService.FillQuery(typeof(BoxModel), lang, 0, 1, "", "", extra);

                if (boxModelService.Query.Extra == "A")
                {
                    BoxModelExtraA boxModelExtraA = new BoxModelExtraA();
                    boxModelExtraA = boxModelService.GetBoxModelExtraAWithBoxModelID(BoxModelID);

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

                    return(Ok(boxModelExtraA));
                }
                else if (boxModelService.Query.Extra == "B")
                {
                    BoxModelExtraB boxModelExtraB = new BoxModelExtraB();
                    boxModelExtraB = boxModelService.GetBoxModelExtraBWithBoxModelID(BoxModelID);

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

                    return(Ok(boxModelExtraB));
                }
                else
                {
                    BoxModel boxModel = new BoxModel();
                    boxModel = boxModelService.GetBoxModelWithBoxModelID(BoxModelID);

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

                    return(Ok(boxModel));
                }
            }
        }
        public void GetBoxModelWithBoxModelID__boxModel_BoxModelID__Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    BoxModelService boxModelService = new BoxModelService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    BoxModel boxModel = (from c in dbTestDB.BoxModels select c).FirstOrDefault();
                    Assert.IsNotNull(boxModel);

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            BoxModel boxModelRet = boxModelService.GetBoxModelWithBoxModelID(boxModel.BoxModelID);
                            CheckBoxModelFields(new List <BoxModel>()
                            {
                                boxModelRet
                            });
                            Assert.AreEqual(boxModel.BoxModelID, boxModelRet.BoxModelID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }