コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,DisplayName,IsVisible,ItemOrder,Title,Description,AnchorText,AnchorUrl,ImageUrl")] ContentManagement contentManagement, IFormCollection formCollection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (formCollection?.Files?.Count > 0)
                    {
                        FileInfo fi          = new FileInfo(formCollection.Files[0].FileName);
                        var      newFilename = "P" + contentManagement.Id + "_" + string.Format("{0:d}",
                                                                                                (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                        var webPath    = _hostingEnvironment.WebRootPath;
                        var path       = Path.Combine("", webPath + @"\uploads\images\ContentManagement\" + newFilename);
                        var pathToSave = @"/uploads/images/ContentManagement/" + newFilename;
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            formCollection.Files[0].CopyTo(stream);
                        }
                        contentManagement.ImageUrl = pathToSave;
                    }
                    _context.Add(contentManagement);
                    await _context.SaveChangesAsync();

                    Message = Toast.SucsessToast();
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(contentManagement));
            }
            catch (Exception e)
            {
                Message = Toast.ErrorToast(GetExceptionMessage(e));
                return(View(contentManagement));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Name,DisplayName,Id,Created,Modified,IsDeleted,ItemOrder")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contact));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("PaymentPackageId,FeatureId,Value,Unit,Id,Created,Modified,IsDeleted,ItemOrder")] PaymentPackageFeature paymentPackageFeature)
        {
            if (ModelState.IsValid)
            {
                _context.Add(paymentPackageFeature);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FeatureId"]        = new SelectList(_context.Feature, "Id", "Name", paymentPackageFeature.FeatureId);
            ViewData["PaymentPackageId"] = new SelectList(_context.PaymentPackage, "Id", "DisplayName", paymentPackageFeature.PaymentPackageId);
            return(View(paymentPackageFeature));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("FuelSupplierId,ContactId,Value,Id,Created,Modified,IsDeleted,ItemOrder")] SupplierContact supplierContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplierContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ContactId"]      = new SelectList(_context.Contact, "Id", "DisplayName", supplierContact.ContactId);
            ViewData["FuelSupplierId"] = new SelectList(_context.FuelSupplier, "Id", "Name", supplierContact.FuelSupplierId);
            return(View(supplierContact));
        }