public ActionResult Details(string providerId) { var userId = User.Identity.GetUserId(); int id = Convert.ToInt32(providerId); Provider selectedProvider = _providerRepository.GetById(id); if (_visitRepository.IsUniqueVisit(userId, id)) { _visitRepository.Add(new Visit { date = DateTime.Now, providerId = id, providerName = selectedProvider.name, userId = userId }); if (_visitRepository.Save()) { selectedProvider.totalClicks += 1; selectedProvider.uniqueClicks += 1; selectedProvider.lastVisited = DateTime.Now; _providerRepository.Save(); return(Content($"<script> (() => window.open('{selectedProvider.link}'))() </script>")); } return(View()); } selectedProvider.totalClicks += 1; selectedProvider.lastVisited = DateTime.Now; _providerRepository.Save(); return(Content($"<script> (() => window.open('{selectedProvider.link}'))() </script>")); }
public async Task <int> AddVisit_Post(TemporaryVisitVM newVisit) { newVisit.VisitDate = newVisit.VisitDate + newVisit.TimeOfVisit; var visits = _visitRepository.GetForDateTime(newVisit.VisitDate); if (newVisit.DentistId == 0) { if (visits.Any()) { if (visits.Select(v => v.PatientId).Contains(newVisit.PatientId)) { return(1); } var dentists = _dentistRepository.GetAll().Select(d => d.Id).ToList(); foreach (var v in visits) { if (dentists.Contains(v.DentistId)) { dentists.Remove(v.DentistId); } } if (dentists.Any()) { newVisit.DentistId = dentists.First(); } } else { newVisit.DentistId = _dentistRepository.GetAll().Select(d => d.Id).First(); } } var visit = _mapper.Map <Visit>(newVisit); await _visitRepository.Add(visit); return(0); }
public IActionResult AddVisit([FromBody] Visit model) { model.StartTime = DateTime.Now; model.IsActive = true; visit_repo.Add(model); Patient pat = Patient_repo.Find(model.PatientId); if (pat.TotalVisitsToDate == null) { pat.TotalVisitsToDate = 1; } else { pat.TotalVisitsToDate = pat.TotalVisitsToDate + 1; } Patient_repo.Update(pat); return(new OkObjectResult(new { VisitID = model.VisitId })); }
public VisitResult Visit(string aliasName, string ipAddress, string browser, string referrer) { VisitResult result = Validation.Validate <VisitResult>(() => string.IsNullOrWhiteSpace(aliasName), "alias", TextMessages.AliasCannotBeBlank) .Or(() => !baseX.IsValid(aliasName), "alias", TextMessages.AliasIsNotValidAliasCanOnlyContainAlphanumericCharacters) .And(() => string.IsNullOrWhiteSpace(ipAddress), "ipAddress", TextMessages.IpAddressCannotBeBlank) .Or(() => !ipAddress.IsIPAddress(), "ipAddress", TextMessages.IpAddressIsNotInValidFormat) .Result(); if (result.RuleViolations.IsEmpty()) { Alias alias = GetAlias(aliasName, out result); if (result.RuleViolations.IsEmpty()) { string referrerDomain = null; Uri referrerUri; if (Uri.TryCreate(referrer, UriKind.Absolute, out referrerUri)) { referrerDomain = referrerUri.Host; } Visit visit = new Visit { IPAddress = ipAddress, Browser = browser, Referrer = new Referrer { Domain = referrerDomain, Url = referrer }, Alias = alias }; visitRepository.Add(visit); unitOfWork.Commit(); result = new VisitResult(new VisitDTO(visit)); eventAggregator.GetEvent <ShortUrlVisitedEvent>().Publish(new EventArgs <Visit>(visit)); } } return(result); }