public IActionResult GetTour(int tourId) { TourDTO tour = _tourService.GetTour(tourId); Log.Information($"Your tour with id: {tourId}"); return(Ok(tour)); }
private void btAdd_Click(object sender, EventArgs e) { TourDTO tourDTO = new TourDTO(); tourDTO.ID = tbID.Text; tourDTO.Ten = tbName.Text; tourDTO.DacDiem = tbCharacteristic.Text; tourDTO.GiaTour = Double.Parse(tbMoney.Text); tourDTO.IDLoaiHinh = cbType.SelectedValue.ToString(); Result result = tourBUS.Insert(tourDTO); if (result.Flag) { MessageBox.Show("Thêm tour mới thành công", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetField(); } else { MessageBox.Show("Thêm tour mới thất bại\n Error: " + result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btUpdate_Click(object sender, EventArgs e) { int currentRow = dgvTour.CurrentCellAddress.Y; if (-1 < currentRow && currentRow < dgvTour.RowCount) { TourDTO tourDTO = new TourDTO(); tourDTO.ID = tbID.Text; tourDTO.Ten = tbName.Text; tourDTO.DacDiem = tbDacDiem.Text; tourDTO.GiaTour = Double.Parse(tbMoney.Text); tourDTO.IDLoaiHinh = cbLoaiHinh.SelectedValue.ToString(); Result result = tourBUS.Update(tourDTO); if (result.Flag) { MessageBox.Show("Cập nhật tour thành công", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Cập nhật tour thất bại\n Error: " + result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task AddTourAsync(TourDTO tourDTO) { var tour = mapper.Map <TourDTO, Tour>(tourDTO); await dataBase.Tours.AddAsync(tour); await dataBase.CompleteAsync(); }
public bool Update(TourDTO tour) { var tourEntity = _tourRepository.First(x => x.Id == tour.Id); if (tourEntity != null) { tourEntity.OverView = tour.OverView; tourEntity.TourActivity = tour.TourActivity; tourEntity.TourCode = tour.TourCode; tourEntity.TourMap = tour.TourMap; tourEntity.TourName = tour.TourName; tourEntity.TourSpot = tour.TourSpot; tourEntity.TourType = tour.TourType; tourEntity.TourImage = tour.TourImage; tourEntity.TourSliderImage = tour.TourSliderImage; tourEntity.SEOTitle = tour.SEOTitle; tourEntity.SEODescription = tour.SEODescription; tourEntity.TourMapDesc = tour.TourMapDesc; tourEntity.TourMapImage = tour.TourMapImage; tourEntity.TourMorning = tour.TourMorning; tourEntity.TourLunch = tour.TourLunch; tourEntity.TourAfternoon = tour.TourAfternoon; tourEntity.Notes = tour.Notes; tourEntity.TourUrl = ConstHelper.UrlFriendly(tour.TourName); return(_tourRepository.Update(tourEntity)); } else { return(false); } }
public void CreateTour(TourDTO tourDTO) { var tour = MappingDTO.MapTour(tourDTO); _dataBase.Tours.Create(tour); _dataBase.Save(); }
public async Task <IActionResult> CreateTour(TourDTO tourDto) { var tour = _mapper.Map <TourDTO, Tour>(tourDto); await _repository.Add(tour); return(CreatedAtAction(nameof(GetTour), new { id = tour.TourId }, tour)); }
public void UpdateTour(TourDTO tourDTO) { var tour = MappingDTO.MapTour(tourDTO); _dataBase.Tours.UpdateInfo(tour); _dataBase.Save(); }
/////// Sửa thành viên public bool suaTour(TourDTO l) { try { _conn.Open(); string SQL = string.Format("UPDATE TOUR SET TENTOUR = '{0}', MALOAI = '{1}' WHERE MATOUR = '{2}'", l.Ten1, l.MaTheLoai1, l.MaTour1); SqlCommand cmd = new SqlCommand(SQL, _conn); if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { // Dong ket noi _conn.Close(); } return(false); }
public async Task <UserDTO> GetGuideByTourId(int tourId) { TourDTO tourDTO = Mapper.Map <TourDTO>(Database.TourManager.Get(tourId)); if (tourDTO == null) { throw new ValidationException("There is no information about this tour", $"{tourId}"); } ApplicationUser user = await Database.UserManager.FindByIdAsync(tourDTO.UserId); if (user == null) { throw new ValidationException($"There is no information about this user {user.Id} in tour", ""); } UserProfile profile = user.User.UserProfile; return(new UserDTO { FullName = profile.FullName, Age = profile.Age, Birthday = profile.Birthday, Email = profile.Email, Address = profile.Address, Phone = profile.Phone, ImageUrl = profile.ImageUrl, Id = user.Id, UserName = user.UserName }); }
public ActionResult Create(TourViewModel tourViewModel) { try { if (ModelState.IsValid) { TourDTO newTour = new TourDTO() { Country = tourViewModel.Country, Region = tourViewModel.Region, StartDate = tourViewModel.StartDate, EndDate = tourViewModel.EndDate, Hotel = tourViewModel.Hotel }; tourService.CreateTour(newTour); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name after DataException and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(tourViewModel)); }
public void Update(TourDTO entity) { var tour = _uow.Tours.Get(entity.Id); if (tour != null) { //TODO: use AutoMapper here? tour.Title = entity.Title; tour.Description = entity.Description; tour.Price = entity.Price; tour.PeopleNumber = entity.PeopleNumber; tour.IsHot = entity.IsHot; tour.IsAvailable = entity.IsAvailable; tour.TourType = entity.TourType; tour.HotelType = entity.HotelType; tour.TransferType = entity.TransferType; if (entity.ImageName != null) { tour.ImageName = entity.ImageName; } Log(string.Format("Updating tour info [Id:{0}].", tour.Id )); } else { throw new ValidationException("Tour does not exist", string.Empty); } }
public async Task <ActionResult <int> > Add([FromBody] TourDTO tour) { tour.TourId = 0; var id = await _toursService.CreateTourAsync(tour); return(Created($"{Request.Path.Value}/{id}", id)); }
public static TourDTO getTour(string id) { TourDTO T = null; using (SqlConnection conn = new SqlConnection(Data.connectionString)) { conn.Open(); string sql = @"Select * from Tour where ID='" + id + "'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { T = new TourDTO() { Id = (string)reader["ID"], Name = (string)reader["Name"], Price = (int)reader["Price"], Region = (string)reader["Region"], MinPax = (int)reader["MinPax"], MaxPax = (int)reader["MaxPax"], NumOfPassengers = (int)reader["NumOfPassengers"], NumOfDays = (int)reader["NumOfDays"], DepartureDate = (DateTime)reader["DepartureDate"], ArrivalDate = (DateTime)reader["ArrivalDate"], Status = (string)reader["Status"] }; } } return(T); }
public void AddTour(TourDTO NewTour) { if (UserLogic.CurrentUser == null || UserLogic.CurrentUser.UserType != DTOs.UserType.Manager) { throw new WrongUserException("Function availible only for managers"); } UoW.ToursTemplates.Add(TourLogicMapper.Map <TourDTO, Tour>(NewTour)); }
async Task <TourDTO> IService <TourDTO, int> .Delete(TourDTO entity) { Tour tour = await _tourRepository.Get(entity.Id); tour.CountOfTours = 0; tour = await _tourRepository.Update(tour); return(_mapper.Map <Tour, TourDTO>(tour)); }
public async Task <IActionResult> Add([FromBody] TourDTO tour) { if (ModelState.IsValid) { tour = await _tourService.Add(tour); return(Ok(tour)); } return(BadRequest(ModelState)); }
public async Task <ActualResult> CreateAsync(TourDTO dto) { if (!await CheckNameAsync(dto.Name)) { await _database.EventRepository.Create(_mapperService.Mapper.Map <Event>(dto)); return(_mapperService.Mapper.Map <ActualResult>(await _database.SaveAsync())); } return(new ActualResult(Errors.DuplicateData)); }
private void btnEdit_Click(object sender, EventArgs e) { if (BangTour.SelectedRows.Count > 0) { if (txtMa.Text != "" && txtTen.Text != "" && txtDacDiem.Text != "" && cbbLoai.Text != "") { if (ValadateTen(txtTen.Text)) { MessageBox.Show("Tên tác giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtTen.Text = ""; txtTen.Focus(); } else if (ValadateTen(txtMa.Text)) { MessageBox.Show("Mã đọc giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtMa.Text = ""; txtMa.Focus(); } else if (ValadateTen(txtDacDiem.Text)) { MessageBox.Show("Mã đọc giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtDacDiem.Text = ""; txtDacDiem.Focus(); } else { DataGridViewRow row = BangTour.SelectedRows[0]; string ma = row.Cells[0].Value.ToString(); TourDTO sDTO = new TourDTO(ma, txtTen.Text, cbbLoai.Text); // Sửa if (bus.suaTour(sDTO)) { MessageBox.Show("Sửa thành công"); BangTour.DataSource = bus.getTour(); // refresh datagridview } else { MessageBox.Show("Sửa ko thành công"); } } } else { MessageBox.Show("Xin hãy nhập đầy đủ"); } } else { MessageBox.Show("Hãy chọn tác giả muốn sửa"); } }
public void EditTour(int Id, TourDTO Tour) { if (UserLogic.CurrentUser == null || UserLogic.CurrentUser.UserType != DTOs.UserType.Manager) { throw new WrongUserException("Function availible only for managers"); } Tour tour = UoW.ToursTemplates.Get(Id); tour = TourLogicMapper.Map <TourDTO, Tour>(Tour); UoW.ToursTemplates.Modify(Id, tour); }
public ActionResult GetTour() { string Id = Request["TourList"]; TourDTO t = TourDAO.getTour(Id); ViewBag.Tour = t; List <TourLeadDTO> LeadList = TourLeadDAO.getTourLeadList(t); ViewBag.Leads = LeadList; return(View()); }
public async Task WhenExecuteGetByIdIfElementNotFoundThenGetNotFoundResult() { TourDTO tour = null; Mock <ITourService> mock = new Mock <ITourService>(); mock.Setup(repo => repo.Get(It.IsAny <int>())).ReturnsAsync(tour); TourController controller = new TourController(mock.Object, null, null, null, null, null, null, null, null, null); IActionResult result = await controller.Get(It.IsAny <int>()); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public async Task <int> CreateTourAsync(TourDTO tour) { var tourToAdd = _mapper.Map <Tour>(tour); var resId = await _unit.TourRepository.CreateAsync(tourToAdd); if ((resId ?? 0) == 0) { throw new OperationCanceledException(); } return(resId.Value); }
private void Save_Click(object sender, EventArgs e) { int k = 0; if (textBox_matour.Text == "") { k = 1; errorProvider1.SetError(textBox_matour, "Mã tour không được để trống!"); } if (textBox_tentour.Text == "") { k = 1; errorProvider1.SetError(textBox_tentour, "Tên tour không được để trống!"); } if (textBox_thongtintour.Text == "") { k = 1; errorProvider1.SetError(textBox_thongtintour, "Thông tin tour không được để trống!"); } if (textBox_giatour.Text == "") { k = 1; errorProvider1.SetError(textBox_giatour, "Giá tour không được để trống!"); } if (k == 0) { TourBUS tour = new TourBUS(); TourDTO t = new TourDTO(); t.MaTour = int.Parse(textBox_matour.Text); t.TenTour = textBox_tentour.Text; t.ThongTinTour = textBox_thongtintour.Text; t.GiaTour = int.Parse(textBox_giatour.Text); foreach (ListViewItem item in listView1.Items) { if (item.Selected) { if (tour.suaTour(t) == 1) { MessageBox.Show("Lưu thành công!", "Thông báo"); item.Text = textBox_matour.Text; item.SubItems[1].Text = textBox_tentour.Text; item.SubItems[2].Text = textBox_thongtintour.Text; item.SubItems[3].Text = textBox_giatour.Text; } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); Dispose(); } } } } }
public async Task EditTourAsync(int id, TourDTO tourDTO) { //Check for nullRefExc //if //var tour = await dataBase.Tours.GetAsync(id); //else var editedTour = mapper.Map <TourDTO, Tour>(tourDTO); dataBase.Tours.Update(editedTour); await dataBase.CompleteAsync(); }
public ActionResult EditTour(int?id) { try { TourDTO tour = displayService.GetTour(id); return(View(Mapper.Map <TourDTO, TourViewModel>(tour))); } catch (ValidationException ex) { return(Content(ex.Message)); } }
public void FindByIdTest() { ResetData(); var uow = new Mock <UnitOfWork>(); TourService ts = new TourService(uow.Object); OutputTourService ots = new OutputTourService(uow.Object); TourDTO tour = ots.GetAllFilteredTours(null, null, null, false)[0]; Assert.AreEqual(tour.Country, ts.FindById(tour.TourId).Country); Assert.AreEqual(tour.Region, ts.FindById(tour.TourId).Region); Assert.AreEqual(tour.Hotel, ts.FindById(tour.TourId).Hotel); }
private static TourDTO FillDTO(SqlDataReader reader) { var dto = new TourDTO(); dto.TourID = reader.GetInt32(0); dto.FromCity = reader.GetString(1); dto.ToCity = reader.GetString(2); dto.SubDeadLine = reader.GetDateTime(3); dto.Departure = reader.GetDateTime(4); dto.ReturnDate = reader.GetDateTime(5); dto.Dues = reader.GetInt32(6); return(dto); }
public async Task<ActualResult> UpdateAsync(TourDTO dto) { try { _context.Entry(_mapper.Map<Event>(dto)).State = EntityState.Modified; await _context.SaveChangesAsync(); return new ActualResult(); } catch (Exception exception) { return new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)); } }
public async Task <IActionResult> Get([Required] int id) { if (ModelState.IsValid) { TourDTO tour = await _tourService.Get(id); if (tour != null) { return(Ok(tour)); } return(NotFound()); } return(BadRequest(ModelState)); }