Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public bool AddPet(Pet entity)
 {
     try
     {
         _petDb.Pets.Add(entity);
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemplo n.º 3
0
        public int CreatePet(Pet entity)
        {
            try
            {
                if (entity == null)
                    return 0;

                _petDb.Pets.Add(entity);
                return _petDb.SaveChanges()==1 ? entity.PetId : 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }
Exemplo n.º 4
0
        public int AddData(string customerId, string category, string price,  string description)
        {
            customerId = RetriveIDFromThis(customerId);
            _logic = new PetLogic();
            PetLogic _pLogic = new PetLogic(_logic._petDb);
            try
            {
                Customer owner = _logic.GetCustomerById(Convert.ToInt32(customerId));

               Pet  newpet = new Pet()
                {
                    Customer = owner,
                    CustomerId = owner.CustomerId,
                    PetCategory = category,
                    Description = description,
                    Price =Convert.ToDecimal(price)

                };

               var addedPetId = _pLogic.CreatePet(newpet);
               if (addedPetId > 0)
                {
                    return addedPetId;
                }
                else
                {
                    Response.Write("Some error happened in our dataBase, Refresh the page and try again");
                    Response.StatusCode = 500;
                    Response.End();
                    return -1;
                }
            }
            catch (FormatException)
            {

                Response.Write("Please check your inputs.");
                Response.StatusCode = 404;
                Response.End();
                return -1;
            }
        }
Exemplo n.º 5
0
        public bool DeletePet(int id=0)
        {
            //EF5 only
            var pet = new Pet {PetId = id};
            try
            {
                //var obj = _petDb.Pets.SingleOrDefault(p => p.PetId == id);
                //_petDb.Pets.Remove(obj);
                //_petDb.SaveChanges();

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

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemplo n.º 6
0
 public ActionResult Edit(Pet pet)
 {
     if (ModelState.IsValid)
     {
         _logic = new PetLogic();
         _logic.UpdatePet(pet);
         //db.Entry(pet).State = EntityState.Modified;
         //db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Username", pet.CustomerId);
     return View(pet);
 }
Exemplo n.º 7
0
 public bool UpdatePet(Pet entity)
 {
     try
     {
         _petDb.Entry(entity).State = EntityState.Modified;
         _petDb.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemplo n.º 8
0
        // GET:/PetLostFound/ClaimProcess/
        // Claim back one's pet
        public ActionResult ClaimProcess(int serviceId = 0)
        {
            int petId = 0;
            var cUser = (Customer)Session["currentUser"];
            Transaction trans = new Transaction();

            trans.CustomerId = cUser.CustomerId;
            trans.ServiceId = serviceId;
            trans.Date = System.DateTime.Now;
            trans.Status = "Pet claim initiated";

            if (ModelState.IsValid)
            {
                db.Transactions.Add(trans);
                db.SaveChanges();
            }

            var getPetId = (from service in db.Services
                            where service.ServiceId.Equals(serviceId)
                            select new { service.PetId });

            foreach (var c in getPetId)
            {
                petId = (int)c.PetId;
            }

            Pet thePet = new Pet();
            thePet = db.Pets.Find(petId);
            thePet.TransactionId = trans.TransactionId;

            if (ModelState.IsValid)
            {
                db.Entry(thePet).State = EntityState.Modified;
                db.SaveChanges();
            }

            return View();
        }
Exemplo n.º 9
0
        public ActionResult Selling(Pet cPet)
        {
            //@ViewBag.Message = cPet.Description;
            //var cityId = Request.Form["citylist"];
            Customer currentUser = (Customer)Session["currentUser"];
            int customerId = currentUser.CustomerId;

            cPet.CustomerId = customerId;
            if (cPet.Description == null)
            {
                cPet.Description = "";
            }
            db.Pets.Add(cPet);
            db.SaveChanges();

            Service newService = new Service();
            newService.ProviderId = customerId;
            newService.PetId = cPet.PetId;
            newService.ServiceName = "Pet Selling by " + currentUser.FirstName + " " + currentUser.LastName;
            newService.Description = "Ordinary pet selling transaction";
            newService.Price = cPet.Price;
            db.Services.Add(newService);
            db.SaveChanges();

            ViewBag.Message = "Your pet info has been posted. Thank you for using our service.";

            return View();
        }
Exemplo n.º 10
0
        // POST:/PetBuyingSelling/SearchResult/
        // Show the search result and option to buy
        public ActionResult SearchResult(Pet cPet, decimal fromPrice = -12, decimal toPrice = -12)
        {
            // get list of all pets which is going to be sold by their owners.
            var petForSale = (from thePets in db.Pets
                              join theOwner in db.Customers on thePets.CustomerId equals theOwner.CustomerId
                              join service in db.Services on thePets.PetId equals service.PetId
                              where service.ServiceName.StartsWith("Pet Selling by ")
                              where thePets.PetCategory.Equals(cPet.PetCategory)
                              where !thePets.TransactionId.HasValue
                              select new SearchPetResult
                              {
                                  service_id = service.ServiceId,
                                  pet_owner_name = theOwner.FirstName + " " + theOwner.LastName,
                                  pet_category = thePets.PetCategory,
                                  pet_desc = thePets.Description,
                                  pet_price = (decimal)thePets.Price
                              }).Distinct();

            // Check whether user input a minimum value or maximum value for price
            // if the user only input the minimum price, then only minimum price is set
            // if the user only input the maximum price, then only the maximum price is set
            // if the user input both minimum & maximum price, then the price range is set
            if (!(fromPrice == -12))
            {
                petForSale = petForSale.Where(x => x.pet_price >= fromPrice);
            }

            if (!(toPrice == -12))
            {
                petForSale = petForSale.Where(x => x.pet_price <= toPrice);
            }
            //List<SearchPetResult> test = petForSale.ToList();
            //ViewData["petForSale"] = petForSale.ToList();
            //SearchPetResult petForSaleModel = (SearchPetResult)petForSale;
            return View(petForSale.AsEnumerable());
        }
Exemplo n.º 11
0
 public ActionResult Edit(Pet pet)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pet).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", pet.CustomerId);
     return View(pet);
 }
Exemplo n.º 12
0
        public ActionResult Create(Pet pet)
        {
            if (ModelState.IsValid)
            {
                db.Pets.Add(pet);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", pet.CustomerId);
            return View(pet);
        }
Exemplo n.º 13
0
        public ActionResult BuyProcess(int serviceId = 0)
        {
            int petId = 0;
            var cUser = (Customer)Session["currentUser"];
            Transaction trans = new Transaction();

            trans.CustomerId = cUser.CustomerId;
            trans.ServiceId = serviceId;
            trans.Date = System.DateTime.Now;
            trans.Status = "Finished";

            if (ModelState.IsValid)
            {
                db.Transactions.Add(trans);
                db.SaveChanges();
                //return RedirectToAction("Index");
            }

            /* Service theService = db.Services.Find(serviceId);
             db.Services.Remove(theService);
             db.SaveChanges();*/

            var getPetId = (from service in db.Services
                            where service.ServiceId.Equals(serviceId)
                            select new { service.PetId });

            foreach (var c in getPetId)
            {
                petId = (int)c.PetId;
            }

            Pet thePet = new Pet();
            thePet = db.Pets.Find(petId);
            thePet.TransactionId = trans.TransactionId;

            if (ModelState.IsValid)
            {
                db.Entry(thePet).State = EntityState.Modified;
                db.SaveChanges();
            }

            /*
            if (pet == null)
            {
                return HttpNotFound();
            }
            return View(pet);*/
            return View();
        }
Exemplo n.º 14
0
        public ActionResult PostInfo(Pet cPet)
        {
            //@ViewBag.Message = cPet.Description;
            //var cityId = Request.Form["citylist"];
            Customer currentUser = (Customer)Session["currentUser"];
            int customerId = currentUser.CustomerId;

            cPet.CustomerId = customerId;
            cPet.IsForAdoption = true;
            db.Pets.Add(cPet);
            db.SaveChanges();
            ViewBag.Message = "Your pet info has been posted. Thank you.";

            return View();
        }
Exemplo n.º 15
0
 public bool BookThisClassForMyPet(int classId, Pet pet, Customer owner)
 {
     PetClass target = GetPetClassById(classId);
        return BookThisClassForMyPet(target, pet, owner);
 }
Exemplo n.º 16
0
        public ActionResult Create(Pet pet)
        {
            if (ModelState.IsValid)
            {
                _logic = new PetLogic();
                _logic.AddPet(pet);
                //db.Pets.Add(pet);
                //db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Username", pet.CustomerId);
            return View(pet);
        }
Exemplo n.º 17
0
        public ActionResult PostFinding(Pet cPet)
        {
            Customer currentUser = (Customer)Session["currentUser"];
            int customerId = currentUser.CustomerId;

            cPet.CustomerId = customerId;
            cPet.Price = 0;
            db.Pets.Add(cPet);
            db.SaveChanges();

            Service newService = new Service();
            newService.ProviderId = customerId;
            newService.PetId = cPet.PetId;
            newService.ServiceName = "A lost pet founded by " + currentUser.FirstName + " " + currentUser.LastName;
            newService.Description = "Found a lost pet";
            newService.Price = 0;
            db.Services.Add(newService);
            db.SaveChanges();

            ViewBag.Message = "Your pet info has been posted. Thank you for using our service.";

            return View();
        }