Exemplo n.º 1
0
        public IActionResult New([FromBody] Fruit fruit)
        {
            JsonResponse <Fruit> jsonResponse;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var fruitEntity = _context.Fruits.SingleOrDefault(f => f.No == fruit.No);

            if (fruitEntity is null)
            {
                fruitEntity = new FruitEntity()
                {
                    No          = fruit.No,
                    Description = fruit.Description
                };

                _context.Fruits.Add(fruitEntity);
                _context.SaveChanges();

                fruit.Id = fruitEntity.Id;

                jsonResponse = JsonResponse <Fruit> .Success(fruit);
            }
            else
            {
                jsonResponse = JsonResponse <Fruit> .Failure("Fruit already exists");
            }

            return(Ok(jsonResponse));
        }
Exemplo n.º 2
0
 public static void AddFruit(ModelBuilder modelBuilder, FruitEntity fruit)
 {
     modelBuilder.Entity <FruitEntity>().HasData(new FruitEntity
     {
         Id        = fruit.Id,
         Name      = fruit.Name,
         VarietyId = fruit.Variety.Id
     });
 }
Exemplo n.º 3
0
 public bool Eatable(FruitEntity other)
 {
     if (other == null || fruitEntity == null)
     {
         return(false);
     }
     if (other.transform.parent.tag == transform.parent.tag)
     {
         return(false);
     }
     return(fruitEntity.Grower.Growth - other.Grower.Growth > Threshold);
 }
Exemplo n.º 4
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag != "FruitEntity")
        {
            AudioManager.Find().PlayOneShotSound(AudioManager.SoundType.BOUNCE);
            return;
        }

        FruitEntity otherFruitEntity = collision.gameObject.GetComponent <FruitEntity>();

        if (Eatable(otherFruitEntity))
        {
            otherFruitEntity.OnSquish();
        }
        else if (otherFruitEntity.Squishes.Eatable(fruitEntity))
        {
            fruitEntity.OnSquish();
        }
        else
        {
            AudioManager.Find().PlaySound(AudioManager.SoundType.HIT_FRUIT);
        }
    }
 // Start is called before the first frame update
 private void Awake()
 {
     FruitEntity = GetComponentInChildren <FruitEntity>();
 }
Exemplo n.º 6
0
 private void Awake()
 {
     fruitEntity = GetComponent <FruitEntity>();
 }