Exemplo n.º 1
0
        public void TestUpdateMeteorology()
        {
            BoraNowSeeder.Seed();
            var mbo     = new MeteorologyBusinessObject();
            var resList = mbo.List();
            var item    = resList.Result.FirstOrDefault();

            var meteo = new Meteorology(10, 11, 50, 2, 7, DateTime.Now.AddDays(200));

            item.MaxTemperature = meteo.MaxTemperature;
            item.MinTemperature = meteo.MinTemperature;
            item.RainPercentage = meteo.RainPercentage;
            item.UvIndex        = meteo.UvIndex;
            item.WindIndex      = meteo.WindIndex;
            item.Date           = meteo.Date;

            var resUpdate = mbo.Update(item);

            resList = mbo.List();

            Assert.IsTrue(resUpdate.Success && resList.Success &&
                          resList.Result.First().MaxTemperature == meteo.MaxTemperature && resList.Result.First().MinTemperature == meteo.MinTemperature &&
                          resList.Result.First().RainPercentage == meteo.RainPercentage && resList.Result.First().UvIndex == meteo.UvIndex &&
                          resList.Result.First().WindIndex == meteo.WindIndex && resList.Result.First().Date == meteo.Date);
        }
Exemplo n.º 2
0
        public ActionResult Update([FromBody] MeteorologyViewModel mvm)
        {
            var currentResult = _bo.Read(mvm.Id);

            if (!currentResult.Success)
            {
                return(new ObjectResult(HttpStatusCode.InternalServerError));
            }
            var current = currentResult.Result;

            if (current == null)
            {
                return(NotFound());
            }
            if (current.MaxTemperature == mvm.MaxTemperature && current.MinTemperature == mvm.MinTemperature &&
                current.RainPercentage == mvm.RainPercentage && current.UvIndex == mvm.UvIndex &&
                current.WindIndex == mvm.WindIndex && current.Date == mvm.Date)
            {
                return(new ObjectResult(HttpStatusCode.NotModified));
            }

            if (current.MaxTemperature != mvm.MaxTemperature)
            {
                current.MaxTemperature = mvm.MaxTemperature;
            }
            if (current.MinTemperature != mvm.MinTemperature)
            {
                current.MinTemperature = mvm.MinTemperature;
            }
            if (current.RainPercentage != mvm.RainPercentage)
            {
                current.RainPercentage = mvm.RainPercentage;
            }
            if (current.UvIndex != mvm.UvIndex)
            {
                current.UvIndex = mvm.UvIndex;
            }
            if (current.WindIndex != mvm.WindIndex)
            {
                current.WindIndex = mvm.WindIndex;
            }
            if (current.Date != mvm.Date)
            {
                current.Date = mvm.Date;
            }

            var updateResult = _bo.Update(current);

            if (!updateResult.Success)
            {
                return(new ObjectResult(HttpStatusCode.InternalServerError));
            }
            return(Ok());
        }