public ActionResult Details(string urlParam) { if (urlParam == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled); if (isGuid.IsMatch(urlParam)) { return(RedirectPermanent("/visa")); } Visa visa = db.Visas.FirstOrDefault(current => current.UrlParam == urlParam); List <VisaTour> visaTours = db.VisaTours.Where(current => current.VisaId == visa.Id).Include(c => c.Tour).Include(c => c.Tour.TourCategory).ToList(); List <Tour> tours = new List <Tour>(); foreach (VisaTour visaTour in visaTours) { tours.Add(visaTour.Tour); } VisaDetailViewModel visaDetail = new VisaDetailViewModel() { Visa = visa, VisaDetails = db.VisaDetails.Where(current => current.VisaId == visa.Id && current.IsDelete == false) .OrderBy(current => current.Order).ToList(), Menu = menu.ReturnMenuTours(), MenuBlogGroups = menu.ReturnBlogGroups(), Footer = menu.ReturnFooter(), SuggestedTours = tours }; if (!string.IsNullOrEmpty(visa.PageTitle)) { ViewBag.Title = visa.PageTitle; } else { ViewBag.Title = visa.Title + " | اخذ ویزا تضمینی توسط بکتاش سیر"; } if (!string.IsNullOrEmpty(visa.PageDescription)) { ViewBag.Description = visa.PageDescription; } else { ViewBag.Description = "راهنمای جامع اخذ " + visa.Title + " به صورت تضمینی. اطلاعات جامع اخذ ویزا تمامی کشورها و ویزا شینگن را در وب سایت بکتاش سیر گشت مطالعه نمایید."; } ViewBag.Canonical = "https://www.bektashtravel.com/visa/" + visa.UrlParam; return(View(visaDetail)); }
public async Task <IActionResult> Details(VisaDetailViewModel formData) { try { if (ModelState.IsValid) { //if (DateTime.Parse(formData.ExpiryDate) <= DateTimeOffset.Now) //{ // ModelState.AddModelError("Visas", $"Employee Visa Expiry Date {formData.ExpiryDate} can't be now or less than today, Please enter a valid visa expiry date greater than today."); //} //else if (DateTimeOffset.Now.Date.Day - DateTime.Parse(formData.ExpiryDate).Day <= 7) //{ // int days = DateTime.Parse(formData.ExpiryDate).Day - DateTimeOffset.Now.Date.Day; // ModelState.AddModelError("Visas", $"Employee Visa can't be expiring in {days} days, Please enter a valid date that expiries in 8 days and above ."); //} ////else ////{ //// bool bIfExist = false; //// var q = from c in _db.Visas where c.VisaNumber == formData.VisaNumber select c; //// try //// { //// q.ToList()[0].VisaNumber.ToString(); //// bIfExist = true; //// } //// catch { } //// if (bIfExist == true) //// { //// ModelState.AddModelError("Visas", $"Can not register duplicate record. {formData.VisaNumber} is already registered"); //// } // else // { await _visaServices.UpdateVisaAsync(new Visa { DateTimeModified = DateTimeOffset.Now, VisaNumber = formData.VisaNumber, EmployeeId = formData.EmployeeId, UserAccount = User.Identity.Name, ExpiryDate = DateTime.Parse(formData.ExpiryDate), Id = formData.Id }); TempData["Message"] = "Changes saved successfully"; _logger.LogInformation($"Successfully updated employee visa {formData.EmployeeId} record by user={@User.Identity.Name.Substring(4)}"); return(RedirectToAction("details", new { id = formData.Id })); } } catch (ApplicationException error) { _logger.LogError( error, $"FAIL: failed to update employee visa {formData.EmployeeId}. Internal Application Error.; user={@User.Identity.Name.Substring(4)}"); ModelState.AddModelError("Visa", $"Failed to update employee visa record {formData.EmployeeId}. Contact IT ServiceDesk for support thank you."); } await LoadSelectListsAsync(); return(View(formData)); }
//[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)] public async Task <IActionResult> Details(Guid id) { var visaQuery = await _visaServices.GetVisaById(id); if (visaQuery == null) { return(NotFound()); } var model = new VisaDetailViewModel { Id = visaQuery.Id, EmployeeId = visaQuery.EmployeeId ?? Guid.Empty, VisaNumber = visaQuery.VisaNumber, ExpiryDate = visaQuery.ExpiryDate == null ? string.Empty : DateTime.Parse(visaQuery.ExpiryDate.ToString()).ToString("yyyy-MM-dd") }; await LoadSelectListsAsync(); return(View(model)); }
private void VisaDetail_OnUnloaded(object sender, RoutedEventArgs e) { VisaDetailViewModel.CleanUp(); }