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

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

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("EmployeeId,Name,Position,Age,Salatry")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,MobileNo")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("id,name")] MakeModel makeModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(makeModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(makeModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("id,model,year,cylinders,MakeId")] CarModel carModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MakeId"] = new SelectList(_context.Make, "id", "Name", carModel.MakeId);
            return(View(carModel));
        }
Exemplo n.º 6
0
        public async Task <int> AddCourse(Courses course)
        {
            if (db != null)
            {
                await db.Courses.AddAsync(course);

                await db.SaveChangesAsync();

                return(course.CId);
            }

            return(0);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,StoreId,CustomerId,DateSold")] Sale sale)
        {
            if (id != sale.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sale);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SaleExists(sale.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Address", sale.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Product, "Id", "Name", sale.ProductId);
            ViewData["StoreId"]    = new SelectList(_context.Store, "Id", "Address", sale.StoreId);
            return(View(sale));
        }