コード例 #1
0
        public async Task <IActionResult> Add([Bind("lineItemID, fileName")] FileAttachment fileAttachment, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (file.Length > 0)
                    {
                        using (var stream = new FileStream(fileAttachment.FileName, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                    }
                    _context.Add(fileAttachment);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Edit", "LineItem"));
                }
                catch (Exception e)
                {
                    _logger.LogError("FileAttachmentsController.Add Error:" + e.GetBaseException());
                    Log.Error("FileAttachmentsController.Add Error:" + e.GetBaseException() + "\n" + e.StackTrace);
                }
            }
            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("CategoryID,CategoryCode,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #3
0
ファイル: FundsController.cs プロジェクト: Csands-Aecom/EPS3
        public async Task <IActionResult> Create([Bind("FundID,FundCode,FundDescription")] Fund fund)
        {
            if (ModelState.IsValid)
            {
                _context.Add(fund);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(fund));
        }
コード例 #4
0
ファイル: UsersController.cs プロジェクト: Csands-Aecom/EPS3
        public async Task <IActionResult> Create([Bind("UserID,FirstName,LastName,UserLogin,Email,Phone,ReceiveEmails")] User user)
        {
            if (ModelState.IsValid)
            {
                //user.ReceiveEmails = 1;
                user.UserLogin = user.UserLogin.ToUpper();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Edit", new { id = user.UserID }));
            }
            return(View(user));
        }
コード例 #5
0
 public async Task <IActionResult> Create([Bind("VendorCode, VendorName")] Vendor vendor, int ContractID)
 {
     if (ModelState.IsValid)
     {
         var oldVendor = _context.Vendors.Where(v => v.VendorCode == vendor.VendorCode);
         // if the vendorcode does not already exist, add the new vendor
         if (oldVendor != null)
         {
             vendor.VendorCode = vendor.VendorCode.ToUpper();
             _context.Add(vendor);
             await _context.SaveChangesAsync();
         }
     }
     return(RedirectToAction("Edit", "Contracts", new { id = ContractID }));
 }