Esempio n. 1
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.productid)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.userid)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutHistoryEvent(int id, HistoryEvent historyEvent)
        {
            if (id != historyEvent.hisevid)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <outputSignUp> PutUser(int id, User user)
        {
            outputSignUp output = new outputSignUp();

            //if (id != user.userid)
            //{
            //    return BadRequest();
            //}

            //_context.Entry(user).State = EntityState.Modified;

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

            try
            {
                _context.Entry(user).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                if (user.userid != 0)
                {
                    //result = user;

                    output.Result  = "OK";
                    output.users   = user;
                    output.Message = "Success";
                }
                else
                {
                    output.Result  = "NG";
                    output.Message = "Fail";
                }
            }
            catch (Exception ex)
            {
                output.Result  = "NG";
                output.Message = ex.ToString();
            }

            return(output);
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("bannerid,image")] Banner banner, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                string filename = ContentDispositionHeaderValue.Parse(image.ContentDisposition).FileName.Trim('"');
                var    path     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", image.FileName);
                using (System.IO.Stream stream = new FileStream(path, FileMode.Create))
                {
                    await image.CopyToAsync(stream);
                }
                banner.image = filename;
                _context.Add(banner);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(banner));
        }