public Animal Get(int id)
        {
            Animal animalToReturn = _db.Animals.FirstOrDefault(entry => entry.AnimalId == id);
            IEnumerable <AnimalVaccination> theseVaccinationLinks = _db.AnimalVaccinations.Where(entry => entry.AnimalId == id);

            foreach (AnimalVaccination link in theseVaccinationLinks)
            {
                Vaccination vaccineToAdd = _db.Vaccinations.FirstOrDefault(entry => entry.VaccinationId == link.VaccinationId);
                string      name         = vaccineToAdd.Name;
                animalToReturn.Add(name);
            }
            return(animalToReturn);
        }
    protected void CreateAnimal(object sender, EventArgs e)
    {
        WebsiteUser Op          = (WebsiteUser)Session["User"];
        WebImage    photo       = null;
        var         newFileName = "";
        var         imagePath   = "";

        if (IsValid)
        {
            photo = WebImage.GetImageFromRequest();
            if (photo != null)
            {
                newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(photo.FileName);
                imagePath   = @"Images\" + newFileName;
                photo.Resize(width: 250, height: 300, preserveAspectRatio: true, preventEnlarge: true);
                photo.Save(@"~\" + imagePath);
                ErrorMessage.Visible = true;

                Animal subject = new Animal(Nome.Text, Espécie.Text, Raca.Text, Convert.ToUInt32(Idade.Text.ToString()), Convert.ToUInt32(Peso.Text.ToString()), Convert.ToUInt32(Temperatura.Text.ToString()), imagePath, Op.ClientID, Convert.ToUInt32(DropDownTipo.Text));

                switch (Animal.Add(subject))
                {
                case 0:
                    ErrorMessage.Text = "Erro ao registar novo animal. Por favor verifique se os dados que inseriu são válidos.";
                    break;

                case 1:
                    ErrorMessage.Text = "O animal foi registdo com sucesso mas houve um problema ao enviar a foto.";
                    break;

                case 2:
                    ErrorMessage.Text = "Registo efectuado com sucesso.";
                    break;

                default:
                    ErrorMessage.Text = "Erro desconhecido.";
                    break;
                }
            }
            else
            {
                ErrorMessage.Text = "Foto inválida.";
            }
        }
    }
Exemple #3
0
        public ActionResult Index(Animal model)
        {
            AnimalMessageId message = AnimalMessageId.Error;
            int             id      = 0;

            try
            {
                if (model != null)
                {
                    model.Add();
                    message = AnimalMessageId.AddSuccess;
                    id      = model.Id;
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", new { message = AnimalMessageId.Error }));
            }
            return(RedirectToAction("Index", new { AnimalId = id, message = message }));
        }
Exemple #4
0
        //Allan
        public void ControllerNewAnimal(string Name, char Gender, string Birthdate, string Race, int Doctor, int Chip)
        {
            Animal animal = new Animal(Name, Gender, Birthdate, Race, Doctor, Chip);

            animal.Add();
        }