Example #1
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <News> > PostNews([FromBody] News news)
        {
            _context.News.Add(news);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNewsFromId", new { id = news.NewsId }, news));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Name,Group")] Student student)
        {
            if (ModelState.IsValid)
            {
                // register new user
                var user = new IdentityUser {
                    UserName = student.Name, Email = $"{student.Name}@gmail.com"
                };

                var result = await _userManager.CreateAsync(user, "!1Tempo");

                if (result.Succeeded)
                {
                    // add new student
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    await _userManager.AddClaimAsync(user, new Claim("studentId", student.Id.ToString()));

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError("Name", result.Errors.First().Description);
                }
            }
            return(View(student));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Id,Title,Annotation,TeacherId")] Discipline discipline)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discipline);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TeacherId"] = new SelectList(_context.Teachers, "Id", "Name", discipline.TeacherId);
            return(View(discipline));
        }
Example #6
0
        public async Task <IActionResult> Execute(int customerId, UpdateCustomerModel data)
        {
            var customer = await _db.Set <Customer>().SingleAsync(p => p.Id == customerId);

            customer.Update(name: data.Name);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(int customerId, CreateVersionModel data)
        {
            var customer = await _db.Set <Customer>().SingleAsync(p => p.Id == customerId);

            customer.IncrementVersion(data.Message);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(CreateCustomerModel data)
        {
            var customer = new Customer(data.Name);
            await _db.AddAsync(customer);

            await _db.SaveChangesAsync();

            var result = new CreateCustomerResult {
                Id = customer.Id, Name = customer.Name
            };

            return(Ok(result));
        }
        public async Task <IActionResult> Execute(int customerId, int addressId, CreateAddressModel data)
        {
            var customer = await _db.Set <Customer>().Include(p => p.Addresses).SingleAsync(p => p.Id == customerId);

            customer.UpdateAddress(addressId: addressId,
                                   line: data.Line,
                                   suburb: data.Suburb,
                                   city: data.City,
                                   province: data.Province,
                                   code: data.Code);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(int customerId, CreateAddressModel data)
        {
            var customer = await _db.Set <Customer>().Include(p => p.Addresses).SingleAsync(p => p.Id == customerId);

            var address = customer.AddAddress(
                line: data.Line,
                suburb: data.Suburb,
                city: data.City,
                province: data.Province,
                code: data.Code);
            await _db.SaveChangesAsync();

            var result = new CreateAddressResult {
                Id = address.Id
            };

            return(Ok(result));
        }
Example #11
0
        public async Task InsertAsync(T obj)
        {
            await _context.Set <T>().AddAsync(obj);

            await _context.SaveChangesAsync();
        }
        /// <summary>
        /// Saves a new domain data from the form into the connected database
        /// </summary>
        public async Task CreateDomainAsync(Domain domain)
        {
            await _context.Domain.AddAsync(domain);

            await _context.SaveChangesAsync();
        }