public async Task <IActionResult> Create([Bind("IdWorker,IdPosition,FullName,PhoneNumber,Address,Rate,DateOfBirth,PathWorkerImg")] Worker worker, IFormFile uploadedFile)
        {
            if (ModelState.IsValid && uploadedFile != null)
            {
                _context.Add(worker);

                //збереження зображення
                // путь к папке Files
                string path = $"/Files/WorkerImg/{worker.IdWorker}_{uploadedFile.FileName}";
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }

                worker.PathWorkerImg = path;
                await _context.SaveChangesAsync();

                //
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdPosition"] = new SelectList(_context.Positions, "IdPosition", "Name", worker.IdPosition);
            return(View(worker));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("IdCar,Name,Owner,IdClient,IdTypeOfCar,PathCarImg")] Car car, IFormFile uploadedFile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                //збереження зображення
                // путь к папке Files
                string path = $"/Files/CarImg/{car.IdCar}_{uploadedFile.FileName}";
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }

                car.PathCarImg = path;
                await _context.SaveChangesAsync();

                //
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdClient"]    = new SelectList(_context.Clients, "IdClient", "FullName", car.IdClient);
            ViewData["IdTypeOfCar"] = new SelectList(_context.TypeOfCars, "IdTypeOfCar", "TypeOfCar1", car.IdTypeOfCar);
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("IdClient,FullName,PhoneNumber")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
        public async Task <IActionResult> Create([Bind("IdTypeOfCar,TypeOfCar1")] TypeOfCar typeOfCar)
        {
            if (ModelState.IsValid)
            {
                _context.Add(typeOfCar);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeOfCar));
        }
        public async Task <IActionResult> Create([Bind("IdPosition,Name")] Position position)
        {
            if (ModelState.IsValid)
            {
                _context.Add(position);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
        public async Task <IActionResult> Create([Bind("IdService,ServiceName,Price")] Service service)
        {
            if (ModelState.IsValid)
            {
                _context.Add(service);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(service));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("IdOrder,Date,IdClient,IdCar,Price")] Order order, int[] idMaterials, int[] idWorkers, int[] idServices)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                //
                foreach (var n in idMaterials)
                {
                    order.MaterialsOrders.Add(new MaterialsOrder
                    {
                        IdOrderNavigation     = order,
                        IdMaterialsNavigation = _context.Materials.FirstOrDefault(p => p.IdMaterials == n)
                    });
                }

                foreach (var n in idWorkers)
                {
                    order.OrderWorkers.Add(new OrderWorker
                    {
                        IdOrderNavigation  = order,
                        IdWorkerNavigation = _context.Workers.FirstOrDefault(p => p.IdWorker == n)
                    });
                }

                foreach (var n in idServices)
                {
                    order.ServiceOrders.Add(new ServiceOrder
                    {
                        IdOrderNavigation   = order,
                        IdServiceNavigation = _context.Services.FirstOrDefault(p => p.IdService == n)
                    });
                }
                //
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //
            //
            ViewData["Materials"] = _context.Materials.ToList();
            ViewData["Workers"]   = _context.Workers.ToList();
            ViewData["Services"]  = _context.Services.ToList();
            //
            //
            ViewData["IdCar"]    = new SelectList(_context.Cars, "IdCar", "Name", order.IdCar);
            ViewData["IdClient"] = new SelectList(_context.Clients, "IdClient", "FullName", order.IdClient);
            return(View(order));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("IdMaterials,NameMaterial,Price,PathMaterialsImg")] Material material, IFormFile uploadedFile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(material);
                await _context.SaveChangesAsync();

                //збереження зображення
                // путь к папке Files
                string path = $"/Files/MaterialImg/{material.IdMaterials}_{uploadedFile.FileName}";
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }

                material.PathMaterialsImg = path;
                await _context.SaveChangesAsync();

                //
                return(RedirectToAction(nameof(Index)));
            }
            return(View(material));
        }