コード例 #1
0
        public bool Update(PetTrackerModel petTrackerModel)
        {
            var original = DatabaseManager.Instance.PetTrackers.Find(petTrackerModel.Id);

            if (original != null)
            {
                DatabaseManager.Instance.Entry(original).CurrentValues.SetValues(ToDBModel(petTrackerModel));
                DatabaseManager.Instance.SaveChanges();
            }

            return(false);
        }
コード例 #2
0
        public PetTracker ToDBModel(PetTrackerModel petTrackerModel)
        {
            var petTrackerDB = new PetTracker()
            {
                PetId          = petTrackerModel.Id,
                PetNumber      = petTrackerModel.Number,
                PetBreed       = petTrackerModel.Breed,
                PetDescription = petTrackerModel.Description,
                PetPrice       = petTrackerModel.Price,
                PetQuantity    = petTrackerModel.Quantity,
                PetCost        = petTrackerModel.Cost,
                PetValue       = petTrackerModel.Value,
                PetCreatedDate = petTrackerModel.CreatedDate,
            };

            return(petTrackerDB);
        }
コード例 #3
0
        public PetTrackerModel Add(PetTrackerModel petTrackerModel)
        {
            var petTrackerDB = ToDBModel(petTrackerModel);

            DatabaseManager.Instance.PetTrackers.Add(petTrackerDB);
            DatabaseManager.Instance.SaveChanges();

            petTrackerModel = new PetTrackerModel
            {
                Id          = petTrackerDB.PetId,
                Breed       = petTrackerDB.PetBreed,
                Description = petTrackerDB.PetDescription,
                Price       = petTrackerDB.PetPrice,
                Quantity    = petTrackerDB.PetQuantity,
                Cost        = petTrackerDB.PetCost,
                Value       = petTrackerDB.PetValue,
                CreatedDate = petTrackerDB.PetCreatedDate,
            };
            return(petTrackerModel);
        }