public async Task <IActionResult> Delete(int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Agences _agences = _unitOfWork.Agences.GetSingleOrDefault(e => e.Id == id);
                    if (_agences != null)
                    {
                        _unitOfWork.Agences.Remove(_agences);
                        await _unitOfWork.SaveChangesAsync();

                        return(Ok("OK"));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public HotelContext(DbContextOptions <HotelContext> options) : base(options)
        {
            if (Agences.Count() == 0)
            {
                Agences.Add(new HotelModel.Agence
                {
                    IdentifiantAgence = "hijk",
                    MotDePasseAgence  = "lmnop",
                    Reduction         = 0.75
                });

                SaveChanges();
            }

            if (Chambres.Count() == 0)
            {
                Chambres.Add(new HotelModel.Chambre
                {
                    NombreDeLits = 3,
                    Surface      = 40,
                    BasePrix     = 100,
                    ImageUrl     = "https://www.usine-digitale.fr/mediatheque/3/9/8/000493893/hotel-c-o-q-paris.jpg"
                });

                Chambres.Add(new HotelModel.Chambre
                {
                    NombreDeLits = 1,
                    Surface      = 100,
                    BasePrix     = 35,
                    ImageUrl     = "https://www.hotel-design-secret-de-paris.com/wp-content/uploads/2015/01/secret-de-paris-chambre-trocadero-21-md1.jpg"
                });

                SaveChanges();
            }
        }
Example #3
0
        public async Task <IActionResult> Post([FromBody] EntrepriseUserInfosViewModel entrepriseUserInfos)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    EntrepriseUserInfos _entrepriseUserInfos = Mapper.Map <EntrepriseUserInfos>(entrepriseUserInfos);

                    Agences  _agence  = _unitOfWork.Agences.GetSingleOrDefault(e => e.Id == entrepriseUserInfos.AgencesId);
                    Services _service = _unitOfWork.Services.GetSingleOrDefault(e => e.Id == entrepriseUserInfos.ServicesId);

                    _entrepriseUserInfos.Agences           = _agence;
                    _entrepriseUserInfos.Services          = _service;
                    _entrepriseUserInfos.ApplicationUserId = entrepriseUserInfos.ApplicationUserId;
                    _unitOfWork.EntrepriseUserInfos.Add(_entrepriseUserInfos);
                    await _unitOfWork.SaveChangesAsync();

                    return(Ok("OK"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <IActionResult> Put(int id, [FromBody] AgencesViewModel agences)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Agences _agences = Mapper.Map <Agences>(agences);
                    Villes  villes   = _unitOfWork.Villes.GetSingleOrDefault(e => e.Id == agences.VillesId);
                    _agences.Villes = villes;
                    //_agences.Name = _agences.Name.ToUpper();
                    _unitOfWork.Agences.Update(_agences);

                    await _unitOfWork.SaveChangesAsync();

                    return(Ok("OK"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Example #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Agences agences = db.Agences.Find(id);

            db.Agences.Remove(agences);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #6
0
 public ActionResult Edit([Bind(Include = "id_agence,agence")] Agences agences)
 {
     if (ModelState.IsValid)
     {
         db.Entry(agences).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(agences));
 }
Example #7
0
        public ActionResult Create([Bind(Include = "id_agence,agence")] Agences agences)
        {
            if (ModelState.IsValid)
            {
                db.Agences.Add(agences);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(agences));
        }
        public HotelContext(DbContextOptions <HotelContext> options) : base(options)
        {
            if (Agences.Count() == 0)
            {
                Agences.Add(new HotelModel.Agence
                {
                    IdentifiantAgence = "abcd",
                    MotDePasseAgence  = "efgh",
                    Reduction         = 0.25
                });

                Agences.Add(new HotelModel.Agence
                {
                    IdentifiantAgence = "hijk",
                    MotDePasseAgence  = "lmnop",
                    Reduction         = 0.5
                });

                SaveChanges();
            }

            if (Chambres.Count() == 0)
            {
                Chambres.Add(new HotelModel.Chambre
                {
                    NombreDeLits = 3,
                    Surface      = 20,
                    BasePrix     = 80,
                    ImageUrl     = "https://www.hotel-beaujolais.com/img/build/les-pierres-dorees-chambres.jpg"
                });

                Chambres.Add(new HotelModel.Chambre
                {
                    NombreDeLits = 5,
                    Surface      = 50,
                    BasePrix     = 100,
                    ImageUrl     = "https://assets.hotelaparis.com/uploads/pictures/000/043/953/Chambre-3-6.jpg"
                });

                Chambres.Add(new HotelModel.Chambre
                {
                    NombreDeLits = 2,
                    Surface      = 40,
                    BasePrix     = 60,
                    ImageUrl     = "https://www.hotel-diana-dauphine.com/media/cache/jadro_resize/rc/rhCiPkJe1582096951/jadroRoot/medias/5658345e8f976/chambre-1.jpg"
                });

                SaveChanges();
            }
        }
Example #9
0
        // GET: Agences/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Agences agences = db.Agences.Find(id);

            if (agences == null)
            {
                return(HttpNotFound());
            }
            return(View(agences));
        }
        public async Task <IActionResult> Post([FromBody] AgencesViewModel agences)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Agences _agences = Mapper.Map <Agences>(agences);
                    Villes  villes   = _unitOfWork.Villes.GetSingleOrDefault(e => e.Id == agences.VillesId);
                    _agences.Villes = villes;
                    //_agences.Name = _agences.   ;
                    await _unitOfWork.Agences.AddAsync(_agences);

                    return(Ok(await _unitOfWork.SaveChangesAsync()));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            return(BadRequest());
        }