コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Username,Password,DisplayName,Status,Role,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,ProfilePicture")] SystemUser systemUser, IFormFile ProfilePicture)
        {
            if (ModelState.IsValid)
            {
                if (ProfilePicture != null)
                {
                    string     FileName = Guid.NewGuid().ToString() + Path.GetExtension(ProfilePicture.FileName);
                    string     FilePath = _env.WebRootPath + "/SystemData/ProfilePictures/";
                    FileStream FS       = new FileStream(FilePath + FileName, FileMode.Create);
                    ProfilePicture.CopyTo(FS);
                    FS.Close();
                    systemUser.ProfilePicture = "/SystemData/ProfilePictures/" + FileName;
                }

                systemUser.Status      = "Active";
                systemUser.Role        = "staff";
                systemUser.CreatedDate = DateTime.Now;
                systemUser.CreatedBy   = "Self";
                _context.Add(systemUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(systemUser));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Quantity,CostPice,SalePrice,MainImage,ItemCode,Status,ItemCategory,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] SystemItem systemItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(systemItem);
                await _context.SaveChangesAsync();

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