示例#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);
        }
示例#3
0
 public bool AddPetClass(PetClass entity)
 {
     try
     {
         _petDb.PetClass.Add(entity);
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
示例#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;
 }
示例#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;
            }
        }
示例#6
0
 public bool UpdatePetClass(PetClass entity)
 {
     try
     {
         _petDb.Entry(entity).State = EntityState.Modified;
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
示例#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);
 }
示例#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);
 }
示例#9
0
 public bool HasEnoughCapacity(PetClass target, int inComming)
 {
     return (target.Pets.Count + inComming) <= target.Capacity;
 }
示例#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;
            }
        }