コード例 #1
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Phone,Email,Username,Password,Note,Age,Gender,Address,City,UserType,SubsidiaryTotalProduct,AgentName,SupplyCode,ImageFile,SupplyName,Salary,Id,CreatedDate,ModifiedDate")] User user)
        {
            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                //string wwwRootPath = _hostEnvironment.WebRootPath;
                //string fileName = Path.GetFileNameWithoutExtension(user.ImageFile.FileName);
                //string extension = Path.GetExtension(user.ImageFile.FileName);
                user.Avatar = await _commonServices.CreateImage(user.ImageFile, user.Avatar, "/images/People");

                //Insert record
                user.CreatedDate = user.ModifiedDate = DateTime.Now.ToUniversalTime();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Phone,Email,Note,Age,Gender,Address,City,AgentName,ImageFile,ExpireContractDate")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Avatar = await _commonServices.CreateImage(user.ImageFile, user.Avatar, "/images/People");

                await _userServices.CreateSubsidiaryAgent(user);

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Url,ProductId,Id,CreatedDate,ModifiedDate,ImageFile")] Image image)
        {
            if (ModelState.IsValid)
            {
                var product = _context.Products.Find(image.ProductId);
                image.Url = await _commonServices.CreateImage(image.ImageFile, image.Url, "/images/Products/" + product.Name);

                image.CreatedDate = image.ModifiedDate = DateTime.UtcNow;
                _context.Add(image);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "DisplayName", image.Product.DisplayName);
            return(View(image));
        }
コード例 #4
0
        public async Task CreateProduct(Product product)
        {
            try
            {
                int NewestID = _unitOfWork.Products.getNewId().Equals(null) ? 0 : (int)_unitOfWork.Products.getNewId();
                product.Code      = $"P_{NewestID + 1}";
                product.MainImage = await _commonServices.CreateImage(product.ImageFile, product.MainImage, "/images/Products/" + product.Name);

                product.MFG         = product.MFG.ToUniversalTime();
                product.EXP         = product.EXP.ToUniversalTime();
                product.RecieveDate = product.RecieveDate.ToUniversalTime();
                product.CreatedDate = product.ModifiedDate = DateTime.UtcNow;
                product.IsActive    = true;
                _unitOfWork.Products.Add(product);
                await _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw e;
            }
        }