// ----------
        //  Product Details Page
        private DetailsAnuntViewModel MapDbObjectToModelIMG(Anunt dbAnunt)
        {
            DetailsAnuntViewModel detailsAnunt = new DetailsAnuntViewModel();

            if (dbAnunt != null)
            {
                detailsAnunt.ID_Anunt = dbAnunt.ID_Anunt;

                detailsAnunt.KM              = dbAnunt.KM;
                detailsAnunt.AnFabricatie    = dbAnunt.AnFabricatie;
                detailsAnunt.Descriere       = dbAnunt.Descriere;
                detailsAnunt.DescriereScurta = dbAnunt.DescriereScurta;
                detailsAnunt.Pret            = dbAnunt.Pret;

                MarcaAutoRepository marcaAutoRepository = new Repository.MarcaAutoRepository();
                MarcaAutoModel      marca = marcaAutoRepository.GetMarcaAutoByID(dbAnunt.ID_Marca);
                if (marca != null)
                {
                    detailsAnunt.Marca = marca.Marca;
                }


                ModelAutoRepository modelAutoRepository = new Repository.ModelAutoRepository();
                ModelAutoModel      model = modelAutoRepository.GetModelAutoByID(dbAnunt.ID_Model);
                if (model != null)
                {
                    detailsAnunt.Model = model.Model;
                }


                TipCaracteristicaRepository tipCaracteristica      = new TipCaracteristicaRepository();
                TipCaracteristicaModel      tipCaracteristicaModel = tipCaracteristica.GetTipCaracteristicaByID(dbAnunt.ID_TipCaracteristica);
                if (tipCaracteristicaModel != null)
                {
                    detailsAnunt.NumeTipCaracteristica = tipCaracteristicaModel.NumeTipCaracteristica;
                }


                CaracteristiciRepository caracteristicaRepo  = new CaracteristiciRepository();
                CaracteristiciModel      caracteristicaModel = caracteristicaRepo.GetCaracteristiciModelByID(dbAnunt.ID_Caracteristica);
                if (caracteristicaModel != null)
                {
                    detailsAnunt.NumeTipCaracteristica = caracteristicaModel.NumeTipCaracteristica;
                }


                CarImgRepository   carImgRepository = new CarImgRepository();
                List <CarImgModel> listaImg         = carImgRepository.GetAllCarImgByAnunt(dbAnunt.ID_Anunt);
                if (listaImg != null)
                {
                    detailsAnunt.Photos = listaImg;
                }



                return(detailsAnunt);
            }
            return(null);
        }
        //delete
        public void DeleteAnunt(Guid ID)
        {
            Anunt anuntToDelete = dbContext.Anunts.FirstOrDefault(x => x.ID_Anunt == ID);

            if (anuntToDelete != null)
            {
                dbContext.Anunts.DeleteOnSubmit(anuntToDelete);
                dbContext.SubmitChanges();
            }
        }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Anunt = await _context.Anunt.FirstOrDefaultAsync(m => m.ID == id);

            if (Anunt == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Anunt = await _context.Anunt.FindAsync(id);

            if (Anunt != null)
            {
                _context.Anunt.Remove(Anunt);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #5
0
        public int AddAnunt(AnuntDto dto)
        {
            var role = _roleManager.Roles.Where(x => x.Name == dto.Role).FirstOrDefault();

            var anunt = new Anunt()
            {
                Content = dto.Content,
                Subject = dto.Subject,
                Role    = role,
                Created = DateTime.Now
            };

            _anuntRepo.Insert(anunt);

            _anuntRepo.Save();

            return(anunt.Id);
        }
        // map Model to ORM - mapper method
        private Anunt MapModelToDbObject(AnuntModel anuntModel)
        {
            Anunt dbAnuntModel = new Anunt();

            if (anuntModel != null)
            {
                dbAnuntModel.ID_Anunt             = anuntModel.ID_Anunt;
                dbAnuntModel.ID_Caracteristica    = anuntModel.ID_Caracteristica;
                dbAnuntModel.ID_TipCaracteristica = anuntModel.ID_TipCaracteristica;
                dbAnuntModel.ID_User         = anuntModel.ID_User;
                dbAnuntModel.ID_Model        = anuntModel.ID_Model;
                dbAnuntModel.ID_Marca        = anuntModel.ID_Marca;
                dbAnuntModel.KM              = anuntModel.KM;
                dbAnuntModel.Descriere       = anuntModel.Descriere;
                dbAnuntModel.DescriereScurta = anuntModel.DescriereScurta;
                dbAnuntModel.Pret            = anuntModel.Pret;
                dbAnuntModel.AnFabricatie    = anuntModel.AnFabricatie;

                return(dbAnuntModel);
            }
            return(null);
        }
        // map ORM to Model - mapper method
        private AnuntModel MapDbObjectToModel(Anunt dbAnunt)
        {
            AnuntModel anuntModel = new AnuntModel();

            if (dbAnunt != null)
            {
                anuntModel.ID_Anunt             = dbAnunt.ID_Anunt;
                anuntModel.ID_User              = dbAnunt.ID_User;
                anuntModel.ID_Model             = dbAnunt.ID_Model;
                anuntModel.ID_Marca             = dbAnunt.ID_Marca;
                anuntModel.ID_TipCaracteristica = dbAnunt.ID_TipCaracteristica;
                anuntModel.ID_Caracteristica    = dbAnunt.ID_Caracteristica;
                anuntModel.KM              = dbAnunt.KM;
                anuntModel.AnFabricatie    = dbAnunt.AnFabricatie;
                anuntModel.Descriere       = dbAnunt.Descriere;
                anuntModel.DescriereScurta = dbAnunt.DescriereScurta;
                anuntModel.Pret            = dbAnunt.Pret;


                return(anuntModel);
            }
            return(null);
        }