public async Task <IActionResult> PutDepartment(int id, Department department)
        {
            if (id != department.DbID)
            {
                return(BadRequest());
            }

            _context.Entry(department).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployees(string id, Employees employees)
        {
            if (id != employees.ID)
            {
                return(BadRequest());
            }

            _context.Entry(employees).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IHttpActionResult> UpdateEvento([FromUri] Guid IdEvento, [FromBody] EventoDtoInput Evento)
        {
            //Controllo che i parametri siano valorizzati
            if (Evento == null || !ModelState.IsValid || (IdEvento == null || IdEvento == Guid.Empty))
            {
                return(BadRequest(ModelState));
            }

            //Cerco l'evento
            Evento evento = await dbDataContext.Evento.Include(x => x.ImmagineEvento).Where(x => x.Id == IdEvento).FirstAsync();

            if (evento == null)
            {
                return(NotFound());
            }

            //Modifico l'evento
            evento.Titolo       = Evento.Titolo;
            evento.Descrizione  = Evento.Descrizione;
            evento.DataModifica = DateTime.Now;
            evento.DataEvento   = Evento.DataEvento;
            evento.Cancellato   = Evento.Cancellato;
            //L'immagine esiste sempre
            evento.ImmagineEvento.Immagine = Evento.ImmagineEvento;

            try
            {
                //Salvo le modifiche sul DB.
                await dbDataContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventoExists(evento.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            //return StatusCode(HttpStatusCode.NoContent);
            return(Ok(EventoMapper.EventoToEventoDto(evento)));
            //CreatedAtRoute("UpdateEvento", new { id = evento.Id }, evento);
        }