public IHttpActionResult GetMWQMSampleList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                            [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
 {
     using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
     {
         MWQMSampleService mwqmSampleService = new MWQMSampleService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Beispiel #2
0
        public void MWQMSample_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSampleController mwqmSampleController = new MWQMSampleController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSampleController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSampleController.DatabaseType);

                    MWQMSample mwqmSampleLast = new MWQMSample();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMSampleService mwqmSampleService = new MWQMSampleService(query, db, ContactID);
                        mwqmSampleLast = (from c in db.MWQMSamples select c).FirstOrDefault();
                    }

                    // ok with MWQMSample info
                    IHttpActionResult jsonRet = mwqmSampleController.GetMWQMSampleWithID(mwqmSampleLast.MWQMSampleID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSample> Ret = jsonRet as OkNegotiatedContentResult <MWQMSample>;
                    MWQMSample mwqmSampleRet = Ret.Content;
                    Assert.AreEqual(mwqmSampleLast.MWQMSampleID, mwqmSampleRet.MWQMSampleID);

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

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

                    OkNegotiatedContentResult <MWQMSample> mwqmSampleRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSample>;
                    Assert.IsNotNull(mwqmSampleRet2);

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

                    // Put to return CSSPError because MWQMSampleID of 0 does not exist
                    mwqmSampleRet.MWQMSampleID = 0;
                    IHttpActionResult jsonRet3 = mwqmSampleController.Put(mwqmSampleRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMSample> mwqmSampleRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMSample>;
                    Assert.IsNull(mwqmSampleRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Beispiel #3
0
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _AppTaskService       = new AppTaskService(LanguageRequest, User);
     _MWQMSiteService      = new MWQMSiteService(LanguageRequest, User);
     _MWQMRunService       = new MWQMRunService(LanguageRequest, User);
     _MWQMSampleService    = new MWQMSampleService(LanguageRequest, User);
     _MapInfoPointService  = new MapInfoPointService(LanguageRequest, User);
     _MWQMSubsectorService = new MWQMSubsectorService(LanguageRequest, User);
     _MWQMAnalysisReportParameterService = new MWQMAnalysisReportParameterService(LanguageRequest, User);
 }
        public IHttpActionResult GetMWQMSampleWithID([FromUri] int MWQMSampleID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSampleService mwqmSampleService = new MWQMSampleService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mwqmSampleService.Query = mwqmSampleService.FillQuery(typeof(MWQMSample), lang, 0, 1, "", "", extra);

                if (mwqmSampleService.Query.Extra == "A")
                {
                    MWQMSampleExtraA mwqmSampleExtraA = new MWQMSampleExtraA();
                    mwqmSampleExtraA = mwqmSampleService.GetMWQMSampleExtraAWithMWQMSampleID(MWQMSampleID);

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

                    return(Ok(mwqmSampleExtraA));
                }
                else if (mwqmSampleService.Query.Extra == "B")
                {
                    MWQMSampleExtraB mwqmSampleExtraB = new MWQMSampleExtraB();
                    mwqmSampleExtraB = mwqmSampleService.GetMWQMSampleExtraBWithMWQMSampleID(MWQMSampleID);

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

                    return(Ok(mwqmSampleExtraB));
                }
                else
                {
                    MWQMSample mwqmSample = new MWQMSample();
                    mwqmSample = mwqmSampleService.GetMWQMSampleWithMWQMSampleID(MWQMSampleID);

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

                    return(Ok(mwqmSample));
                }
            }
        }
        public void SetupTest(ContactModel contactModelToDo, CultureInfo culture)
        {
            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

            contactModel               = contactModelToDo;
            user                       = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null);
            mwqmSampleService          = new MWQMSampleService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            mwqmSampleLanguageService  = new MWQMSampleLanguageService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            testDBService              = new TestDBService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user, TableName, Plurial);
            randomService              = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            mwqmSampleLanguageModelNew = new MWQMSampleLanguageModel();
            mwqmSampleLanguage         = new MWQMSampleLanguage();
            mwqmSampleServiceTest      = new MWQMSampleServiceTest();
            mwqmSampleServiceTest.SetupTest(contactModelToDo, culture);
        }
