Exemplo n.º 1
0
        public void AddWeatherInfo_InvalidEntry_ThrowError(int id, string day, string weather, string outfit, int temperature, string lastmaintainerId)
        {
            WeatherInfo _weatherInfo = new WeatherInfo();

            _weatherInfo.Id               = id;
            _weatherInfo.Day              = day;
            _weatherInfo.Weather          = weather;
            _weatherInfo.Outfit           = outfit;
            _weatherInfo.Temperature      = temperature;
            _weatherInfo.LastMaintainerId = lastmaintainerId;

            maintainer.AddWeatherInfo(_weatherInfo);

            Assert.That(() => maintainer.AddWeatherInfo(_weatherInfo), Throws.Exception);
        }
Exemplo n.º 2
0
        public ActionResult AddWeatherInfo(WeatherInfo weatherInfo, string day)
        {
            try{
                if (ModelState.IsValid)
                {
                    var _weatherInfo = maintainer.SearchByDay((string)day);
                    if (_weatherInfo != null)
                    {
                        throw new Exception("The day already exist, please choose another day!");
                    }
                    else
                    {
                        weatherInfo.LastMaintainerId = User.Identity.Name;
                        maintainer.AddWeatherInfo(weatherInfo);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View("Error", new HandleErrorInfo(e, "Maintainer", "AddWeatherInfo")));
            }
        }