private string addLogForList <T>(string log, Guid ReferenceId, string Name, List <string> oldValue, List <string> newValue) { if (newValue != null) { newValue = newValue.ConvertAll(d => d.ToUpper()); } if (oldValue != null) { oldValue = oldValue.ConvertAll(d => d.ToUpper()); } string addedlog = string.Empty; if (newValue != null) { foreach (string value in newValue) { if (oldValue != null && oldValue.Contains(value)) { oldValue.Remove(value); } else { addedlog = append <T>(addedlog, value, ", "); } } } if (!string.IsNullOrEmpty(addedlog)) { addedlog = Environment.NewLine + "Added: " + addedlog; } string removedlog = string.Empty; if (oldValue != null) { foreach (string value in oldValue) { removedlog = append <T>(removedlog, value, ", "); } } if (!string.IsNullOrEmpty(removedlog)) { removedlog = Environment.NewLine + "Removed: " + removedlog; } if (!string.IsNullOrEmpty(removedlog) || !string.IsNullOrEmpty(addedlog)) { string newlog = Name + " UPDATE: " + removedlog + addedlog; ActivityLogsController.Add(db, Session, ReferenceId, newlog); return(Util.append(log, newlog, Environment.NewLine + Environment.NewLine)); } else { return(log); } }
public ActionResult Edit(RemindersModel model, string Notes) { if (ModelState.IsValid) { string log = string.Format("[{0}] {1}", Util.GetEnumDescription <EnumReminderStatuses>(model.Status_enumid), Notes); db.Entry(model).State = EntityState.Modified; ActivityLogsController.Add(db, Session, model.Id, log); db.SaveChanges(); return(RedirectToAction(nameof(HomeController.Index), "Home")); } return(View(model)); }
private string addLog(string log, Guid ReferenceId, string Name, object oldValue, object newValue, string format) { string newlog = string.Empty; newlog = Util.appendChange(newlog, oldValue, newValue, format); if (string.IsNullOrEmpty(newlog)) { return(log); } else { ActivityLogsController.Add(db, Session, ReferenceId, newlog); return(Util.append(log, string.Format(Name + " UPDATE: {0} to {1}", oldValue, newValue), Environment.NewLine + Environment.NewLine)); } }
public void add(List <PayrollPaymentItemsModel> items, PayrollPaymentsModel model) { if (items.Count == 0) { return; } Guid?PayrollPayments_Id = null; foreach (PayrollPaymentItemsModel item in items) { if (item.PayrollPayments_Id != null) { PayrollPayments_Id = item.PayrollPayments_Id; break; } } string log = string.Format("Payment of {0:N0} on {1:dd/MM/yy}", model.Amount, model.Timestamp); if (!string.IsNullOrWhiteSpace(model.Notes)) { log += ", Notes: " + model.Notes; } if (PayrollPayments_Id != null) { log = "Additional " + log; model = get(Session, (Guid)PayrollPayments_Id); } else { model.Id = Guid.NewGuid(); db.Database.ExecuteSqlCommand(@" -- INCREMENT LAST HEX NUMBER DECLARE @HexLength int = 5, @LastHex_String varchar(5), @NewNo varchar(5) SELECT @LastHex_String = ISNULL(MAX(No),'') From PayrollPayments DECLARE @LastHex_Int int SELECT @LastHex_Int = CONVERT(INT, CONVERT(VARBINARY, REPLICATE('0', LEN(@LastHex_String)%2) + @LastHex_String, 2)) --@LastHex_String length must be even number of digits to convert to int SET @NewNo = RIGHT(CONVERT(NVARCHAR(10), CONVERT(VARBINARY(8), @LastHex_Int + 1), 1),@HexLength) INSERT INTO PayrollPayments (Id, No, Timestamp, UserAccounts_Id, Amount, Branches_Id, Approved, Cancelled, CancelNotes, Notes) VALUES(@Id,@NewNo,@Timestamp,@UserAccounts_Id,@Amount,@Branches_Id,@Approved,@Cancelled,@CancelNotes,@Notes); ", DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Id.Name, model.Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Timestamp.Name, model.Timestamp), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_No.Name, model.No), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_UserAccounts_Id.Name, model.UserAccounts_Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Amount.Name, model.Amount), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Branches_Id.Name, model.Branches_Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Approved.Name, model.Approved), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Cancelled.Name, model.Cancelled), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_CancelNotes.Name, model.CancelNotes), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Notes.Name, model.Notes) ); } ActivityLogsController.Add(db, Session, model.Id, log); PayrollPaymentItemsController.update_PayrollPayments_Id(db, Session, model.Id, items); db.SaveChanges(); }