Create Prize and create Team ready

This commit is contained in:
2020-05-17 16:41:53 +02:00
parent effdbe02b4
commit c13e2f3ccb
9 changed files with 406 additions and 2 deletions

View File

@ -0,0 +1,104 @@
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackerLibrary;
using TrackerLibrary.Models;
namespace TrackerWPFUI.ViewModels
{
public class CreatePrizeViewModel : Screen
{
private int _placeNumber;
private string _placeName;
private decimal _prizeAmount;
private double _prizePercentage;
public int PlaceNumber
{
get { return _placeNumber; }
set {
_placeNumber = value;
NotifyOfPropertyChange(() => PlaceNumber);
}
}
public string PlaceName
{
get { return _placeName; }
set { _placeName = value;
NotifyOfPropertyChange(() => PlaceName);
}
}
public decimal PrizeAmount
{
get { return _prizeAmount; }
set { _prizeAmount = value;
NotifyOfPropertyChange(() => PrizeAmount);
}
}
public double PrizePercentage
{
get { return _prizePercentage; }
set { _prizePercentage = value;
NotifyOfPropertyChange(() => PrizePercentage);
}
}
public bool CanCreatePrize(int placeNumber, string placeName, decimal prizeAmount, double prizePercentage)
{
return ValidateForm(placeNumber, placeName, prizeAmount, prizePercentage);
}
public void CreatePrize(int placeNumber, string placeName, decimal prizeAmount, double prizePercentage)
{
PrizeModel model = new PrizeModel
{
PlaceNumber = placeNumber,
PlaceName = placeName,
PrizeAmount = prizeAmount,
PrizePercentage = prizePercentage
};
GlobalConfig.Connection.CreatePrize(model);
//TODO Close out the form and alert the calling form
}
private bool ValidateForm(int placeNumber, string placeName, decimal prizeAmount, double prizePercentage)
{
bool output = true;
if (placeNumber < 1)
{
output = false;
}
if (placeName.Length == 0)
{
output = false;
}
if (prizeAmount <= 0 && prizePercentage <= 0)
{
output = false;
}
if (prizePercentage < 0 || prizePercentage > 100)
{
output = false;
}
return output;
}
}
}