public async Task <IActionResult> Edit(string id, [Bind("DddlMa,DddlTen")] Diadiemdulich diadiemdulich)
        {
            if (id != diadiemdulich.DddlMa)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(diadiemdulich);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiadiemdulichExists(diadiemdulich.DddlMa))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(diadiemdulich));
        }
        public async Task <IActionResult> Create([Bind("DddlMa,DddlTen")] Diadiemdulich diadiemdulich)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diadiemdulich);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(diadiemdulich));
        }
Example #3
0
        public void AddLocation(LocationCommand locationCommand)
        {
            //var newStaff = new Nguoidung();
            var newLocation = new Diadiemdulich();

            {
                newLocation.Tendiadiem = locationCommand.Tendiadiem;
                newLocation.Mota       = locationCommand.Mota;
                newLocation.MienID     = locationCommand.MienID;
            }
            _db.Diadiemduliches.Add(newLocation);
            _db.SaveChanges();
        }
Example #4
0
        public IActionResult InsertTour(InsertTourCommand tourCommand, Diadiemdulich diadiem, Mien mien)
        {
            List <Diadiemdulich> listDiadiem = new List <Models.db.Diadiemdulich>();

            listDiadiem = (from t in _db.Diadiemduliches
                           //where t.MienID == SelectedValue2
                           select t).ToList();
            ViewBag.ListDiaDiem = listDiadiem;
            List <Mien> listMien = new List <Models.db.Mien>();

            listMien         = (from t in _db.Miens select t).ToList();
            ViewBag.ListMien = listMien;
            string getNameLichTrinh = null;
            string getNamePicture   = null;

            if (ModelState.IsValid)
            {
                if (tourCommand != null)
                {
                    getNameLichTrinh = Path.GetFileName(tourCommand.Lichtrinh.FileName);
                    var uploadFolderLT       = Path.Combine(this._hostingEnvironment.WebRootPath, "docs/lichtrinh");
                    var getLichtrinhToFolder = Path.Combine(uploadFolderLT, getNameLichTrinh);
                    getNamePicture = Path.GetFileName(tourCommand.Hinhanh.FileName);
                    var uploadFolder       = Path.Combine(this._hostingEnvironment.WebRootPath, "images/tour_images");
                    var getPictureToFolder = Path.Combine(uploadFolder, getNamePicture);
                    if (System.IO.File.Exists(getPictureToFolder))
                    {
                        ViewBag.Picture = "Hinh anh da ton tai";
                        return(View());
                    }
                    else
                    {
                        var filestream2 = new FileStream(getLichtrinhToFolder, FileMode.Create);
                        tourCommand.Lichtrinh.CopyTo(filestream2);
                        var filestream = new FileStream(getPictureToFolder, FileMode.Create);
                        tourCommand.Hinhanh.CopyTo(filestream);
                        var newTour = new Tour();
                        {
                            //newTour.ID = _db.Tours.Count() + 1;
                            newTour.Tentour         = tourCommand.Tentour;
                            newTour.Code            = tourCommand.Code;
                            newTour.Diadiemkhoihanh = tourCommand.Diadiemkhoihanh;
                            newTour.Diemden         = tourCommand.Diemden;
                            newTour.Ngaydi          = tourCommand.Ngaydi;
                            newTour.Thuocmien       = tourCommand.Thuocmien;
                            if (tourCommand.Loaitour == "Trong nước")
                            {
                                newTour.Loaitour = "Trong nước";
                            }
                            else
                            {
                                newTour.Loaitour = "Nước ngoài";
                            }
                            newTour.Thoigiandi  = tourCommand.Thoigiandi;
                            newTour.Lichtrinh   = getNameLichTrinh;
                            newTour.Gianguoilon = tourCommand.Gianguoilon;
                            newTour.Hinhanh     = getNamePicture /*+ DateTime.Now.ToString()*/;
                            newTour.Mota        = tourCommand.Mota;
                            newTour.Songuoi     = tourCommand.Songuoi;
                            //newTour.Loaitour = tourCommand.Loaitour;
                            newTour.TenHDV    = tourCommand.TenHDV;
                            newTour.Trangthai = "Còn chỗ";
                            //foreach (var selectedId in tourCommand.MultiDiaDiem)
                            //{
                            //    _db.DiadiemTours.Add(new DiadiemTour
                            //    {
                            //        TourID = newTour.ID,
                            //        DiadiemdulichID = selectedId,
                            //    });
                            //}
                            //_db.SaveChanges();
                        }
                        _db.Tours.Add(newTour);
                        _db.SaveChanges();
                        RedirectToAction("Index", "Admin");
                    }
                }
            }
            return(View());
        }