public void SaveUserActivity(int userProfile, string activity, DateTime activityDate) { string username = GetUserNamebyUserId(userProfile); string fullname = GetUserFullNamebyProdileId(userProfile); string desc = username + " " + activity + " on " + activityDate; string branchCode = GetBranchIdbyProdileId(userProfile); string branchName = GetBranchName(branchCode); CMDM_ACTIVITY_LOG activity_log = new CMDM_ACTIVITY_LOG(); try { activity_log = new CMDM_ACTIVITY_LOG { USER_ID = userProfile, USER_NAME = username, FULLNAME = fullname, BRANCH_CODE = branchCode, BRANCH_NAME = branchName, ACTIVITY_DESC = desc, ACTIVITY_DATE = activityDate }; db.CMDM_ACTIVITY_LOG.Add(activity_log); db.SaveChanges(); }catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void SaveUserActivity(int userProfile, string activity, DateTime activityDate, string unauthusername = "") { string username = ""; string fullname = ""; string desc = ""; string branchCode = ""; string branchName = ""; if (String.IsNullOrEmpty(unauthusername)) { username = GetUserNamebyUserId(userProfile); fullname = GetUserFullNamebyProdileId(userProfile); desc = username + " " + activity + " on " + activityDate; branchCode = GetBranchIdbyProdileId(userProfile); branchName = GetBranchName(branchCode); } else { username = unauthusername; fullname = unauthusername; desc = username + " " + activity + " on " + activityDate; branchCode = ""; branchName = ""; } using (var db = new AppDbContext()) { CMDM_ACTIVITY_LOG activity_log; try { activity_log = new CMDM_ACTIVITY_LOG { USER_ID = userProfile, USER_NAME = username, FULLNAME = fullname, BRANCH_CODE = branchCode, BRANCH_NAME = branchName, ACTIVITY_DESC = desc, ACTIVITY_DATE = activityDate }; db.CMDM_ACTIVITY_LOG.Add(activity_log); db.Entry(activity_log).State = EntityState.Added; db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }