Exemple #1
0
 public bool BookThisClassForMyPet( PetClass target,Pet pet, Customer owner)
 {
     pet.HasClass = true;
        target.Pets.Add(pet);
        target.BookedCustomers.Add(owner);
        return UpdatePetClass(target);
 }
        public ActionResult Create(PetClass petClass)
        {
            if (ModelState.IsValid)
            {
                _petClassLogic.AddPetClass(petClass);
                return RedirectToAction("Index");
            }

            return View(petClass);
        }
Exemple #3
0
 public bool AddPetClass(PetClass entity)
 {
     try
     {
         _petDb.PetClass.Add(entity);
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemple #4
0
 /// <summary>
 /// Subscribe all pets of gienCustomer to a given class,before calling this method, make sure to include the pets to Customer.
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="owner"></param>
 /// <returns>true on success, false if thers no space for all incoming pets</returns>
 public bool BookAllMyPetsToThisClass(PetClass target, Customer owner)
 {
     if(HasEnoughCapacity(target, owner.Pets.Count))
     {
       foreach (Pet p in owner.Pets)
         {
             target.Pets.Add(p);
         }
         target.BookedCustomers.Add(owner);
         return UpdatePetClass(target);
     }
     return false;
 }
Exemple #5
0
        public int CreatePet(PetClass entity)
        {
            try
            {
                if (entity == null)
                    return 0;

                _petDb.PetClass.Add(entity);
                return _petDb.SaveChanges() == 1 ? entity.PetClassId : 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
Exemple #6
0
 public bool UpdatePetClass(PetClass entity)
 {
     try
     {
         _petDb.Entry(entity).State = EntityState.Modified;
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemple #7
0
 public bool RemoveMyPetFromThisClass(PetClass target, int petId, int ownerId)
 {
     target.Pets.Remove(new Pet() { PetId = petId });
         target.BookedCustomers.Remove(new Customer() { CustomerId = ownerId });
         return UpdatePetClass(target);
 }
Exemple #8
0
 public bool RemoveAllMyPetsFromThisClass(PetClass target, int ownerId)
 {
     for (int i = 0; i < target.Pets.Count; i++)
     {
         int currentPetId = target.Pets.ElementAt(i).PetId;
         if (target.Pets.ElementAt(i).CustomerId.Equals(ownerId))
             target.Pets.Remove(new Pet() { PetId = currentPetId });
     }
     target.BookedCustomers.Remove(new Customer() { CustomerId = ownerId });
     return UpdatePetClass(target);
 }
Exemple #9
0
 public bool HasEnoughCapacity(PetClass target, int inComming)
 {
     return (target.Pets.Count + inComming) <= target.Capacity;
 }
Exemple #10
0
        public bool DeletePetClass(int id = 0)
        {
            //EF5 only
            var petClass = new PetClass { PetClassId = id };
            try
            {
                //var obj = _petDb.Pets.SingleOrDefault(p => p.PetId == id);
                //_petDb.Pets.Remove(obj);
                //_petDb.SaveChanges();

                //EF 5 only
                _petDb.PetClass.Attach(petClass);
                _petDb.Entry(petClass).State = EntityState.Deleted;
                _petDb.SaveChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }