public async Task <ActionResult> CreateAsync(IFormFile Photo, int IdSpeciePet, int IdBreedPet, int AgePet, bool IsAgeMonth, decimal WeightPet, int IdSexPet, string NamePet, int EnergyLevelId, string DescriptionPet)
        {
            try
            {
                string wwwRoothPath = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(Photo.FileName);
                string extension    = Path.GetExtension(Photo.FileName);

                fileName = fileName + DateTime.Now.ToString("yyyyMMddmmss") + extension;

                string path = Path.Combine(wwwRoothPath + "/img/" + fileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await Photo.CopyToAsync(stream);
                }

                var pet = new Pet()
                {
                    IdSpeciePet    = IdSpeciePet,
                    IdBreedPet     = IdBreedPet,
                    AgePet         = AgePet,
                    IsAgeMonth     = IsAgeMonth,
                    WeightPet      = WeightPet,
                    IdSexPet       = IdSexPet,
                    NamePet        = NamePet,
                    EnergyLevelId  = EnergyLevelId,
                    DescriptionPet = DescriptionPet,
                    PhotoPathPet   = "/img/" + fileName,
                    IdStatusPet    = 1
                };

                _dbcontext.Pets.Add(pet);
                _dbcontext.SaveChanges();

                return(RedirectToAction(nameof(Index), new { idSpecie = IdSpeciePet }));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        private static EnergyLevel CreateEnergyLevelIfNotExists(ProyectoPrograWebContext dbcontext, int Id, string descripcion)
        {
            var obj = dbcontext.EnergyLevels.Where(x => x.LevelId == Id);

            if (!obj.Any())
            {
                EnergyLevel o = new EnergyLevel()
                {
                    LevelName = descripcion
                };

                dbcontext.EnergyLevels.Add(o);
                dbcontext.SaveChanges();

                return(o);
            }

            return(null);
        }
Exemplo n.º 3
0
        private static Sex CreateSexIfNotExists(ProyectoPrograWebContext dbcontext, int Id, string descripcion)
        {
            var obj = dbcontext.Sexes.Where(x => x.IdSex == Id);

            if (!obj.Any())
            {
                Sex o = new Sex()
                {
                    NameSex = descripcion
                };

                dbcontext.Sexes.Add(o);
                dbcontext.SaveChanges();

                return(o);
            }

            return(null);
        }
Exemplo n.º 4
0
        private static StatusPet CreateStatusPetIfNotExists(ProyectoPrograWebContext dbcontext, int Id, string descripcion)
        {
            var obj = dbcontext.StatusPets.Where(x => x.IdStatus == Id);

            if (!obj.Any())
            {
                StatusPet o = new StatusPet()
                {
                    NameStatus = descripcion
                };

                dbcontext.StatusPets.Add(o);
                dbcontext.SaveChanges();

                return(o);
            }

            return(null);
        }
Exemplo n.º 5
0
        private static Breed CreateBreedIfNotExists(ProyectoPrograWebContext dbcontext, int Id, int IdSpecie, string descripcion)
        {
            var obj = dbcontext.Breeds.Where(x => x.IdBreed == Id);

            if (!obj.Any())
            {
                Breed o = new Breed()
                {
                    IdSpecieRace = IdSpecie,
                    NameBreed    = descripcion
                };

                dbcontext.Breeds.Add(o);
                dbcontext.SaveChanges();

                return(o);
            }

            return(null);
        }