Пример #1
0
        public async Task <IActionResult> Create(Product product)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!ProductExists(product.Name))
                    {
                        _context.Add(product);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.Message = ("Name already exists.");
                        return(View(product));
                    }
                }
                return(View(product));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
Пример #2
0
 public async Task InsertAsync(Offer obj)
 {
     _context.Add(obj);
     await _context.SaveChangesAsync();
 }