public async Task <IActionResult> Post([FromBody] DepartementsViewModel departements) { if (ModelState.IsValid) { try { Departements _departements = Mapper.Map <Departements>(departements); //_departements.Name = _departements.Name.ToUpper(); // _unitOfWork.Departements.Add(_departements); _unitOfWork.BudjetDepartement.Add(new BudjetDepartement { Annees = DateTime.Now, LigneCapex = departements.BudjetCapex, LigneOpex = departements.BudjetOpex, DepartementsId = _departements.Id, Departements = _departements }); 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] DepartementsViewModel departements) { if (ModelState.IsValid) { try { Departements _departements = Mapper.Map <Departements>(departements); BudjetDepartement _Bd = getBudejetByDepId(_departements.Id); if (_Bd != null) { _unitOfWork.BudjetDepartement.Update(_Bd); } else { _unitOfWork.BudjetDepartement.Add(new BudjetDepartement { LigneCapex = departements.BudjetCapex, LigneOpex = departements.BudjetOpex, Departements = _departements, Annees = DateTime.Now }); } _unitOfWork.Departements.Update(_departements); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }