Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Departements _departements = _unitOfWork.Departements.GetSingleOrDefault(e => e.Id == id);
                    if (_departements != null)
                    {
                        _unitOfWork.Departements.Remove(_departements);


                        BudjetDepartement _Bd = getBudejetByDepId(id);
                        if (_Bd != null)
                        {
                            _unitOfWork.BudjetDepartement.Remove(_Bd);
                        }

                        await _unitOfWork.SaveChangesAsync();

                        return(Ok("OK"));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        private BudjetDepartement getBudejetByDepId(int Id)
        {
            BudjetDepartement bd = _unitOfWork.BudjetDepartement.GetSingleOrDefault(e => e.DepartementsId == Id && e.Annees.Year == DateTime.Now.Year);

            return(bd);
        }