Beispiel #6
0
        public void MWQMSample_Controller_GetMWQMSampleWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSampleController mwqmSampleController = new MWQMSampleController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSampleController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSampleController.DatabaseType);

                    MWQMSample mwqmSampleFirst = new MWQMSample();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MWQMSampleService mwqmSampleService = new MWQMSampleService(new Query(), db, ContactID);
                        mwqmSampleFirst = (from c in db.MWQMSamples select c).FirstOrDefault();
                    }

                    // ok with MWQMSample info
                    IHttpActionResult jsonRet = mwqmSampleController.GetMWQMSampleWithID(mwqmSampleFirst.MWQMSampleID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSample> Ret = jsonRet as OkNegotiatedContentResult <MWQMSample>;
                    MWQMSample mwqmSampleRet = Ret.Content;
                    Assert.AreEqual(mwqmSampleFirst.MWQMSampleID, mwqmSampleRet.MWQMSampleID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mwqmSampleController.GetMWQMSampleWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSample> mwqmSampleRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSample>;
                    Assert.IsNull(mwqmSampleRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([FromBody] MWQMSample mwqmSample, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSampleService mwqmSampleService = new MWQMSampleService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!mwqmSampleService.Delete(mwqmSample))
                {
                    return(BadRequest(String.Join("|||", mwqmSample.ValidationResults)));
                }
                else
                {
                    mwqmSample.ValidationResults = null;
                    return(Ok(mwqmSample));
                }
            }
        }
Beispiel #8
0
        public bool CreateSamplesBC()
        {
            lblStatus.Text = "Starting ... CreateSamplesBC";
            Application.DoEvents();

            TVItemService   tvItemServiceR  = new TVItemService(LanguageEnum.en, user);
            MWQMRunService  mwqmRunService  = new MWQMRunService(LanguageEnum.en, user);
            MWQMSiteService mwqmSiteService = new MWQMSiteService(LanguageEnum.en, user);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelProv = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "British Columbia", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelProv))
            {
                return(false);
            }

            List <TVItemModel> BCSubSectorLangList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelProv.TVItemID, TVTypeEnum.Subsector);

            if (BCSubSectorLangList.Count == 0)
            {
                return(false);
            }

            List <BCStation> BCWQMSiteList         = new List <BCStation>();
            TVItemModel      BCSubSector           = new TVItemModel();
            List <TT>        tideTextInDBList      = new List <TT>();
            List <AM>        analyseMethodInDBList = new List <AM>();
            List <Mat>       matrixInDBList        = new List <Mat>();
            List <Lab>       labInDBList           = new List <Lab>();

            int StartBCCreateSamplesBC = int.Parse(textBoxBCCreateSamplesBC.Text);

            int TotalCount = BCSubSectorLangList.Count();
            int Count      = 0;

            foreach (TVItemModel tvItemModelSubsector in BCSubSectorLangList)
            {
                if (Cancel)
                {
                    return(false);
                }

                Count          += 1;
                lblStatus.Text  = (Count * 100 / TotalCount).ToString() + " ... CreateSamplesBC of " + tvItemModelSubsector.TVText;
                lblStatus2.Text = Count + " of " + TotalCount;
                Application.DoEvents();

                textBoxBCCreateSamplesBC.Text = Count.ToString();

                if (StartBCCreateSamplesBC > Count)
                {
                    continue;
                }

                List <MWQMRunModel> BCRunModelList = mwqmRunService.GetMWQMRunModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);
                if (BCRunModelList.Count == 0)
                {
                    continue;
                }

                List <TVItemModel> tvItemModelList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite);
                if (tvItemModelList.Count == 0)
                {
                    return(false);
                }

                MWQMSampleService mwqmSampleService = new MWQMSampleService(LanguageEnum.en, user);

                List <MWQMSample> mwqmSampleList = new List <MWQMSample>();
                using (CSSPDBEntities dd = new CSSPDBEntities())
                {
                    mwqmSampleList = (from c in dd.MWQMSamples
                                      from ts in dd.TVItems
                                      from tr in dd.TVItems
                                      where c.MWQMSiteTVItemID == ts.TVItemID &&
                                      c.MWQMRunTVItemID == tr.TVItemID &&
                                      ts.ParentID == tvItemModelSubsector.TVItemID &&
                                      tr.ParentID == tvItemModelSubsector.TVItemID
                                      select c).Distinct().ToList();
                }

                // doing land samples

                List <TempData.BCLandSampleStation> bcLandSampleStation = new List <TempData.BCLandSampleStation>();

                using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                {
                    string TVText = tvItemModelSubsector.TVText.Substring(0, 4);
                    bcLandSampleStation = (from c in dbDT.BCLandSampleStations
                                           where c.SS_STATION == TVText
                                           orderby c.BCLandSampleStationID
                                           select c).ToList <TempData.BCLandSampleStation>();
                }

                int countSta = 0;
                int totalSta = bcLandSampleStation.Count;
                foreach (TempData.BCLandSampleStation bcmss in bcLandSampleStation)
                {
                    if (Cancel)
                    {
                        return(false);
                    }

                    countSta       += 1;
                    lblStatus2.Text = "Doing Land Station " + bcmss.SS_STATION + " --- " + countSta + " of " + totalSta;
                    Application.DoEvents();

                    string TVText = bcmss.SS_STATION;

                    BCSubSector = (from c in BCSubSectorLangList where c.TVText.StartsWith(bcmss.SS_SHELLFI) select c).FirstOrDefault();
                    if (!CheckModelOK <TVItemModel>(BCSubSector))
                    {
                        continue;
                    }

                    TVItemService tvItemService = new TVItemService(LanguageEnum.en, user);

                    TVItemModel tvItemModelMWQMSite = tvItemModelList.Where(c => c.TVText == TVText).FirstOrDefault();
                    if (tvItemModelMWQMSite == null)
                    {
                        richTextBoxStatus.AppendText("Could not find MWQMSite [" + TVText + "]");
                        return(false);
                    }

                    List <TempData.BCLandSample> bcLandSampleList = new List <TempData.BCLandSample>();

                    using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                    {
                        bcLandSampleList = (from c in dbDT.BCLandSamples
                                            where c.SR_STATION_CODE == bcmss.SS_STATION
                                            orderby c.SR_READING_DATE
                                            select c).ToList <TempData.BCLandSample>();
                    }

                    int countSample = 0;
                    int TotalSample = bcLandSampleList.Count;
                    foreach (TempData.BCLandSample bcms in bcLandSampleList)
                    {
                        if (Cancel)
                        {
                            return(false);
                        }
                        countSample    += 1;
                        lblStatus2.Text = "Doing Marine Station " + bcms.SR_STATION_CODE + " --- " + countSta + " of " + totalSta + " Sample " + countSample + " of " + TotalSample;
                        Application.DoEvents();

                        try
                        {
                            DateTime DayOfSample = (DateTime)(bcms.SR_READING_DATE);
                            string   SampleTime  = bcms.SR_READING_TIME;

                            if (SampleTime == null)
                            {
                                SampleTime = "0000";
                            }

                            DateTime SampleDate = new DateTime(DayOfSample.Year, DayOfSample.Month, DayOfSample.Day, (SampleTime.Length == 1 ? 0 : (SampleTime.Length == 3 ? (int.Parse(SampleTime.Substring(0, 1))) : (int.Parse(SampleTime.Substring(0, 1))))), (SampleTime.Length == 1 ? 0 : (SampleTime.Length == 3 ? (int.Parse(SampleTime.Substring(1, 2))) : (SampleTime.Substring(2, 2) == "60" ? 59 : (int.Parse(SampleTime.Substring(2, 2)))))), 0);

                            int FecCol = 0;
                            if (bcms.SR_FECAL_COLIFORM_IND == "<" && bcms.SR_FECAL_COLIFORM == 2)
                            {
                                FecCol = 1;
                            }
                            else
                            {
                                if (bcms.SR_FECAL_COLIFORM == null)
                                {
                                    continue;
                                }

                                FecCol = (int)bcms.SR_FECAL_COLIFORM;
                            }

                            MWQMRunModel mwqmRunModel = (from c in BCRunModelList
                                                         where c.SubsectorTVItemID == BCSubSector.TVItemID &&
                                                         c.DateTime_Local.Year == SampleDate.Year &&
                                                         c.DateTime_Local.Month == SampleDate.Month &&
                                                         c.DateTime_Local.Day == SampleDate.Day
                                                         select c).FirstOrDefault();

                            if (mwqmRunModel == null)
                            {
                                richTextBoxStatus.AppendText("Could not find run for date [" + SampleDate.ToString("yyyy MMM dd") + "] for subsector [" + BCSubSector.TVText + "]\r\n");
                                continue;
                                //return false;
                            }

                            bool SampleExist = (from c in mwqmSampleList
                                                where c.MWQMSiteTVItemID == tvItemModelMWQMSite.TVItemID &&
                                                c.MWQMRunTVItemID == mwqmRunModel.MWQMRunTVItemID &&
                                                c.SampleDateTime_Local == SampleDate &&
                                                c.FecCol_MPN_100ml == FecCol &&
                                                c.Salinity_PPT == null &&
                                                c.WaterTemp_C == null &&
                                                c.SampleTypesText.Contains(((int)SampleTypeEnum.Routine).ToString())
                                                select c).Any();

                            if (!SampleExist)
                            {
                                MWQMSampleModel mwqmSampleModelNew = new MWQMSampleModel()
                                {
                                    MWQMSiteTVItemID     = tvItemModelMWQMSite.TVItemID,
                                    MWQMRunTVItemID      = mwqmRunModel.MWQMRunTVItemID,
                                    SampleDateTime_Local = SampleDate,
                                    Depth_m          = null,
                                    FecCol_MPN_100ml = FecCol,
                                    Salinity_PPT     = null,
                                    MWQMSampleNote   = (string.IsNullOrWhiteSpace(bcms.SR_OBS) == true ? "--" : bcms.SR_OBS.Trim()),
                                    WaterTemp_C      = null,
                                    SampleTypesText  = ((int)SampleTypeEnum.Routine).ToString() + ",",
                                    SampleTypeList   = new List <SampleTypeEnum>()
                                    {
                                        SampleTypeEnum.Routine
                                    },
                                };

                                MWQMSampleModel mwqmSampleModelRet = mwqmSampleService.GetMWQMSampleModelExistDB(mwqmSampleModelNew);
                                if (!string.IsNullOrWhiteSpace(mwqmSampleModelRet.Error))
                                {
                                    mwqmSampleModelRet = mwqmSampleService.PostAddMWQMSampleDB(mwqmSampleModelNew);
                                    if (!CheckModelOK <MWQMSampleModel>(mwqmSampleModelRet))
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }

                // doing water samples
                List <TempData.BCMarineSampleStation> bcMarineSampleStation = new List <TempData.BCMarineSampleStation>();

                using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                {
                    string TVText = tvItemModelSubsector.TVText.Substring(0, 4);
                    bcMarineSampleStation = (from c in dbDT.BCMarineSampleStations
                                             where c.SS_SHELLFI == TVText
                                             orderby c.BCMarineSampleStationID
                                             select c).ToList <TempData.BCMarineSampleStation>();
                }

                countSta = 0;
                totalSta = bcMarineSampleStation.Count;
                foreach (TempData.BCMarineSampleStation bcmss in bcMarineSampleStation)
                {
                    if (Cancel)
                    {
                        return(false);
                    }

                    countSta       += 1;
                    lblStatus2.Text = "Doing Marine Sample " + countSta + " of " + totalSta;
                    Application.DoEvents();

                    string TVText = bcmss.SS_STATION;

                    BCSubSector = (from c in BCSubSectorLangList where c.TVText.StartsWith(bcmss.SS_SHELLFI) select c).FirstOrDefault();
                    if (!CheckModelOK <TVItemModel>(BCSubSector))
                    {
                        return(false);
                    }

                    TVItemService tvItemService = new TVItemService(LanguageEnum.en, user);

                    TVItemModel tvItemModelMWQMSite = tvItemModelList.Where(c => c.TVText == TVText).FirstOrDefault();
                    if (tvItemModelMWQMSite == null)
                    {
                        richTextBoxStatus.AppendText("Could not find MWQMSite [" + TVText + "]");
                        return(false);
                    }

                    List <TempData.BCMarineSample> bcMarineSampleList = new List <TempData.BCMarineSample>();

                    using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                    {
                        bcMarineSampleList = (from c in dbDT.BCMarineSamples
                                              where c.SR_STATION_CODE == bcmss.SS_STATION
                                              orderby c.SR_READING_DATE
                                              select c).ToList <TempData.BCMarineSample>();
                    }

                    int countSample = 0;
                    int TotalSample = bcMarineSampleList.Count;
                    foreach (TempData.BCMarineSample bcms in bcMarineSampleList)
                    {
                        if (Cancel)
                        {
                            return(false);
                        }
                        countSample    += 1;
                        lblStatus2.Text = "Doing Marine station " + bcms.SR_STATION_CODE + " ----" + countSta + " of " + totalSta + " Sample " + countSample + " of " + TotalSample;
                        Application.DoEvents();

                        try
                        {
                            DateTime DayOfSample = (DateTime)(bcms.SR_READING_DATE);
                            string   SampleTime  = bcms.SR_READING_TIME;

                            if (SampleTime == null)
                            {
                                SampleTime = "0000";
                            }

                            if (SampleTime == "093")
                            {
                                SampleTime = "0930";
                            }
                            if (SampleTime == "080")
                            {
                                SampleTime = "0800";
                            }
                            if (SampleTime == "073")
                            {
                                SampleTime = "0730";
                            }
                            if (SampleTime == "060")
                            {
                                SampleTime = "0600";
                            }

                            DateTime SampleDate = new DateTime(DayOfSample.Year, DayOfSample.Month, DayOfSample.Day, (SampleTime.Length == 1 ? 0 : (SampleTime.Length == 3 ? (int.Parse(SampleTime.Substring(0, 1))) : (int.Parse(SampleTime.Substring(0, 1))))), (SampleTime.Length == 1 ? 0 : (SampleTime.Length == 3 ? (int.Parse(SampleTime.Substring(1, 2))) : (SampleTime.Substring(2, 2) == "60" ? 59 : (int.Parse(SampleTime.Substring(2, 2)))))), 0);

                            int FecCol = 0;
                            if (bcms.SR_FECAL_COLIFORM_IND == "<" && bcms.SR_FECAL_COLIFORM == 2)
                            {
                                FecCol = 1;
                            }
                            else
                            {
                                FecCol = (int)bcms.SR_FECAL_COLIFORM;
                            }

                            MWQMRunModel mwqmRunModel = (from c in BCRunModelList
                                                         where c.SubsectorTVItemID == BCSubSector.TVItemID &&
                                                         c.DateTime_Local.Year == SampleDate.Year &&
                                                         c.DateTime_Local.Month == SampleDate.Month &&
                                                         c.DateTime_Local.Day == SampleDate.Day
                                                         select c).FirstOrDefault();

                            if (mwqmRunModel == null)
                            {
                                richTextBoxStatus.AppendText("Could not find run for date [" + SampleDate.ToString("yyyy MMM dd") + "] for subsector [" + BCSubSector.TVText + "]\r\n");
                                continue;
                                //return false;
                            }

                            bool SampleExist = (from c in mwqmSampleList
                                                where c.MWQMSiteTVItemID == tvItemModelMWQMSite.TVItemID &&
                                                c.MWQMRunTVItemID == mwqmRunModel.MWQMRunTVItemID &&
                                                c.SampleDateTime_Local == SampleDate &&
                                                c.FecCol_MPN_100ml == FecCol &&
                                                c.Salinity_PPT == bcms.SR_SALINITY &&
                                                c.WaterTemp_C == bcms.SR_TEMPERATURE &&
                                                c.SampleTypesText.Contains(((int)SampleTypeEnum.Routine).ToString())
                                                select c).Any();

                            if (!SampleExist)
                            {
                                MWQMSampleModel mwqmSampleModelNew = new MWQMSampleModel()
                                {
                                    MWQMSiteTVItemID     = tvItemModelMWQMSite.TVItemID,
                                    MWQMRunTVItemID      = mwqmRunModel.MWQMRunTVItemID,
                                    SampleDateTime_Local = SampleDate,
                                    Depth_m          = bcms.SR_SAMPLE_DEPTH,
                                    FecCol_MPN_100ml = FecCol,
                                    Salinity_PPT     = bcms.SR_SALINITY,
                                    MWQMSampleNote   = (string.IsNullOrWhiteSpace(bcms.SR_OBS) == true ? "--" : bcms.SR_OBS.Trim()),
                                    WaterTemp_C      = bcms.SR_TEMPERATURE,
                                    SampleTypesText  = ((int)SampleTypeEnum.Routine).ToString() + ",",
                                    SampleTypeList   = new List <SampleTypeEnum>()
                                    {
                                        SampleTypeEnum.Routine
                                    },
                                };

                                MWQMSampleModel mwqmSampleModelRet = mwqmSampleService.GetMWQMSampleModelExistDB(mwqmSampleModelNew);
                                if (!string.IsNullOrWhiteSpace(mwqmSampleModelRet.Error))
                                {
                                    mwqmSampleModelRet = mwqmSampleService.PostAddMWQMSampleDB(mwqmSampleModelNew);
                                    if (!CheckModelOK <MWQMSampleModel>(mwqmSampleModelRet))
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }

            return(true);
        }
        private void GenerateSubsectorFaecalColiformDensitiesDocument(Document document)
        {
            Body      body      = new Body();
            Paragraph paragraph = new Paragraph();
            Run       run       = new Run();
            Table     table     = new Table();
            TableRow  tableRow  = new TableRow();
            TableCell tableCell = new TableCell();
            //string URL = "";

            BaseEnumService      baseEnumService      = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService        tvItemService        = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TVItemStatService    tvItemStatService    = new TVItemStatService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MWQMSampleService    mwqmSampleService    = new MWQMSampleService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MWQMSiteService      mwqmSiteService      = new MWQMSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TideSiteService      tideSiteService      = new TideSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TideDataValueService tideDataValueService = new TideDataValueService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            TVItemModel tvItemModelSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
            {
                paragraph = DocxBase.AddParagraph(body);
                DocxBase.AddRunWithCurrentParagraphStyle(paragraph, tvItemModelSubsector.Error);
            }

            //tvItemStatService.SetTVItemStatForTVItemIDAndParentsTVItemID(tvItemModelSubsector.TVItemID);

            TVItemModel tvItemModelTideSite = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.TideSite).FirstOrDefault();

            if (tvItemModelTideSite == null)
            {
                if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
                {
                    paragraph = DocxBase.AddParagraph(body);
                    DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.CoundNotFindTideSite);
                    return;
                }
            }

            List <TVItemModel> tvItemModelMWQMList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite);

            List <StationDateValue> stationDateValueList = new List <StationDateValue>();
            List <DateTime>         DateWithDataList     = new List <DateTime>();
            List <string>           StationList          = new List <string>();

            foreach (TVItemModel tvItemModelMWQM in tvItemModelMWQMList)
            {
                string Station = mwqmSiteService.GetMWQMSiteModelWithMWQMSiteTVItemIDDB(tvItemModelMWQM.TVItemID).MWQMSiteNumber;

                StationList.Add(Station);

                List <MWQMSampleModel> mwqmSampleModelList = mwqmSampleService.GetMWQMSampleModelListWithMWQMSiteTVItemIDDB(tvItemModelMWQM.TVItemID);

                foreach (MWQMSampleModel mwqmSampleModel in mwqmSampleModelList.OrderByDescending(c => c.SampleDateTime_Local))
                {
                    StationDateValue stationDateValue = new StationDateValue()
                    {
                        Station = Station,
                        Date    = new DateTime(mwqmSampleModel.SampleDateTime_Local.Year, mwqmSampleModel.SampleDateTime_Local.Month, mwqmSampleModel.SampleDateTime_Local.Day),
                        Value   = mwqmSampleModel.FecCol_MPN_100ml,
                    };

                    if (!DateWithDataList.Contains(stationDateValue.Date))
                    {
                        DateWithDataList.Add(stationDateValue.Date);
                    }

                    stationDateValueList.Add(stationDateValue);
                }
            }

            DateWithDataList = DateWithDataList.OrderBy(c => c).ToList();
            StationList      = StationList.OrderBy(c => c).ToList();

            for (int i = 0, count = DateWithDataList.Count; i < count; i = i + 15)
            {
                DocxBase.CurrentFontName           = FontNameEnum.Arial;
                DocxBase.CurrentFontSize           = 16;
                DocxBase.CurrentParagraphStyle     = ParagraphStyleEnum.Caption;
                DocxBase.CurrentJustificationValue = JustificationValues.Left;
                paragraph = DocxBase.AddParagraph(body);
                paragraph = DocxBase.AddParagraph(body);

                string TableTitle = DocxServiceSubsectorFCDensitiesRes.Table + "1B-" + ((int)(i / 15) + 1).ToString() + "." + DocxServiceSubsectorFCDensitiesRes.FaecalColiformDensitiesMPNPer100 +
                                    " " + DocxServiceSubsectorFCDensitiesRes.For + " " + tvItemModelSubsector.TVText;
                run = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, TableTitle);

                DocxBase.CurrentTableStyle = TableStyleEnum.PlainTable1;
                DocxBase.CurrentFontName   = FontNameEnum.Arial;
                DocxBase.CurrentFontSize   = 10;
                table    = DocxBase.AddTableStyle(body);
                tableRow = DocxBase.AddTableRow(table);

                List <DateTime> dateTimeNext15 = (from c in DateWithDataList
                                                  where c >= DateWithDataList[i]
                                                  select c).Take(15).ToList <DateTime>();

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, " ");
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Station);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, dateTime.ToString("yyyy"));
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, dateTime.ToString("dd MMM"));
                }

                List <StationDateValue> StationDateValueDataList = (from c in stationDateValueList
                                                                    orderby c.Station
                                                                    select c).ToList <StationDateValue>();

                foreach (string station in StationList)
                {
                    tableRow = DocxBase.AddTableRow(table);

                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, station);

                    foreach (DateTime dateTime in dateTimeNext15)
                    {
                        StationDateValue stationDateValueForDate = (from c in stationDateValueList
                                                                    where c.Station == station &&
                                                                    c.Date.Year == dateTime.Year &&
                                                                    c.Date.Month == dateTime.Month &&
                                                                    c.Date.Day == dateTime.Day
                                                                    select c).FirstOrDefault();

                        tableCell = DocxBase.AddTableCell(tableRow);
                        paragraph = DocxBase.AddTableCellParagraph(tableCell);
                        run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, (stationDateValueForDate == null ? " " : (stationDateValueForDate.Value < 2 ? "<2" : stationDateValueForDate.Value.ToString("F0"))));
                    }
                }

                // Tide Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Tide);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    TideDataValueModel tideDataValueModel = tideDataValueService.GetTideDataValueModelWithTideSiteTVItemIDAndDateDB(tvItemModelTideSite.TVItemID, dateTime);

                    string TideStartAccronym = GetTideTextAccronym(tideDataValueModel.TideStart);
                    string TideEndAccronym   = GetTideTextAccronym(tideDataValueModel.TideEnd);

                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, TideStartAccronym + "-" + TideEndAccronym);
                }

                // Rain (mm) Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Rain_mm);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "");
                }

                // 0-24 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_24h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }

                // 0-48 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_48h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }

                // 0-72 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_72h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }
            }


            DocxBase.CurrentParagraphStyle = ParagraphStyleEnum.Quote;
            paragraph = DocxBase.AddParagraph(body);
            string NoteTxt = DocxServiceSubsectorFCDensitiesRes.Note + " : ";

            for (int i = 1, count = Enum.GetNames(typeof(TideTextEnum)).Length; i < count; i++)
            {
                NoteTxt = GetTideTextAccronym((TideTextEnum)i) + " = " + baseEnumService.GetEnumText_TideTextEnum((TideTextEnum)i) + " | ";
            }

            DocxBase.AddRunWithCurrentParagraphStyle(paragraph, NoteTxt);

            DocxBase.AddSectionProp(body);

            document.Append(body);
        }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _OpenDataService   = new OpenDataService(LanguageRequest, User);
     _MWQMSampleService = new MWQMSampleService(LanguageRequest, User);
 }
