public ActionResult Create([FromBody] PriceViewModel model) { var geocoder = new Geocoder(); var latlong = geocoder.GetLatLong(model.location); if (!new CityService().IsInBsAs(new PointF((float)latlong.Item1, (float)latlong.Item2))) { return(StatusCode(400, "La direccion debe ser dentro de CABA")); } var product = api.GetProductByName(model.selectedProduct); if (product.Name == null) { return(StatusCode(400, "El producto no existe")); } var price = new Price() { price = model.price, Id = Guid.Empty, latitude = latlong.Item1, longitude = latlong.Item2, product = product }; if (api.SavePrice(price)) { return(StatusCode(204)); } return(StatusCode(500)); }
public ActionResult Create(PriceViewModel model) { var geocoder = new Geocoder(); if (!api.ProductIsValid(model.selectedProduct)) { ModelState.AddModelError("selectedProduct", "El producto no es valido"); return(View("Create", model)); } var latlong = geocoder.GetLatLong(model.location); if (latlong == null) { ModelState.AddModelError("location", "La direccion no es valida"); return(View("Create", model)); } if (!new CityService().IsInBsAs(new PointF((float)latlong.Item1, (float)latlong.Item2))) { model.location = String.Empty; ModelState.AddModelError("location", "La direccion es invalida"); return(View("Create", model)); } var product = api.GetProductByName(model.selectedProduct); if (product.Name == null) { model.selectedProduct = String.Empty; ModelState.AddModelError("selectedProduct", "El producto no existe"); return(View("Create", model)); } var price = new Price() { price = model.price, Id = Guid.Empty, latitude = latlong.Item1, longitude = latlong.Item2, product = product, date = DateTimeOffset.Now }; if (api.SavePrice(price)) { return(RedirectToAction("Index", "")); } return(View("Error")); }