Esempio n. 1
0
        public IActionResult Index()
        {
            ViewBag.Win  = false;
            ViewBag.Lose = false;
            var current = HttpContext.Session.GetObjectFromJson <pet>("pet");

            if (HttpContext.Session.GetObjectFromJson <pet>("pet") == null)
            {
                var Pal = new pet();
                HttpContext.Session.SetObjectAsJson("pet", Pal);
            }
            if (HttpContext.Session.GetObjectFromJson <pet>("pet").Energy >= 100 && HttpContext.Session.GetObjectFromJson <pet>("pet").Full >= 100)
            {
                if (HttpContext.Session.GetObjectFromJson <pet>("pet").Happy >= 100)
                {
                    TempData["comment"] = "You win!";
                    ViewBag.Win         = true;
                    return(View("index"));
                }
            }
            if (HttpContext.Session.GetObjectFromJson <pet>("pet").Full <= 0 || HttpContext.Session.GetObjectFromJson <pet>("pet").Happy <= 0)
            {
                TempData["comment"] = "It died!";
                ViewBag.Lose        = true;
                return(View("index"));
            }
            ViewBag.Pal     = HttpContext.Session.GetObjectFromJson <pet>("pet");
            ViewBag.Message = TempData["comment"];
            return(View("index"));
        }
Esempio n. 2
0
        public void DeletePet(pet pet)
        {
            var list = database.Pets.ToList();

            list.Remove(pet);
            database.Pets = list;
        }
Esempio n. 3
0
        public ActionResult Placeorder()
        {
            order      order = new order();
            order_user os    = new order_user();

            int  id = Int32.Parse(Session["user"].ToString());
            user us = ps.users.Where(c => c.id == id).FirstOrDefault();

            order.status     = false;
            order.date_order = DateTime.Now;

            ps.orders.Add(order);
            ps.SaveChanges();


            order = ps.orders.Where(c => c.id == ps.orders.Max(item => item.id)).FirstOrDefault();

            os.user_id  = us.id;
            os.order_id = order.id;

            ps.order_user.Add(os);
            item   ie         = null;
            pet    p          = null;
            double?priceTotal = 0;

            foreach (var item in (List <cart>)Session["cart"])
            {
                order_product od = new order_product();
                if (!item.itemorpet())
                {
                    od.item_id   = item.item.id;
                    ie           = ps.items.Where(c => c.id == item.item.id).FirstOrDefault();
                    od.order_id  = order.id;
                    od.quantity  = item.quantity;
                    ie.quantity -= item.quantity;
                    od.price     = item.price();
                    priceTotal  += item.price();
                    ps.order_product.Add(od);
                }
                else
                {
                    od.pet_id   = item.pet.id;
                    od.order_id = order.id;
                    od.quantity = item.quantity;
                    p           = ps.pets.Where(c => c.id == item.pet.id).FirstOrDefault();
                    p.price    -= item.quantity;
                    od.price    = item.price();
                    priceTotal += item.price();
                    ps.order_product.Add(od);
                }
            }
            order.price = priceTotal;
            ps.SaveChanges();
            Session["cart"] = new List <cart>();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public void AddPet(pet pet)
        {
            var list = database.Pets;

            pet.id = list.ElementAt(list.Count() - 1).id + 1;
            var petList = list.ToList();

            petList.Add(pet);

            database.Pets = petList;
        }
Esempio n. 5
0
        public void UpdatePet(pet updatePet)
        {
            var list = database.Pets.ToArray();;

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i].id == updatePet.id)
                {
                    list[i] = updatePet;
                }
            }
            database.Pets = list;
        }
Esempio n. 6
0
        public void UpdatePet(int id, string name, string type, string colour, string previousOwner, double price, DateTime birthdate)
        {
            var pet = new pet();

            pet.id            = id;
            pet.name          = name;
            pet.type          = type;
            pet.colour        = colour;
            pet.previousOwner = previousOwner;
            pet.price         = price;
            pet.birthDate     = birthdate;

            _petRepository.UpdatePet(pet);
        }
