Example #1
0
        public void CreateAuditTrail(AuditActionType Action, int KeyFieldID, Object OldObject, Object NewObject)
        {
            // get the differance
            CompareLogic compObjects = new CompareLogic();

            compObjects.Config.MaxDifferences = 99;
            ComparisonResult  compResult = compObjects.Compare(OldObject, NewObject);
            List <AuditDelta> DeltaList  = new List <AuditDelta>();

            foreach (var change in compResult.Differences)
            {
                AuditDelta delta = new AuditDelta();
                if (change.PropertyName.Substring(0, 1) == ".")
                {
                    delta.FieldName = change.PropertyName.Substring(1, change.PropertyName.Length - 1);
                }
                delta.ValueBefore = change.Object1Value;
                delta.ValueAfter  = change.Object2Value;
                DeltaList.Add(delta);
            }
            AuditTable audit = new AuditTable();

            audit.AuditActionTypeENUM = (int)Action;
            audit.DataModel           = this.GetType().Name;
            audit.DateTimeStamp       = DateTime.Now;
            audit.KeyFieldID          = KeyFieldID;
            audit.ValueBefore         = JsonConvert.SerializeObject(OldObject); // if use xml instead of json, can use xml annotation to describe field names etc better
            audit.ValueAfter          = JsonConvert.SerializeObject(NewObject);
            audit.Changes             = JsonConvert.SerializeObject(DeltaList);
            AuditTestEntities ent = new AuditTestEntities();

            ent.AuditTable.Add(audit);
            ent.SaveChanges();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            AuditTable audittable = db.AuditTables.Find(id);

            db.AuditTables.Remove(audittable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "AuditId,Admin,Customer,Field,InitialValue,FinalValue,TimeStamp")] AuditTable audittable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(audittable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(audittable));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,StartDate,EndDate,ClientName,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Project project)
 {
     if (ModelState.IsValid)
     {
         db.Entry(project).State = EntityState.Modified;
         AuditTable.UpdateAuditFields(project);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(project));
 }
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,ContactNo,Email,Skills,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         AuditTable.UpdateAuditFields(employee);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
        public ActionResult Create([Bind(Include = "AuditId,Admin,Customer,Field,InitialValue,FinalValue,TimeStamp")] AuditTable audittable)
        {
            if (ModelState.IsValid)
            {
                db.AuditTables.Add(audittable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(audittable));
        }
 public ActionResult Edit([Bind(Include = "Id,Status,Description,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] TaskStatu taskStatu)
 {
     if (ModelState.IsValid)
     {
         db.Entry(taskStatu).State = EntityState.Modified;
         AuditTable.UpdateAuditFields(taskStatu);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(taskStatu));
 }
 public ActionResult Create([Bind(Include = "Id,Name,Address,Phone,JoinDate,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Customer customer)
 {
     AuditTable.InsertAuditFields(customer);
     if (ModelState.IsValid)
     {
         customer.Id = Guid.NewGuid();
         db.Customers.Add(customer);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Example #9
0
 public ActionResult Edit([Bind(Include = "Id,ItemId,CreateDate,LastUsedDate, Rating, IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] MenuItem menuItem)
 {
     AuditTable.UpdateAuditFields(menuItem);
     if (ModelState.IsValid)
     {
         db.Entry(menuItem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ItemId = new SelectList(db.Items.Where(s => !s.IsDeleted), "Id", "Name", menuItem.ItemId);
     return(View(menuItem));
 }
Example #10
0
 public ActionResult Edit([Bind(Include = "Id,SaleId,Quantity,DeliveriedDate,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Delivery delivery)
 {
     AuditTable.UpdateAuditFields(delivery);
     if (ModelState.IsValid)
     {
         db.Entry(delivery).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SaleId = new SelectList(db.Sales.Where(s => !s.IsDeleted), "Id", "SaleCode", delivery.SaleId);
     return(View(delivery));
 }
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,ProjectTaskId,Comments,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] ManagerComment managerComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(managerComment).State = EntityState.Modified;
         AuditTable.UpdateAuditFields(managerComment);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProjectTaskId = new SelectList(db.ProjectTasks.Where(s => !s.IsDeleted).Select(s => s), "Id", "Employee.FullName", managerComment.ProjectTaskId);
     return(View(managerComment));
 }
 public ActionResult Edit([Bind(Include = "Id,SupplierId,Description,Price,PurchaseDate,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Purchase purchase)
 {
     AuditTable.UpdateAuditFields(purchase);
     if (ModelState.IsValid)
     {
         db.Entry(purchase).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SupplierId = new SelectList(db.Suppliers.Where(p => !p.IsDeleted), "Id", "Name", purchase.SupplierId);
     return(View(purchase));
 }
        public ActionResult Create([Bind(Include = "Id,Status,Description,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] TaskStatu taskStatu)
        {
            AuditTable.InsertAuditFields(taskStatu);
            if (ModelState.IsValid)
            {
                taskStatu.Id = Guid.NewGuid();
                db.TaskStatus.Add(taskStatu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(taskStatu));
        }
 public ActionResult Edit([Bind(Include = "Id,SupplierId,EmployeeId,PickUpDate,Price,Quantity,Address,Unit,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] PickUp pickUp)
 {
     AuditTable.UpdateAuditFields(pickUp);
     if (ModelState.IsValid)
     {
         db.Entry(pickUp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmployeeId = new SelectList(db.Employees.Where(p => !p.IsDeleted), "Id", "Name", pickUp.EmployeeId);
     ViewBag.SupplierId = new SelectList(db.Suppliers.Where(p => !p.IsDeleted), "Id", "Name", pickUp.SupplierId);
     return(View(pickUp));
 }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,ContactNo,Email,Skills,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Employee employee)
        {
            AuditTable.InsertAuditFields(employee);
            if (ModelState.IsValid)
            {
                employee.Id = Guid.NewGuid();
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Example #16
0
        public ActionResult Create([Bind(Include = "Id,Name,Rating,ContactNo,ProvideDate,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Supplier supplier)
        {
            AuditTable.InsertAuditFields(supplier);
            if (ModelState.IsValid)
            {
                supplier.Id = Guid.NewGuid();
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
Example #17
0
        public ActionResult Create([Bind(Include = "Id,SaleId,Quantity,DeliveriedDate,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Delivery delivery)
        {
            AuditTable.InsertAuditFields(delivery);
            if (ModelState.IsValid)
            {
                delivery.Id = Guid.NewGuid();
                db.Deliveries.Add(delivery);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SaleId = new SelectList(db.Sales.Where(s => !s.IsDeleted), "Id", "SaleCode", delivery.SaleId);
            return(View(delivery));
        }
        // GET: /Audit/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AuditTable audittable = db.AuditTables.Find(id);

            if (audittable == null)
            {
                return(HttpNotFound());
            }
            return(View(audittable));
        }
Example #19
0
        public ActionResult Create([Bind(Include = "Id,ItemId,CreateDate,LastUsedDate, Rating, IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] MenuItem menuItem)
        {
            AuditTable.InsertAuditFields(menuItem);
            if (ModelState.IsValid)
            {
                menuItem.Id = Guid.NewGuid();
                db.MenuItems.Add(menuItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ItemId = new SelectList(db.Items.Where(s => !s.IsDeleted), "Id", "Name", menuItem.ItemId);
            return(View(menuItem));
        }
Example #20
0
 public ActionResult Edit([Bind(Include = "Id,EmployeeId,CustomerId,SaleCode,Unit,Price,ItemId,Quantity,IsDeleted,InsAt,InsBy,UpdAt,UpdBy")] Sale sale)
 {
     AuditTable.UpdateAuditFields(sale);
     if (ModelState.IsValid)
     {
         db.Entry(sale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customers.Where(s => !s.IsDeleted), "Id", "Name", sale.CustomerId);
     ViewBag.EmployeeId = new SelectList(db.Employees.Where(s => !s.IsDeleted), "Id", "Name", sale.EmployeeId);
     ViewBag.ItemId     = new SelectList(db.Items.Where(s => !s.IsDeleted), "Id", "Name", sale.ItemId);
     return(View(sale));
 }