Ejemplo n.º 1
0
        public async Task <IActionResult> Put(int id, [FromBody] FacturesViewModel factures)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Factures        _factures = Mapper.Map <Factures>(factures);
                    Demandes        dmd       = _unitOfWork.Demandes.GetSingleOrDefault(e => e.Id == factures.DemandesId);
                    ComptesInternes ci        = _unitOfWork.ComptesInternes.GetSingleOrDefault(e => e.Id == factures.ComptesInternesId);
                    _factures.ComptesInternes = ci;
                    _factures.Demandes        = dmd;

                    //_factures.Name = _factures.Name.ToUpper ();
                    _unitOfWork.Factures.Update(_factures);

                    await _unitOfWork.SaveChangesAsync();

                    return(Ok("OK"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Data));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] FacturesViewModel factures)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Factures _factures = Mapper.Map <Factures>(factures);

                    //_factures.Name = _factures.Name.ToUpper ();
                    await _unitOfWork.Factures.AddAsync(_factures);

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