Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Position position)
        {
            if (ModelState.IsValid)
            {
                _context.Add(position);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,IdMaterial,UpdateAt,Price")] PriceMaterial priceMaterial)
        {
            if (ModelState.IsValid)
            {
                _context.Add(priceMaterial);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdMaterial"] = new SelectList(_context.Materials, "Id", "Id", priceMaterial.IdMaterial);
            return(View(priceMaterial));
        }
        public async Task <IActionResult> Create(CarModel carModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carModel);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");
                return(RedirectToAction(nameof(Index)));
            }
            return(View(carModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Phone,Email,Address,Description")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
        public async Task <IActionResult> Edit(int?id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //-------------------------------------------
                    if (employee.ImageFile != null)
                    {
                        string wwwRootPath = _hostEnvironment.WebRootPath;
                        string fileName    = Path.GetFileNameWithoutExtension(employee.ImageFile.FileName);
                        string extension   = Path.GetExtension(employee.ImageFile.FileName);
                        fileName       = fileName + extension;
                        employee.Image = "../assets/img/" + fileName;
                        var checkFile = Path.Combine(wwwRootPath + "/assets/img/", employee.ImageFile.FileName);
                        //Save image to wwwroot/image
                        if (!System.IO.File.Exists(checkFile))
                        {
                            string path = Path.Combine(wwwRootPath + "/assets/img/", fileName);
                            using (var fileStream = new FileStream(path, FileMode.Create))
                            {
                                await employee.ImageFile.CopyToAsync(fileStream);
                            }
                        }
                    }
                    //-------------------------------------------

                    _context.Update(employee);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <IActionResult> Create(TypeOfSupply typeOfSupply)
        {
            if (ModelState.IsValid)
            {
                typeOfSupply.CreateAt = DateTime.Now;
                _context.Add(typeOfSupply);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");
                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeOfSupply));
        }
Exemple #7
0
        public async Task <IActionResult> Create(Account account)
        {
            if (ModelState.IsValid)
            {
                account.Password = "******"; // default pass: 12345678
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdEmployee"] = new SelectList(_context.Employees, "Id", "Id", account.IdEmployee);
            return(View(account));
        }
        public async Task <IActionResult> Create(Work work)
        {
            if (ModelState.IsValid)
            {
                _context.Add(work);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdService"] = new SelectList(_context.Services, "Id", "Name");
            return(View(work));
        }
        public async Task <IActionResult> Create(GoodsDeliveryNote goodsDeliveryNote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(goodsDeliveryNote);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Yêu cầu vật tư thành công");

                return(RedirectToAction("Details", "Repairs", new { id = goodsDeliveryNote.IdRepair }));
            }
            ViewData["IdRepair"] = new SelectList(_context.Repairs, "Id", "Id", goodsDeliveryNote.IdRepair);
            return(View(goodsDeliveryNote));
        }
        public async Task <IActionResult> Create(GoodsReceivedNote goodsReceivedNote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(goodsReceivedNote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var supplier = _context.Suppliers.Select(i => i.Name).ToList();

            ViewData["IdSupplier"] = new SelectList(_context.Suppliers, "Id", "Name", supplier);
            return(View(goodsReceivedNote));
        }
        public async Task <IActionResult> Create(DetailGoodsReceivedNote detailGoodsReceivedNote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(detailGoodsReceivedNote);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                return(RedirectToAction(nameof(Index), new { id = detailGoodsReceivedNote.IdGoodsReceivedNote }));
            }
            ViewData["IdGoodsReceivedNote"] = new SelectList(_context.GoodsReceivedNotes, "Id", "Id", detailGoodsReceivedNote.IdGoodsReceivedNote);
            ViewData["MaterialName"]        = new SelectList(_context.Materials, "Id", "Name");
            return(View(detailGoodsReceivedNote));
        }
        public async Task <IActionResult> Create(DetailRepair detailRepair)
        {
            if (ModelState.IsValid)
            {
                _context.Add(detailRepair);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm công việc thành công");

                return(RedirectToAction("Details", "Repairs", new { id = detailRepair.IdRepair }));
            }
            var workList = _context.Works.Where(w => !_context.DetailRepairs.Any(dr => dr.IdRepair == detailRepair.IdRepair && dr.IdWork == w.Id)).ToList();

            ViewData["IdWork"] = new SelectList(workList, "Id", "WorkName");
            return(View(detailRepair));
        }
        public async Task <IActionResult> Create(DetailGoodsDeliveryNote detailGoodsDeliveryNote)
        {
            if (ModelState.IsValid)
            {
                detailGoodsDeliveryNote.Price = _context.PriceMaterials.Where(m => m.IdMaterial == detailGoodsDeliveryNote.IdMaterial).OrderByDescending(m => m.UpdateAt).FirstOrDefault().Price;
                _context.Add(detailGoodsDeliveryNote);
                await _context.SaveChangesAsync();

                var idRepair = _context.GoodsDeliveryNotes.Include(a => a.IdRepairNavigation).Where(a => a.Id == detailGoodsDeliveryNote.IdGoodsDeliveryNote).FirstOrDefault().IdRepair;
                HttpContext.Session.SetString("SuccessMessage", "Thêm vật tư thành công");

                return(RedirectToAction("Details", "Repairs", new { id = idRepair }));
            }
            ViewData["IdGoodsDeliveryNote"] = new SelectList(_context.GoodsDeliveryNotes, "Id", "Id", detailGoodsDeliveryNote.IdGoodsDeliveryNote);
            ViewData["MaterialName"]        = new SelectList(_context.Materials, "Id", "Name");
            return(View(detailGoodsDeliveryNote));
        }
Exemple #14
0
        public async Task <IActionResult> Create(Material material)
        {
            var type = _context.TypeOfSupplies.Select(i => i.Name).ToList();

            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                if (material.ImageFile != null)
                {
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(material.ImageFile.FileName);
                    string extension   = Path.GetExtension(material.ImageFile.FileName);
                    fileName       = fileName + extension;
                    material.Image = "../assets/img/" + fileName;
                    var checkFile = Path.Combine(wwwRootPath + "/assets/img/", material.ImageFile.FileName);
                    //Save image to wwwroot/image
                    if (!System.IO.File.Exists(checkFile))
                    {
                        string path = Path.Combine(wwwRootPath + "/assets/img/", fileName);
                        using (var fileStream = new FileStream(path, FileMode.Create))
                        {
                            await material.ImageFile.CopyToAsync(fileStream);
                        }
                    }
                }

                material.CreateAt = DateTime.Now;
                _context.Add(material);
                PriceMaterial priceMaterial = new PriceMaterial();
                await _context.SaveChangesAsync();

                priceMaterial.IdMaterial = material.Id;
                priceMaterial.UpdateAt   = DateTime.Now;
                priceMaterial.Price      = material.Price;
                _context.Add(priceMaterial);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                //History
                History history = new History();
                history.DateHistory = DateTime.Now;
                history.UserName    = HttpContext.Session.GetString("SessionUserName");
                history.Event       = "Thêm vật tư " + material.Name;
                _context.Add(history);
                await _context.SaveChangesAsync();

                //============================

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TypeName"] = new SelectList(_context.TypeOfSupplies, "Id", "Name", type);
            return(View(material));
        }
        public async Task <IActionResult> Create(Pay pay)
        {
            if (ModelState.IsValid)
            {
                int?workCost     = 0;
                var workCostData = await _context.DetailRepairs.Include(r => r.IdWorkNavigation).Where(r => r.IdRepair == pay.IdRepair).ToListAsync();

                if (workCostData.Any())
                {
                    foreach (var item in workCostData)
                    {
                        workCost += item.IdWorkNavigation.Cost * item.Amount;
                    }
                }
                int?materialCost     = 0;
                var materialCostData = await _context.GoodsDeliveryNotes.Include(r => r.DetailGoodsDeliveryNotes).Where(r => r.IdRepair == pay.IdRepair).FirstOrDefaultAsync();

                if (materialCostData != null)
                {
                    foreach (var item in materialCostData.DetailGoodsDeliveryNotes)
                    {
                        materialCost += item.Price * item.Amount;
                    }
                }
                pay.Total = ((workCost + materialCost) + ((workCost + materialCost) * 10) / 100);

                _context.Add(pay);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới biên lai thành công");

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdRepair"] = new SelectList(_context.Repairs, "Id", "Id", pay.IdRepair);
            return(View(pay));
        }
Exemple #16
0
        public async Task <IActionResult> Create(Car car)
        {
            if (ModelState.IsValid)
            {
                //-------------------------------------------
                if (car.ImageFile != null)
                {
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(car.ImageFile.FileName);
                    string extension   = Path.GetExtension(car.ImageFile.FileName);
                    fileName  = fileName + extension;
                    car.Image = "../assets/img/" + fileName;
                    var checkFile = Path.Combine(wwwRootPath + "/assets/img/", car.ImageFile.FileName);
                    //Save image to wwwroot/image
                    if (!System.IO.File.Exists(checkFile))
                    {
                        string path = Path.Combine(wwwRootPath + "/assets/img/", fileName);
                        using (var fileStream = new FileStream(path, FileMode.Create))
                        {
                            await car.ImageFile.CopyToAsync(fileStream);
                        }
                    }
                }
                //-------------------------------------------

                _context.Add(car);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                //History
                History history = new History();
                history.DateHistory = DateTime.Now;
                history.UserName    = HttpContext.Session.GetString("SessionUserName");
                var infoCar = _context.Cars.Include(c => c.IdCustomerNavigation).Where(c => c.IdCustomer == car.IdCustomer).FirstOrDefault();
                history.Event = "Thêm xe của khách hàng" + infoCar.IdCustomerNavigation.Name;
                _context.Add(history);
                await _context.SaveChangesAsync();

                //============================

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

            ViewData["Customer"] = new SelectList(_context.Customers, "Id", "Id", car.IdCustomer);
            return(View(car));
        }
Exemple #17
0
        public async Task <IActionResult> Create(Employee employee)
        {
            //-------------------------------------------
            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                if (employee.ImageFile != null)
                {
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(employee.ImageFile.FileName);
                    string extension   = Path.GetExtension(employee.ImageFile.FileName);
                    fileName       = fileName + extension;
                    employee.Image = "../assets/img/" + fileName;
                    var checkFile = Path.Combine(wwwRootPath + "/assets/img/", employee.ImageFile.FileName);
                    //Save image to wwwroot/image
                    if (!System.IO.File.Exists(checkFile))
                    {
                        string path = Path.Combine(wwwRootPath + "/assets/img/", fileName);
                        using (var fileStream = new FileStream(path, FileMode.Create))
                        {
                            await employee.ImageFile.CopyToAsync(fileStream);
                        }
                    }
                }
                //-------------------------------------------
                _context.Add(employee);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                //History
                History history = new History();
                history.DateHistory = DateTime.Now;
                history.UserName    = HttpContext.Session.GetString("SessionUserName");
                history.Event       = "Thêm nhân viên " + employee.Name;
                _context.Add(history);
                await _context.SaveChangesAsync();

                //============================

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemple #18
0
        public async Task <IActionResult> Create(Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                //History
                History history = new History();
                history.DateHistory = DateTime.Now;
                history.UserName    = HttpContext.Session.GetString("SessionUserName");
                history.Event       = "Thêm khách hàng " + customer.Name;
                _context.Add(history);
                await _context.SaveChangesAsync();

                //============================
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemple #19
0
        public async Task <IActionResult> Create([Bind("Id,IdCar,DateOfFactoryEntry,DateFinished,State")] Repair repair)
        {
            if (ModelState.IsValid)
            {
                _context.Add(repair);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");

                //History
                History history = new History();
                history.DateHistory = DateTime.Now;
                history.UserName    = HttpContext.Session.GetString("SessionUserName");
                history.Event       = "Nhập xưởng xe của khách hàng " + _context.Cars.Include(c => c.IdCustomerNavigation).Where(c => c.Id == repair.IdCar).Select(c => c.IdCustomerNavigation.Name).FirstOrDefault();
                _context.Add(history);
                await _context.SaveChangesAsync();

                //============================

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdCar"] = new SelectList(_context.Cars, "Id", "Id", repair.IdCar);
            return(View(repair));
        }