Beispiel #1
0
        public object Post(City added)
        {
            object json;

            try
            {
                City posted = repository.Add(added);

                json = new
                {
                    total   = 1,
                    data    = posted,
                    success = true
                };
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
Beispiel #2
0
 public IActionResult Create([Bind("Name, Description")] CityViewModel model)
 {
     if (ModelState.IsValid)
     {
         var city = new City(model.Name, model.Description);
         repository.Add(city);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }
        public Cities AddCity(Cities city)
        {
            var existingCity = _citiesRepository.GetFirstWhere(x => x.City.ToLower() == city.City.ToLower().Trim());

            if (existingCity != null)
            {
                throw new FlowException("Градот постои!");
            }

            ValidateCity(city);

            _citiesRepository.Add(city);
            _citiesRepository.SaveEntities();

            return(city);
        }
        public async Task <ActionResult> CreateCity(string cityName)
        {
            if (!string.IsNullOrEmpty(cityName))
            {
                rep.Add(new City()
                {
                    Name = cityName
                });
                await Task.Run(() => rep.Save());

                return(Created("restaurants", cityName));
            }
            else
            {
                return(BadRequest());
            }
        }