public void FinishRequest(string inName, string inLatitude, string inLongitude, string inDepth, string inComment) { Location location; double latitude, longitude, depth; // validate fields try { // location name CommonPresenterStuff.ValidateFieldNotEmpty(_view.LocationName, "name"); // latitude CommonPresenterStuff.ValidateFieldNotEmpty(_view.Latitude, "latitude"); latitude = CommonPresenterStuff.ValidateDoubleString(_view.Latitude, "latitude"); CommonPresenterStuff.ValidateDoubleInRange(latitude, -90.0, 90.0, "latitude"); // longitude CommonPresenterStuff.ValidateFieldNotEmpty(_view.Longitude, "longitude"); longitude = CommonPresenterStuff.ValidateDoubleString(_view.Longitude, "longitude"); CommonPresenterStuff.ValidateDoubleInRange(longitude, -180.0, 180.0, "longitude"); // depth CommonPresenterStuff.ValidateFieldNotEmpty(_view.Depth, "depth"); depth = CommonPresenterStuff.ValidateDoubleString(_view.Depth, "depth"); CommonPresenterStuff.ValidateDoubleGreaterThan(depth, 0.0, "depth"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // if comment is empty, warn user if (_view.Comment == "") { if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("comment"))) { return; } } // try creating location try { location = LocationFactory.CreateLocation(inName, latitude, longitude, depth, inComment); } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } Finish(location); }
public void AddFishSaleRequest() { double mass, price; // validate fields try { // fish name CommonPresenterStuff.ValidateFieldNotEmpty(_view.FishName, "fish"); // sold mass CommonPresenterStuff.ValidateFieldNotEmpty(_view.Mass, "mass"); mass = CommonPresenterStuff.ValidateDoubleString(_view.Mass, "mass"); CommonPresenterStuff.ValidateDoubleGreaterThan(mass, 0.0, "mass"); // sale price CommonPresenterStuff.ValidateFieldNotEmpty(_view.Price, "price"); price = CommonPresenterStuff.ValidateDoubleString(_view.Price, "price"); CommonPresenterStuff.ValidateDoubleGreaterThan(price, 0.0, "price"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // try adding fish sale try { Object fishSale = new object[] { _view.FishName, mass, price }; NotifyObservers(fishSale); } catch (FishSaleAlreadyAddedException) { _view.ShowErrorMessage("Fish sale has already been added"); return; } catch (FishNotCaughtException) { _view.ShowErrorMessage("Fish must first be caught!"); return; } catch (SaleMassGreaterThanCaughtMassException) { _view.ShowErrorMessage("Sale mass must be less or equal than caught mass!"); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); } _view.End(); }
public void AddFishCatchRequest() { double mass; // validate fields try { // fish name CommonPresenterStuff.ValidateFieldNotEmpty(_view.FishName, "fish"); // caught mass CommonPresenterStuff.ValidateFieldNotEmpty(_view.Mass, "mass"); mass = CommonPresenterStuff.ValidateDoubleString(_view.Mass, "mass"); CommonPresenterStuff.ValidateDoubleGreaterThan(mass, 0.0, "mass"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // try adding fish catch try { object[] fishCatch = { _view.FishName, mass }; NotifyObservers(fishCatch); } catch (FishCatchAlreadyExistsException) { _view.ShowErrorMessage("Fish has already been caught!"); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } _view.End(); }