Beispiel #11
0
        public PartialViewResult _LabSheetsTranferred(int SamplingPlanID)
        {
            ViewBag.SamplingPlanController      = _SamplingPlanController;
            ViewBag.AdminContactModelList       = null;
            ViewBag.IsSamplingPlanner           = false;
            ViewBag.LabSheetModelAndA1SheetList = null;
            ViewBag.LastAnalyzeMethod           = AnalyzeMethodEnum.Error;
            ViewBag.LastSampleMatrix            = SampleMatrixEnum.Error;
            ViewBag.LastLaboratory                  = LaboratoryEnum.Error;
            ViewBag.MWQMSampleModelList             = new List <MWQMSampleModel>();
            ViewBag.SubsectorMWQMSiteModelList      = new List <SubsectorMWQMSiteModel>();
            ViewBag.SamplingPlanModel               = null;
            ViewBag.LabSheetSiteMonitoredCountsList = null;

            List <LabSheetModelAndA1Sheet> labSheetModelAndA1SheetList = new List <LabSheetModelAndA1Sheet>();

            SamplingPlanService SamplingPlanService = new SamplingPlanService(_TVItemService.LanguageRequest, _TVItemService.User);
            LabSheetService     labSheetService     = new LabSheetService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMRunService      mwqmRunService      = new MWQMRunService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMSampleService   mwqmSampleService   = new MWQMSampleService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMSiteService     mwqmSiteService     = new MWQMSiteService(_TVItemService.LanguageRequest, _TVItemService.User);

            ContactModel contactModel = _ContactService.GetContactLoggedInDB();

            SamplingPlanModel SamplingPlanModel = SamplingPlanService.GetSamplingPlanModelWithSamplingPlanIDDB(SamplingPlanID);

            if (string.IsNullOrWhiteSpace(SamplingPlanModel.Error))
            {
                ViewBag.SamplingPlanModel = SamplingPlanModel;

                ViewBag.IsSamplingPlanner = false;
                if (contactModel.SamplingPlanner_ProvincesTVItemID.Contains(SamplingPlanModel.ProvinceTVItemID.ToString()))
                {
                    ViewBag.IsSamplingPlanner = true;
                }
                else
                {
                    List <ContactModel> adminContactModelList = _ContactService.GetAdminContactModelListDB();
                    ViewBag.AdminContactModelList = adminContactModelList;
                }

                List <LabSheetModel> labSheetModelList = labSheetService.GetLabSheetModelListWithSamplingPlanIDAndLabSheetStatusDB(SamplingPlanID, LabSheetStatusEnum.Transferred);
                foreach (LabSheetModel labSheetModel in labSheetModelList)
                {
                    LabSheetModelAndA1Sheet labSheetModelAndA1Sheet = new LabSheetModelAndA1Sheet();
                    labSheetModelAndA1Sheet.LabSheetModel   = labSheetModel;
                    labSheetModelAndA1Sheet.LabSheetA1Sheet = labSheetService.ParseLabSheetA1WithLabSheetID(labSheetModel.LabSheetID);
                    labSheetModelAndA1SheetList.Add(labSheetModelAndA1Sheet);
                }
                ViewBag.LabSheetModelAndA1SheetList = labSheetModelAndA1SheetList;

                if (labSheetModelAndA1SheetList.Count > 0)
                {
                    MWQMRunModel mwqmRunModelLast = mwqmRunService.GetMWQMRunModelLastWithSubsectorTVItemIDDB(labSheetModelAndA1SheetList[0].LabSheetModel.SubsectorTVItemID);
                    if (string.IsNullOrWhiteSpace(mwqmRunModelLast.Error))
                    {
                        if (mwqmRunModelLast.AnalyzeMethod != null)
                        {
                            ViewBag.LastAnalyzeMethod = (AnalyzeMethodEnum)mwqmRunModelLast.AnalyzeMethod;
                        }
                        if (mwqmRunModelLast.SampleMatrix != null)
                        {
                            ViewBag.LastSampleMatrix = (SampleMatrixEnum)mwqmRunModelLast.SampleMatrix;
                        }
                        if (mwqmRunModelLast.Laboratory != null)
                        {
                            ViewBag.LastLaboratory = (LaboratoryEnum)mwqmRunModelLast.Laboratory;
                        }
                    }
                }

                List <MWQMSampleModel> mwqmSampleModelList = new List <MWQMSampleModel>();
                foreach (LabSheetModelAndA1Sheet labSheetModelAndA1Sheet in labSheetModelAndA1SheetList)
                {
                    int Year  = 0;
                    int Month = 0;
                    int Day   = 0;
                    if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunYear, out Year))
                    {
                        if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunMonth, out Month))
                        {
                            if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunDay, out Day))
                            {
                                MWQMRunModel mwqmRunModelNew = new MWQMRunModel()
                                {
                                    SubsectorTVItemID = labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorTVItemID,
                                    DateTime_Local    = new DateTime(Year, Month, Day),
                                    RunSampleType     = labSheetModelAndA1Sheet.LabSheetA1Sheet.SampleType,
                                    RunNumber         = labSheetModelList[0].RunNumber,
                                };

                                MWQMRunModel mwqmRunModel = mwqmRunService.GetMWQMRunModelExistDB(mwqmRunModelNew);
                                if (string.IsNullOrWhiteSpace(mwqmRunModel.Error))
                                {
                                    List <MWQMSampleModel> mwqmSampleModelList2 = mwqmSampleService.GetMWQMSampleModelListWithMWQMRunTVItemIDDB(mwqmRunModel.MWQMRunTVItemID);
                                    foreach (MWQMSampleModel mwqmSampleModel in mwqmSampleModelList2)
                                    {
                                        mwqmSampleModelList.Add(mwqmSampleModel);
                                    }
                                }
                            }
                        }
                    }
                }
                ViewBag.MWQMSampleModelList = mwqmSampleModelList;


                if (labSheetModelAndA1SheetList.Count > 0)
                {
                    List <SubsectorMWQMSiteModel> subsectorMWQMSiteModelList = new List <SubsectorMWQMSiteModel>();

                    foreach (LabSheetModelAndA1Sheet labSheetModelAndA1Sheet in labSheetModelAndA1SheetList)
                    {
                        List <MWQMSiteModel> mwqmSiteModelList = mwqmSiteService.GetMWQMSiteModelListWithSubsectorTVItemIDDB(labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorTVItemID);
                        subsectorMWQMSiteModelList.Add(new SubsectorMWQMSiteModel()
                        {
                            Subsector = labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorName, MWQMSiteModelList = mwqmSiteModelList
                        });
                    }

                    ViewBag.SubsectorMWQMSiteModelList = subsectorMWQMSiteModelList;
                }

                List <LabSheetSiteMonitoredCounts> labSheetSiteMonitoredCountsList = labSheetService.GetLabSheetIDListAndCountSamplesWithSamplingPlanIDDB(SamplingPlanID);
                ViewBag.LabSheetSiteMonitoredCountsList = labSheetSiteMonitoredCountsList;
            }

            return(PartialView());
        }
