Exemplo n.º 1
0
        public async Task <IActionResult> PutDepartment([FromRoute] int id, [FromBody] Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public static void UpdateSubjectNoTracking()
        {
            Subject s = context.Subject.Include(s => s.Items).Single(s => s.SubjectId == 11);

            s.Items[0].Name = "Izmena 2";
            using (DepartmentsContext newContext = new DepartmentsContext())
            {
                //newContext.Update(s);
                newContext.Attach(s);
                newContext.Entry(s.Items[0]).State = EntityState.Modified;
                newContext.SaveChanges();
            }
        }