public ActionResult Add(AuditSectionViewModel model) { var userId = User.Identity.GetUserId(); var submitDateTime = DateTime.Now; model.CreateDateTime = submitDateTime; model.ModifiedDateTime = submitDateTime; model.CreatedById = userId; model.ModifiedById = userId; var auditTemplate = _context.AuditTemplates.Single(a => a.Id == model.AuditTemplateId); if (ModelState.IsValid) { var newAuditSection = new AuditSection(); AutoMapper.Mapper.Map(model, newAuditSection); auditTemplate.ModifiedById = userId; auditTemplate.ModifiedDateTime = submitDateTime; _context.AuditSections.Add(newAuditSection); _context.SaveChanges(); return(RedirectToAction("Details", "AuditTemplates", new { id = newAuditSection.AuditTemplateId })); } model.AuditTemplate = new AuditTemplateViewModel(); AutoMapper.Mapper.Map(auditTemplate, model.AuditTemplate); return(View("Form", model)); }
public void Log(string auditSection, string auditAction, string details, string otherRefId = null, Person userInfo = null) { var username = (HttpContext.Current.User == null) ? null : HttpContext.Current.User.Identity.Name; if (username == null && userInfo == null) return; //if (this._webUser.GetCurrentUserName == null) return; if (string.IsNullOrEmpty(auditSection) || string.IsNullOrEmpty(auditAction) || string.IsNullOrEmpty(details)) return; var user = userInfo ?? (_personRepo.Table.FirstOrDefault(x => x.Email == username) ?? new Person()); //var user = Membership.GetUser(this._webUser.GetCurrentUserName.UserName); auditSection = auditSection.Trim(); auditAction = auditAction.Trim(); details = details.Trim(); //1. get or insert into Section var section = this._section.Table.FirstOrDefault(x => x.Name.ToLower() == auditSection.ToLower()); if (section == null) { section = new AuditSection { Name = auditSection }; this._section.Add(section); } //get or insert into action var action = this._action.Table.FirstOrDefault(x => x.AuditSectionId == section.Id && x.Name.ToLower() == auditAction.ToLower()); if (action == null) { action = new AuditAction { Name = auditAction, AuditSectionId = section.Id }; this._action.Add(action); } //finally save it var trail = new AuditTrail { Details = details, //Source = _webUser.GetCurrentUserName.Source, Source = user.FullName, PersonalInfoId = user.Id, //UserId = new Guid(user.ProviderUserKey.ToString()), UserId = new Guid(user.UserId), AuditActionId = action.Id, TimeStamp = this._dateTime.ConvertToUserTime(DateTime.Now), UserIP = CommonHelper.RemoteIP, OtherRefId = otherRefId, BrowserName = CommonHelper.UserBrowser, IsMobile = CommonHelper.IsMobileBrowser }; //set the medium and browserName here . . . this._trail.Add(trail); // throw new NotImplementedException(); }