Esempio n. 7
0
        internal void UpdatePet(PetUpdateRequest PetUpdateRequest)
        {
            logger.Trace("Recived pet update request");
            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                if (PetUpdateRequest == null || PetUpdateRequest.id <= 0 ||
                    String.IsNullOrEmpty(PetUpdateRequest.petName))
                {
                    logger.Error("Pet update Request body is empty or required fields not found");
                    throw new CustomException("Pet update request invalid", (int)ErrorCode.VALIDATIONFAILED);
                }
                using (var ctx = new PetWhizzEntities())
                {
                    pet Pet = ctx.pets.Where(a => a.id == PetUpdateRequest.id).FirstOrDefault();
                    if (Pet == null)
                    {
                        logger.Error("Pet record is not fount for petId - " + PetUpdateRequest.id.ToString());
                        throw new CustomException("Pet object not found", (int)ErrorCode.NORECORDFOUND);
                    }
                    //looking for authorization
                    if (Pet.petOwners.Where(a => a.userId == currentUser.userId).FirstOrDefault() == null)
                    {
                        logger.Error("Pet record is not fount for petId - " + PetUpdateRequest.id.ToString() + " and userId - " + currentUser.userId);
                        throw new CustomException("Pet object not found for user", (int)ErrorCode.UNAUTHORIZED);
                    }

                    //update pet
                    ctx.pets.Attach(Pet);
                    Pet.breedId         = PetUpdateRequest.breedId;
                    Pet.birthDay        = PetUpdateRequest.birthDay;
                    Pet.coverImage      = PetUpdateRequest.coverImage;
                    Pet.isActive        = PetUpdateRequest.isActive;
                    Pet.lastUpdatedBy   = currentUser.username;
                    Pet.lastUpdatedTime = DateTime.Now;
                    Pet.petName         = PetUpdateRequest.petName;
                    Pet.profileImage    = PetUpdateRequest.profileImage;
                    Pet.sex             = PetUpdateRequest.sex;
                    ctx.SaveChanges();
                    logger.Trace("Successfully updated Pet id - " + Pet.id + " by - " + currentUser.username);
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
        }
Esempio n. 8
0
        public void CreatePet(string name, string type, string colour, string previousOwner, double price, DateTime birthdate)
        {
            pet pet = new pet()
            {
                name          = name,
                type          = type,
                previousOwner = previousOwner,
                colour        = colour,
                birthDate     = birthdate,
                price         = price,
                soldDate      = DateTime.Now
            };

            Save(pet);
        }
Esempio n. 9
0
 // Use this for initialization
 void Start()
 {
     gold     = 100;
     donut    = new Item(20, 1, 1, 0, -1);
     smoothie = new Item(10, 0, 1, 0, -1);
     ball     = new Item(15, 2, -1, 0, -1);
     bandaid  = new Item(10, 0, 0, 1, 0);
     soap     = new Item(5, 0, 0, 0, 1);
     itemList.Add(donut);
     itemList.Add(smoothie);
     itemList.Add(ball);
     itemList.Add(bandaid);
     itemList.Add(soap);
     pet = trashi.GetComponent <pet>();
 }
Esempio n. 10
0
        internal PetUserResponse GetUsersByPet(PetUserRequest petUserRequest)
        {
            logger.Trace("Recived Get Users By Pet request");
            PetUserResponse PetUserResponse = new PetUserResponse();

            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                if (petUserRequest.petId <= 0)
                {
                    logger.Error("Get users by pet petId is invalid");
                    throw new CustomException("Get users by pet petId is invalid", (int)ErrorCode.VALIDATIONFAILED);
                }
                using (var ctx = new PetWhizzEntities())
                {
                    pet Pet = ctx.pets.Where(a => a.id == petUserRequest.petId).FirstOrDefault();
                    if (Pet == null)
                    {
                        logger.Error("No pet found for given Id");
                        throw new CustomException("No pet found for given Id", (int)ErrorCode.NORECORDFOUND);
                    }
                    List <petOwner> petOwnerList = Pet.petOwners.Where(a => a.userId != currentUser.userId).ToList();
                    PetUserResponse.PetUserList = new List <PetUser>();
                    foreach (petOwner owner in petOwnerList)
                    {
                        PetUserResponse.userCount++;
                        PetUser PetUser = new PetUser()
                        {
                            isConfirmed = owner.isActive,
                            profilePic  = owner.user.profilePic,
                            userId      = owner.userId,
                            userName    = owner.user.userName
                        };
                        PetUserResponse.PetUserList.Add(PetUser);
                    }
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
            return(PetUserResponse);
        }
Esempio n. 11
0
 internal void DeletePet(PetDeleteRequest petDeleteRequest)
 {
     logger.Trace("Recived get pets delete request");
     try
     {
         CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
         petDeleteRequest.petId = Decryptor.Decrypt(petDeleteRequest.petId).Split('|')[1];
         Int64 petId = Convert.ToInt64(petDeleteRequest.petId);
         if (String.IsNullOrEmpty(petDeleteRequest.petId))
         {
             logger.Error("Pet id not found on request");
             throw new CustomException("Pet id not found on request", (int)ErrorCode.VALIDATIONFAILED);
         }
         using (var ctx = new PetWhizzEntities())
         {
             pet Pet = ctx.pets.Where(a => a.id == petId).FirstOrDefault();
             if (Pet.petOwners.Where(a => a.userId == currentUser.userId && a.isActive == true && a.isMainOwner == true).FirstOrDefault() == null)
             {
                 logger.Error("Requested user not belongs to the pet or not the main owner");
                 throw new CustomException("Requested user not belongs to the pet or not the main owner", (int)ErrorCode.UNAUTHORIZED);
             }
             //delete pet
             ctx.pets.Attach(Pet);
             Pet.isActive  = false;
             Pet.isDeleted = true;
             ctx.SaveChanges();
             logger.Trace("Pet successfully deleted");
         }
     }
     catch (CustomException) { throw; }
     catch (Exception ex)
     {
         logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
         throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
     }
 }
Esempio n. 12
0
        public static void DataStart()
        {
            pet pet1 = new pet()
            {
                id            = 0,
                name          = "fabio",
                birthDate     = DateTime.Parse("10/10/1993"),
                colour        = "latino",
                previousOwner = "my mum",
                price         = 1234,
                soldDate      = DateTime.Parse("20/02/2008"),
                type          = "dog"
            };
            pet pet2 = new pet()
            {
                id            = 1,
                name          = "thgff",
                birthDate     = DateTime.Parse("7/2/1970"),
                colour        = "dfgdfgd",
                previousOwner = "tsr sfd",
                price         = 11151,
                soldDate      = DateTime.Parse("11/11/1911"),
                type          = "cat"
            };
            pet pet3 = new pet()
            {
                id            = 2,
                name          = "gitte",
                type          = "dog",
                colour        = "yellow",
                previousOwner = "someone",
                birthDate     = DateTime.Parse("07/02/1999"),
                price         = 5010,
                soldDate      = DateTime.Parse("20/6/2005")
            };
            pet pet4 = new pet()
            {
                id            = 3,
                name          = "Willow",
                type          = "Popcorn",
                colour        = "White",
                previousOwner = "Me",
                birthDate     = DateTime.Parse("31/10/2016"),
                price         = 7080,
                soldDate      = DateTime.Parse("11/8/2017")
            };
            pet pet5 = new pet()
            {
                id            = 4,
                name          = "dog",
                type          = "dog",
                colour        = "green",
                previousOwner = "tequila",
                birthDate     = DateTime.Parse("2/2/2015"),
                price         = 4500,
                soldDate      = DateTime.Parse("2/2/2016")
            };

            Pets = new List <pet> {
                pet1, pet2, pet3, pet4, pet5
            };
        }
Esempio n. 13
0
        internal void PetEnrollment(PetEnrollmentRequest petEnrollmentRequest)
        {
            logger.Trace("Recived pet enroll request");
            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                if (String.IsNullOrEmpty(petEnrollmentRequest.petName) || petEnrollmentRequest.breedId == 0)
                {
                    logger.Error("Required fiedls not found on pet emrollment reuest");
                    throw new CustomException("Breed or Pet Name is empty", (int)ErrorCode.VALIDATIONFAILED);
                }
                //creating pet object
                pet Pet = new pet()
                {
                    profileImage = petEnrollmentRequest.profileImage,
                    coverImage   = petEnrollmentRequest.coverImage,
                    sex          = petEnrollmentRequest.sex,
                    birthDay     = petEnrollmentRequest.birthDay,
                    breedId      = petEnrollmentRequest.breedId,
                    entryDate    = DateTime.Now,
                    isActive     = true,
                    isDeleted    = false,
                    petName      = petEnrollmentRequest.petName
                };
                using (var ctx = new PetWhizzEntities())
                {
                    using (var dbContextTransaction = ctx.Database.BeginTransaction())
                    {
                        try
                        {
                            ctx.pets.Add(Pet);
                            ctx.SaveChanges();

                            petOwner PetOwner = new petOwner()
                            {
                                enteryDate  = DateTime.Now,
                                petId       = Pet.id,
                                userId      = currentUser.userId,
                                isActive    = true,
                                isMainOwner = true
                            };
                            ctx.petOwners.Add(PetOwner);
                            ctx.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                            logger.Error("DB error occure when enrolling Pet");
                            throw new CustomException("Pet Enrolling failed", (int)ErrorCode.PROCEESINGERROR);
                        }
                    }
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
        }
Esempio n. 14
0
        internal void SharePet(PetShareRequest petShareRequest)
        {
            logger.Trace("Recived Pet share request");
            try
            {
                if (String.IsNullOrEmpty(petShareRequest.username) || String.IsNullOrEmpty(petShareRequest.email) || petShareRequest.petId <= 0)
                {
                    logger.Error("Recived Pet share request");
                    throw new CustomException("Pet share request dosent have required fields", (int)ErrorCode.VALIDATIONFAILED);
                }
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                using (var ctx = new PetWhizzEntities())
                {
                    user User = ctx.users.Where(a => a.eMail.ToLower() == petShareRequest.email.ToLower()).FirstOrDefault();
                    if (User == null)
                    {
                        logger.Error("Requested user details not matching for Petwhizz user email - " + petShareRequest.email);
                        throw new CustomException("Requested user details not matching for Petwhizz user", (int)ErrorCode.USERNOTFOUND);
                    }
                    if (User.userName.ToLower() != petShareRequest.username.ToLower())
                    {
                        logger.Error("Requested user details not matching for Petwhizz user username - " + petShareRequest.username);
                        throw new CustomException("Requested user details not matching for Petwhizz user username", (int)ErrorCode.VALIDATIONFAILED);
                    }
                    pet Pet = ctx.pets.Where(a => a.id == petShareRequest.petId).FirstOrDefault();
                    if (Pet.petOwners.Where(a => a.userId == currentUser.userId && a.isActive == true && a.isMainOwner == true).FirstOrDefault() == null)
                    {
                        logger.Error("Requested user not belongs to the pet or not the main owner");
                        throw new CustomException("Requested user not belongs to the pet or not the main owner", (int)ErrorCode.UNAUTHORIZED);
                    }

                    petOwner PetOwner = ctx.petOwners.Where(a => a.petId == petShareRequest.petId && a.userId == User.id).FirstOrDefault();
                    if (PetOwner != null && PetOwner.isActive == true)
                    {
                        logger.Error("Pet is already shared with requestd user");
                        throw new CustomException("Pet is already shared with requestd user", (int)ErrorCode.ALREADYEXIST);
                    }
                    else if (PetOwner != null && PetOwner.isActive == false)
                    {
                        logger.Error("Pet is already shared with this user but not yet confirmed.");
                        throw new CustomException("Pet is already shared with this user but not yet confirmed.", (int)ErrorCode.NOTCONFIRMED);
                    }
                    else
                    {
                        //share pet
                        PetOwner = new petOwner()
                        {
                            enteryDate   = DateTime.Now,
                            isActive     = false,
                            isMainOwner  = false,
                            petId        = petShareRequest.petId,
                            sharedTime   = DateTime.Now,
                            sharedUserId = currentUser.userId,
                            acceptedTime = null,
                            userId       = User.id
                        };
                        ctx.petOwners.Add(PetOwner);
                        ctx.SaveChanges();
                        // var EmailService = new EmailService();
                        SendPetSharingEmail(PetOwner);
                    }
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
        }
Esempio n. 15
0
 public void Save(pet pet)
 {
     _petRepository.AddPet(pet);
 }
Esempio n. 16
0
        public void DeletePet(int id)
        {
            pet pet = ReturnPetId(id);

            _petRepository.DeletePet(pet);
        }