public void logActivity(string userName, string Action) { Pogi.Entities.Log2 Activity = new Pogi.Entities.Log2(); Activity.createdTS = _dateTime.getNow(); Activity.Action = Action; Activity.ipAddr = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); if (userName != null && userName.Length > 0) { Member member = _memberData.getByEmailAddr(userName.Trim().ToLower()); if (member == null) { member = _memberData.getByEmailAddr2nd(userName.Trim().ToLower()); } if (member != null) { Activity.MemberId = member.MemberId; Activity.UserName = member.FirstName + " " + member.LastName; if (Action == "Login" || Action == "LoginExt") { _logIp.logIp(Activity.ipAddr, Activity.UserName); } } } else { Activity.UserName = _logIp.getUser(Activity.ipAddr) + " (G)"; } _context.Log2.Add(Activity); _context.SaveChanges(); }
//public async Task<IActionResult> Create([Bind("TeeTimeId,ReservedById,TeeTimeTS,CourseId,NumPlayers")] TeeTime teeTime) public async Task <IActionResult> Create(TeeTimeCreateViewModel model) { if (ModelState.IsValid) { DateTime ts; if (!DateTime.TryParse(model.TeeTimeTS.ToString(), out ts)) { ModelState.AddModelError("TeeTimeTS", "Invalid Date"); model.Courses = _courseData.getSelectList(); model.Member = _memberData.getByEmailAddr(_userManager.GetUserName(User)); model.ReservedById = model.Member.MemberId; return(View(model)); } if (ts < _dateTime.getNow()) { ModelState.AddModelError("TeeTimeTS", "Please specify a future Date and Time"); model.Courses = _courseData.getSelectList(); model.Member = _memberData.getByEmailAddr(_userManager.GetUserName(User)); model.ReservedById = model.Member.MemberId; return(View(model)); } TeeTime teeTime = new TeeTime(); teeTime.TeeTimeId = model.TeeTimeId; teeTime.ReservedById = model.ReservedById; teeTime.TeeTimeTS = ts; teeTime.CourseId = model.CourseId; teeTime.NumPlayers = model.NumPlayers; teeTime.MajorTour = model.MajorTour; teeTime.TeeTimeInterval = model.TeeTimeInterval; teeTime.LockWithdrawDays = model.LockWithdrawDays; teeTime.AutoAssign = false; _context.Add(teeTime); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } model.Courses = _courseData.getSelectList(); model.Member = _memberData.getByEmailAddr(_userManager.GetUserName(User)); model.ReservedById = model.Member.MemberId; return(View(model)); }
public void logIp(string IpAddr, string UserName) { IpGuest IpGuest = new IpGuest(); IpGuest.IpAddr = IpAddr.Trim(); IpGuest.UserName = UserName; IpGuest.LastUpdtTs = _dateTime.getNow(); if (_context.IpGuest.Any(e => e.IpAddr == IpAddr)) { _context.IpGuest.Update(IpGuest); } else { _context.IpGuest.Add(IpGuest); } _context.SaveChanges(); }