Beispiel #1
0
        public int Create(PetVaccine item)
        {
            _context.PetVaccines.Add(item);
            _context.SaveChanges();

            return item.Id;
        }
        public int Create(AnimalType item)
        {
            _context.AnimalTypes.Add(item);
            _context.SaveChanges();

            return(item.Id);
        }
Beispiel #3
0
        public int Create(UserVm item)
        {
            var ent = _mapper.MaptoEntity(item);

            _context.Users.Add(ent);
            _context.SaveChanges();

            return(ent.Id);
        }
Beispiel #4
0
        public int Create(Petvm item)
        {
            var ent = _mapper.MaptoEntetity(item);

            _context.Pets.Add(ent);
            _context.SaveChanges();

            return(ent.Id);
        }
        public void AddComment(Comment comment)
        {
            comment.PublishDate = DateTime.Now;
            var db = new AnimalsContext();

            db.Comments.Add(comment);
            db.SaveChanges();
        }
        public Animal Post(Animal model)
        {
            model.PublishDate = DateTime.Now;
            model.UserId      = Members.GetCurrentMemberId();
            var db        = new AnimalsContext();
            var newAnimal = db.Animals.Add(model);

            db.SaveChanges();
            return(newAnimal);
        }
    public void Test()
    {
        var context       = new AnimalsContext();
        var genericAnimal = new Animal();

        context.Animals.Add(genericAnimal);
        context.SaveChanges();
        // Make a new clean entity, but copy the ID (important!)
        var dog = new Dog {
            Id = genericAnimal.Id,
        };

        // Do the old switch-a-roo -- detach the existing one and attach the new one
        // NOTE: the order is important!  Detach existing FIRST, then attach the new one
        context.Entry(genericAnimal).State = EntityState.Detached;
        context.Entry(dog).State           = EntityState.Modified;
        context.SaveChanges();
        var thisShouldBeADog = context.Animals.Find(genericAnimal.Id);

        // thisShouldBeADog is indeed a Dog!
        Debug.Assert(thisShouldBeADog is Dog);
        // And, of course, all the IDs match because it's the same entity
        Debug.Assert((genericAnimal.Id == dog.Id) && (dog.Id == thisShouldBeADog.Id));
    }
        public HttpResponseMessage PutStatus(Animal model)
        {
            var db            = new AnimalsContext();
            var modelToUpdate = db.Animals.SingleOrDefault(x => x.AnimalId == model.AnimalId);

            if (modelToUpdate != null)
            {
                modelToUpdate.Status = model.Status != modelToUpdate.Status ? model.Status : modelToUpdate.Status;
                db.SaveChanges();

                // We promissed to inform by e-mail
                Email.SendEmail(modelToUpdate);

                return(Request.CreateResponse(HttpStatusCode.OK, modelToUpdate));
            }
            return(Request.CreateResponse(HttpStatusCode.Gone));
        }
        public HttpResponseMessage Put(Animal model)
        {
            var db            = new AnimalsContext();
            var modelToUpdate = db.Animals.SingleOrDefault(x => x.AnimalId == model.AnimalId);

            if (modelToUpdate != null)
            {
                modelToUpdate.Status      = model.Status != modelToUpdate.Status ? model.Status : modelToUpdate.Status;
                modelToUpdate.Name        = model.Name != null && model.Name != modelToUpdate.Name ? model.Name : modelToUpdate.Name;
                modelToUpdate.PhotoUrl    = model.PhotoUrl != null && model.PhotoUrl != modelToUpdate.PhotoUrl ? model.PhotoUrl : modelToUpdate.PhotoUrl;
                modelToUpdate.Description = model.Description != null && model.Description != modelToUpdate.Description ? model.Description : modelToUpdate.Description;
                //modelToUpdate.Species = model.Species != modelToUpdate.Species ? model.Species : modelToUpdate.Species;
                modelToUpdate.AnimalSpeciesId = model.AnimalSpeciesId != 0 && model.AnimalSpeciesId != modelToUpdate.AnimalSpeciesId ? model.AnimalSpeciesId : modelToUpdate.AnimalSpeciesId;
                db.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, modelToUpdate));
            }
            return(Request.CreateResponse(HttpStatusCode.Gone));
        }
Beispiel #10
0
 public IActionResult Choosecage([Bind("Name,Sex,ShopID,CageID,SpeciesID,Date,ColorID,Price")] Animal animal)
 {
     if (animal.CageID == null && animal.Name != null)
     {
         animal1 = animal;
         CagesDropDownList(animal.ShopID);
         return(View(animal));
     }
     animal1.CageID = animal.CageID;
     if (animal1.CageID == null)
     {
         Animal animal2 = animal1;
         return(Choosecage(animal2));
     }
     _context.Add(animal1);
     _context.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
Beispiel #11
0
        private void UpdateSpeciesFood(string[] selectedFood, Species speciesToUpdate)
        {
            if (selectedFood == null)
            {
                speciesToUpdate.SpeciesFood = new List <SpeciesFood>();
                return;
            }

            var selectedFoodHS = new HashSet <string>(selectedFood);
            var speciesFood    = new HashSet <int>
                                     (speciesToUpdate.SpeciesFood.Select(sf => sf.Food.ID));

            foreach (var food in _context.Food)
            {
                if (selectedFoodHS.Contains(food.ID.ToString()))
                {
                    if (!speciesFood.Contains(food.ID))
                    {
                        SpeciesFood newElement = new SpeciesFood {
                            SpeciesID = speciesToUpdate.ID, FoodID = food.ID, ID = Guid.NewGuid().GetHashCode()
                        };
                        speciesToUpdate.SpeciesFood.Add(newElement);
                        _context.SpeciesFood.Add(newElement);
                    }
                }
                else
                {
                    if (speciesFood.Contains(food.ID))
                    {
                        SpeciesFood foodToRemove = speciesToUpdate.SpeciesFood.FirstOrDefault(i => i.FoodID == food.ID);
                        _context.Remove(foodToRemove);
                    }
                }
            }
            _context.SaveChanges();
        }
 public void AddNewAnimal(Animal newAnimal)
 {
     _context.Add(newAnimal);
     _context.SaveChanges();
 }
Beispiel #13
0
 public void SaveChanges() => _db.SaveChanges();