Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Employee employee)
        {
            if (id != employee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <T> Update(T entity)
        {
            _context.Update <T>(entity);
            await _context.SaveChangesAsync();

            return(Get(entity.ID));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StartDate,FinishDate,Priority,ManagerId,CustomerId,PerformerId")] Project project)
        {
            if (id != project.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try {
                    _context.Update(project);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException) {
                    if (!ProjectExists(project.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            var companies = _context.Companies.ToList();
            var employees = _context.Employees.ToList();

            ViewData["CustomerId"]  = new SelectList(companies, "Id", "Name", project.CustomerId);
            ViewData["PerformerId"] = new SelectList(companies, "Id", "Name", project.PerformerId);
            ViewData["ManagerId"]   = new SelectList(employees, "Id", "Surname", project.ManagerId);
            return(View(project));
        }
Esempio n. 4
0
        public IActionResult Put(int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = _context.Categories.Find(id);

            if (item == null)
            {
                return(NotFound());
            }
            _context.Update <Category>(category);

            return(CreatedAtAction(nameof(GetById),
                                   new { id = category.ID }, category));
        }
Esempio n. 5
0
        public IActionResult Put(int id, [FromBody] Property property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = _context.Properties.Find(id);

            if (item == null)
            {
                return(NotFound());
            }
            _context.Update <Property>(property);

            return(CreatedAtAction(nameof(GetById),
                                   new { id = property.ID }, property));
        }
 public int Update(T entity)
 {
     _context.Update(entity);
     return(_context.SaveChanges());
 }