public async Task <IActionResult> Put(int id, [FromBody] EntrepriseViewModel entreprise) { if (ModelState.IsValid) { try { //Entreprise _entreprise = Mapper.Map<Entreprise>(entreprise); var _entreprise = _unitOfWork.Entreprise.GetSingleOrDefault(e => e.Id == id); _entreprise.Adresse = entreprise.Adresse; _entreprise.email = entreprise.email; _entreprise.FormeJuridique = entreprise.FormeJuridique; _entreprise.Name = entreprise.Name; _entreprise.Tel = entreprise.Tel; _entreprise.titre = entreprise.titre; _entreprise.webSite = entreprise.webSite; // _entreprise.Name="rrtt"; _unitOfWork.Entreprise.Update(_entreprise); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> Post([FromBody] EntrepriseViewModel entreprise) { if (ModelState.IsValid) { try { Entreprise _entreprise = Mapper.Map <Entreprise>(entreprise); await _unitOfWork.Entreprise.AddAsync(_entreprise); return(Ok(await _unitOfWork.SaveChangesAsync())); } catch (Exception ex) { return(BadRequest(ex.Data)); } } return(BadRequest()); }