Beispiel #12
0
        public void MWQMSample_Controller_GetMWQMSampleList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSampleController mwqmSampleController = new MWQMSampleController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSampleController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSampleController.DatabaseType);

                    MWQMSample mwqmSampleFirst = new MWQMSample();
                    int        count           = -1;
                    Query      query           = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSampleService mwqmSampleService = new MWQMSampleService(query, db, ContactID);
                        mwqmSampleFirst = (from c in db.MWQMSamples select c).FirstOrDefault();
                        count           = (from c in db.MWQMSamples select c).Count();
                        count           = (query.Take > count ? count : query.Take);
                    }

                    // ok with MWQMSample info
                    IHttpActionResult jsonRet = mwqmSampleController.GetMWQMSampleList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MWQMSample> mwqmSampleList = new List <MWQMSample>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSampleService mwqmSampleService = new MWQMSampleService(query, db, ContactID);
                        mwqmSampleList = (from c in db.MWQMSamples select c).OrderBy(c => c.MWQMSampleID).Skip(0).Take(2).ToList();
                        count          = (from c in db.MWQMSamples select c).Count();
                    }

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

                        // ok with MWQMSample info
                        jsonRet = mwqmSampleController.GetMWQMSampleList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MWQMSample> >;
                        Assert.AreEqual(mwqmSampleList[0].MWQMSampleID, ret.Content[0].MWQMSampleID);
                        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 MWQMSample info
                            IHttpActionResult jsonRet2 = mwqmSampleController.GetMWQMSampleList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MWQMSample> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMSample> >;
                            Assert.AreEqual(mwqmSampleList[1].MWQMSampleID, ret2.Content[0].MWQMSampleID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public void MWQMSample_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSampleController mwqmSampleController = new MWQMSampleController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSampleController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSampleController.DatabaseType);

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

                        MWQMSampleService mwqmSampleService = new MWQMSampleService(query, db, ContactID);
                        mwqmSampleLast = (from c in db.MWQMSamples select c).FirstOrDefault();
                    }

                    // ok with MWQMSample info
                    IHttpActionResult jsonRet = mwqmSampleController.GetMWQMSampleWithID(mwqmSampleLast.MWQMSampleID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSample> Ret = jsonRet as OkNegotiatedContentResult <MWQMSample>;
                    MWQMSample mwqmSampleRet = Ret.Content;
                    Assert.AreEqual(mwqmSampleLast.MWQMSampleID, mwqmSampleRet.MWQMSampleID);

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

                    // Post to return CSSPError because MWQMSampleID exist
                    IHttpActionResult jsonRet2 = mwqmSampleController.Post(mwqmSampleRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSample> mwqmSampleRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSample>;
                    Assert.IsNull(mwqmSampleRet2);

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

                    // Post to return newly added MWQMSample
                    mwqmSampleRet.MWQMSampleID              = 0;
                    mwqmSampleController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmSampleController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmSample");
                    IHttpActionResult jsonRet3 = mwqmSampleController.Post(mwqmSampleRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMSample> mwqmSampleRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMSample>;
                    Assert.IsNotNull(mwqmSampleRet3);

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

                    IHttpActionResult jsonRet4 = mwqmSampleController.Delete(mwqmSampleRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMSample> mwqmSampleRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMSample>;
                    Assert.IsNotNull(mwqmSampleRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        public IHttpActionResult GetMWQMSampleList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                   [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSampleService mwqmSampleService = new MWQMSampleService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

                if (extra == "A") // QueryString contains [extra=A]
                {
                    mwqmSampleService.Query = mwqmSampleService.FillQuery(typeof(MWQMSampleExtraA), lang, skip, take, asc, desc, where, extra);

                    if (mwqmSampleService.Query.HasErrors)
                    {
                        return(Ok(new List <MWQMSampleExtraA>()
                        {
                            new MWQMSampleExtraA()
                            {
                                HasErrors = mwqmSampleService.Query.HasErrors,
                                ValidationResults = mwqmSampleService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mwqmSampleService.GetMWQMSampleExtraAList().ToList()));
                    }
                }
                else if (extra == "B") // QueryString contains [extra=B]
                {
                    mwqmSampleService.Query = mwqmSampleService.FillQuery(typeof(MWQMSampleExtraB), lang, skip, take, asc, desc, where, extra);

                    if (mwqmSampleService.Query.HasErrors)
                    {
                        return(Ok(new List <MWQMSampleExtraB>()
                        {
                            new MWQMSampleExtraB()
                            {
                                HasErrors = mwqmSampleService.Query.HasErrors,
                                ValidationResults = mwqmSampleService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mwqmSampleService.GetMWQMSampleExtraBList().ToList()));
                    }
                }
                else // QueryString has no parameter [extra] or extra is empty
                {
                    mwqmSampleService.Query = mwqmSampleService.FillQuery(typeof(MWQMSample), lang, skip, take, asc, desc, where, extra);

                    if (mwqmSampleService.Query.HasErrors)
                    {
                        return(Ok(new List <MWQMSample>()
                        {
                            new MWQMSample()
                            {
                                HasErrors = mwqmSampleService.Query.HasErrors,
                                ValidationResults = mwqmSampleService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mwqmSampleService.GetMWQMSampleList().ToList()));
                    }
                }
            }
        }