示例#1
0
        public async Task <ActionResult> deleteDepartament(CountryDepartametsModel departamentModel)
        {
            try
            {
                var departament = _context.CountryDepartaments.FirstOrDefault(x => x.id == departamentModel.id);
                _context.CountryDepartaments.Remove(departament);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                Console.WriteLine("an error ocurred" + ex.ToString());
                return(BadRequest());
            }
        }
示例#2
0
        public async Task <ActionResult <CountryDepartametsModel> > newDepartament(CountryDepartametsModel departamentModel)
        {
            try
            {
                departamentModel.date_created = DateTime.Now;
                _context.CountryDepartaments.Add(departamentModel);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetModelDepartament", new { id = departamentModel.id }, departamentModel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("an error ocurred" + ex.ToString());
                return(BadRequest(ex));
            }
        }
示例#3
0
        public async Task <ActionResult <CountryModel> > updateDepartament(CountryDepartametsModel departamentModel)
        {
            try
            {
                var departament = _context.CountryDepartaments.FirstOrDefault(x => x.id == departamentModel.id);
                departament.name = departamentModel.name;
                departament.code = departamentModel.code;
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetModelDepartament", new { id = departamentModel.id }, departamentModel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("an error ocurred" + ex.ToString());
                return(BadRequest());
            }
        }