/// <summary>Audit entity deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityDeleted }; AuditEntityDeleted(entry, objectStateEntry.OriginalValues); audit.Entries.Add(entry); }
/// <summary>Default constructor.</summary> public AuditEntry(ObjectStateEntry objectStateEntry) { _objectStateEntry = objectStateEntry; Date = DateTime.Now; EntitySetName = objectStateEntry.EntitySet.Name; if (!objectStateEntry.IsRelationship) { TypeName = objectStateEntry.Entity.GetType().Name; } Properties = new List<AuditEntryProperty>(); }
/// <summary>Audit entity added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityAdded }; // CHECK if the key should be resolved in POST Action if (objectStateEntry.EntityKey.IsTemporary) { entry.DelayedKey = objectStateEntry; } AuditEntityAdded(entry, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
/// <summary>Audit entity modified.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditEntityModified(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.EntityModified }; if (audit.Configuration.IsSoftAdded != null && audit.Configuration.IsSoftAdded(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftAdded; } else if (audit.Configuration.IsSoftDeleted != null && audit.Configuration.IsSoftDeleted(objectStateEntry.Entity)) { entry.State = AuditEntryState.EntitySoftDeleted; } AuditEntityModified(audit, entry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues); audit.Entries.Add(entry); }
/// <summary>Audit relationship deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationDeleted(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipDeleted }; var values = objectStateEntry.OriginalValues; for (var i = 0; i < values.FieldCount; i++) { var relationName = values.GetName(i); var value = (EntityKey) values.GetValue(i); foreach (var keyValue in value.EntityKeyValues) { // todo: better add a new property association? var keyName = string.Concat(relationName, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, keyValue.Value, null)); } } audit.Entries.Add(entry); }
/// <summary>Audit relationship added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> public static void AuditRelationAdded(Audit audit, ObjectStateEntry objectStateEntry) { var entry = new AuditEntry(objectStateEntry) { State = AuditEntryState.RelationshipAdded }; var values = objectStateEntry.CurrentValues; var value_0 = (EntityKey) values.GetValue(0); var value_1 = (EntityKey) values.GetValue(1); if (value_0.IsTemporary || value_1.IsTemporary) { entry.DelayedKey = objectStateEntry; } else { var relationName_0 = values.GetName(0); var relationName_1 = values.GetName(1); foreach (var keyValue in value_0.EntityKeyValues) { var keyName = string.Concat(relationName_0, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } foreach (var keyValue in value_1.EntityKeyValues) { var keyName = string.Concat(relationName_1, ";", keyValue.Key); entry.Properties.Add(new AuditEntryProperty(keyName, null, keyValue.Value)); } } audit.Entries.Add(entry); }
public ActionResult Index(string submitButton, GoodsReceiptViewModels model, HttpPostedFileBase file = null) { try { //ApplicationUser currentUser = ApplicationUserManager.GetApplicationUser(User.Identity.Name, HttpContext.GetOwinContext()); if (submitButton == "Save") { // model.goodreceipt.BaseDocId = model.PurchaseOrder.Purchase_Order_Id; model.goodreceipt.Document_Date = DateTime.Now; model.goodreceipt.Posting_Date = DateTime.Now; model.goodreceipt.Doc_Status = "Open"; model.goodreceipt.TargetDocId = "0"; model.goodreceipt.Created_Branc_Id = CurrentBranchId; //CurrentBranchId; model.goodreceipt.Created_Dte = DateTime.Now; model.goodreceipt.Created_User_Id = CurrentUser.Id; //CurrentUser.Id; // model.goodreceipt.Distribute_LandedCost = "equality"; //if (model.goodreceipt.Distribute_LandedCost == "Equality") //{ // double a = Convert.ToDouble(model.goodreceipt.Freight + model.goodreceipt.Loading / model.goodreceiptitemlist.Count); //}Purchase_Order_Id //else if(model.goodreceipt.Distribute_LandedCost=="Quantity") //{ // double b = Convert.ToDouble(model.goodreceipt.Freight + model.goodreceipt.Loading / model.goodreceiptitemlist.Count *(model.goodreceiptitemlist.FirstOrDefault().LineTotal)); //} //else //{ // double c = Convert.ToDouble((model.goodreceipt.Freight + model.goodreceipt.Loading / model.goodreceiptitemlist.Count) - (model.goodreceiptitem.Quantity * model.goodreceiptitem.Unit_price)*model.goodreceiptitem.Discount_percent); //} var GoodsList = model.goodreceiptitemlist.Where(x => x.IsDummy == 0); model.goodreceiptitemlist = GoodsList.ToList(); for (int i = 0; i < model.goodreceiptitemlist.Count; i++) { model.goodreceiptitemlist[i].BaseDocLink = "N"; //model.goodreceiptitemlist[i].Product_id = model.PurchaseOrderItemsList[i].Product_id; //model.goodreceiptitemlist[i].Quantity = model.PurchaseOrderItemsList[i].Quantity; //model.goodreceiptitemlist[i].Unit_price = model.PurchaseOrderItemsList[i].Unit_price; //model.goodreceiptitemlist[i].Discount_percent = model.PurchaseOrderItemsList[i].Discount_percent; //model.goodreceiptitemlist[i].Vat_Code = model.PurchaseOrderItemsList[i].Vat_Code; //model.goodreceiptitemlist[i].Freight_Loading = Convert.ToDecimal(model.PurchaseOrderItemsList[i].Freight_Loading); } if (goodsrepository.AddNewQuotation(model.goodreceipt, model.goodreceiptitemlist, ref ErrorMessage)) { return(RedirectToAction("Index", "GoodsReceipt")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } else if (submitButton == "Save ") { GoodsReceiptViewModels model1 = new GoodsReceiptViewModels(); model1.BranchList = goodsrepository.GetAddressbranchList().ToList(); model1.BussinessList = goodsrepository.GetAddressbusinessList().ToList(); model1.productlist = goodsrepository.GetProductList(); model1.VATList = goodsrepository.GetVATList(); model1.PurchaseOrder = goodsrepository.FindOneQuotationById1(model.PurchaseOrder.Purchase_Order_Id); model1.PurchaseOrderItemsList = goodsrepository.FindOneQuotationItemById1(model.PurchaseOrder.Purchase_Order_Id); // model1.PurchaseOrderItems = goodsrepository.FindOneQuotationItemById1(model.PurchaseOrderList.FirstOrDefault().Purchase_Order_Id); if (model1.PurchaseOrder.Vendor == model.PurchaseOrder.Vendor) { //for BaseDocId for (int j = 0; j < model.PurchaseOrderItemsList.Count; j++) { if (model1.PurchaseOrderItemsList[j].Product_id == model.PurchaseOrderItemsList[j].Product_id) { model.goodreceipt.BaseDocId = model.PurchaseOrder.Purchase_Order_Id; } } //for BaseDocLink for (int j = 0; j < model.PurchaseOrderItemsList.Count; j++) { if (model1.PurchaseOrderItemsList[j].Product_id == model.PurchaseOrderItemsList[j].Product_id) { model.goodreceiptitemlist[j].BaseDocLink = "Y"; } else { model.goodreceiptitemlist[j].BaseDocLink = "N"; } model.goodreceipt.Doc_Status = "Open"; model.goodreceipt.Created_Branc_Id = CurrentBranchId; //CurrentBranchId; model.goodreceipt.Created_Dte = DateTime.Now; model.goodreceipt.Created_User_Id = CurrentBranchId; //CurrentUser.Id; model.goodreceipt.Purchase_Order_Id = model.PurchaseOrder.Purchase_Order_Id; model.goodreceipt.Reference_Number = model.PurchaseOrder.Reference_Number; model.goodreceipt.Vendor = model.PurchaseOrder.Vendor; model.goodreceipt.Doc_Status = model.PurchaseOrder.Order_Status; model.goodreceipt.Posting_Date = model.PurchaseOrder.Posting_Date; model.goodreceipt.Due_Date = model.PurchaseOrder.Delivery_Date; model.goodreceipt.Document_Date = model.PurchaseOrder.Document_Date; model.goodreceipt.Ship_To = model.PurchaseOrder.Ship_To; model.goodreceipt.Freight = model.PurchaseOrder.Freight; model.goodreceipt.Loading = model.PurchaseOrder.Loading; model.goodreceipt.TotalBefDocDisc = model.PurchaseOrder.TotalBefDocDisc; model.goodreceipt.DocDiscAmt = model.PurchaseOrder.DocDiscAmt; model.goodreceipt.TotalGRDocAmt = model.PurchaseOrder.TotalOrdAmt; model.goodreceipt.TaxAmt = model.PurchaseOrder.TaxAmt; model.goodreceipt.TargetDocId = "0"; //model.PurchaseOrder.BaseDocId = qq; var Goodslist = model.PurchaseOrderItemsList.Where(x => x.IsDummy == 0); model.PurchaseOrderItemsList = Goodslist.ToList(); for (int i = 0; i < model.PurchaseOrderItemsList.Count; i++) { model.goodreceiptitemlist[i].BaseDocLink = "Y"; model.goodreceiptitemlist[i].Product_id = model.PurchaseOrderItemsList[i].Product_id; model.goodreceiptitemlist[i].Quantity = model.PurchaseOrderItemsList[i].Quantity; model.goodreceiptitemlist[i].Unit_price = model.PurchaseOrderItemsList[i].Unit_price; model.goodreceiptitemlist[i].Discount_percent = model.PurchaseOrderItemsList[i].Discount_percent; model.goodreceiptitemlist[i].Vat_Code = model.PurchaseOrderItemsList[i].Vat_Code; model.goodreceiptitemlist[i].Freight_Loading = Convert.ToDecimal(model.PurchaseOrderItemsList[i].Freight_Loading); } if (goodsrepository.AddNewQuotation(model.goodreceipt, model.goodreceiptitemlist, ref ErrorMessage)) { for (int k = 0; k < model.PurchaseOrderItemsList.Count; k++) { if (model1.PurchaseOrderItemsList[k].Product_id == model.PurchaseOrderItemsList[k].Product_id && model.PurchaseOrderItemsList[k].Quantity >= model1.PurchaseOrderItemsList[k].Received_Qty) { model1.PurchaseOrder.Order_Status = "Closed"; //model1.PurchaseOrder.TargetDocId = Convert.ToString(model.PurchaseOrder.Purchase_Order_Id); if (model1.PurchaseOrder.TargetDocId == "") { model1.PurchaseOrder.TargetDocId = Convert.ToString(model.goodreceipt.Goods_Receipt_Id); } else { model1.PurchaseOrder.TargetDocId = Convert.ToString(model.goodreceipt.Goods_Receipt_Id); } // model.PurchaseOrderItemsList[k].BaseDocLink = "N"; model1.PurchaseOrderItemsList[k].Purchase_OrderItem_Id = model1.PurchaseOrderItemsList[k].Purchase_OrderItem_Id; model1.PurchaseOrderItemsList[k].Purchase_Order_Id = model1.PurchaseOrderItemsList[k].Purchase_Order_Id; //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date; model1.PurchaseOrderItemsList[k].Received_Qty = Convert.ToInt32(model.PurchaseOrderItemsList[k].Received_Qty) + model1.PurchaseOrderItemsList[k].Quantity; model1.PurchaseOrderItemsList[k].Product_id = model.PurchaseOrderItemsList[k].Product_id; model1.PurchaseOrderItemsList[k].Unit_price = model.PurchaseOrderItemsList[k].Unit_price; model1.PurchaseOrderItemsList[k].Discount_percent = model.PurchaseOrderItemsList[k].Discount_percent; model1.PurchaseOrderItemsList[k].Vat_Code = model.PurchaseOrderItemsList[k].Vat_Code; } else if (model1.PurchaseOrderItemsList[k].Product_id == model.PurchaseOrderItemsList[k].Product_id && model.PurchaseOrderItemsList[k].Quantity < model1.PurchaseOrderItemsList[k].Received_Qty) { model1.PurchaseOrder.Order_Status = "Open"; model1.PurchaseOrder.TargetDocId = Convert.ToString(model.PurchaseOrder.Purchase_Order_Id); // model.PurchaseOrderItemsList[k].BaseDocLink = "N"; model1.PurchaseOrderItemsList[k].Purchase_OrderItem_Id = model1.PurchaseOrderItemsList[k].Purchase_OrderItem_Id; model1.PurchaseOrderItemsList[k].Purchase_Order_Id = model1.PurchaseOrderItemsList[k].Purchase_Order_Id; //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date; model1.PurchaseOrderItemsList[k].Received_Qty = Convert.ToInt32(model.PurchaseOrderItemsList[k].Received_Qty) + model1.PurchaseOrderItemsList[k].Quantity; model1.PurchaseOrderItemsList[k].Product_id = model.PurchaseOrderItemsList[k].Product_id; model1.PurchaseOrderItemsList[k].Unit_price = model.PurchaseOrderItemsList[k].Unit_price; model1.PurchaseOrderItemsList[k].Discount_percent = model.PurchaseOrderItemsList[k].Discount_percent; model1.PurchaseOrderItemsList[k].Vat_Code = model.PurchaseOrderItemsList[k].Vat_Code; } } //model1.PurchaseOrder.Creating_Branch = 1; model1.PurchaseOrder.Created_Branc_Id = CurrentBranchId; //currentUser.Created_Branch_Id; model1.PurchaseOrder.Created_Date = DateTime.Now; model1.PurchaseOrder.Created_User_Id = CurrentUser.Id; //currentUser.Created_User_Id; //GetUserId() //model1.PurchaseOrder.Modified_User_Id = CurrentUser.Id;//currentUser.Modified_User_Id; //model1.PurchaseOrder.Modified_Date = DateTime.Now; //model1.PurchaseOrder.Modified_Branch_Id = CurrentBranchId;//currentUser.Modified_Branch_Id; goodsrepository.UpdateQuotationorder(model1.PurchaseOrder, model1.PurchaseOrderItemsList, ref ErrorMessage); return(RedirectToAction("Index", "GoodsReceipt")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } } } else if (submitButton == "Update") { model.goodreceipt.Document_Date = DateTime.Now; model.goodreceipt.Document_Date = model.goodreceipt.Posting_Date; model.goodreceipt.Modified_Branch_Id = CurrentBranchId; //CurrentBranchId; model.goodreceipt.Modified_Dte = DateTime.Now; model.goodreceipt.Modified_User_Id = CurrentUser.Id; //CurrentUser.Id; model.goodreceipt.TargetDocId = "1"; for (int i = 0; i < model.goodreceiptitemlist.Count; i++) { //model.goodreceiptitemlist[i].Goods_Receipt_Id = model.goodreceipt.Goods_Receipt_Id; model.goodreceiptitemlist[i].BaseDocLink = "N"; } if (goodsrepository.UpdateQuotation(model.goodreceipt, model.goodreceiptitemlist, ref ErrorMessage)) { return(RedirectToAction("Index", "GoodsReceipt")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } return(RedirectToAction("Index", "GoodsReceipt")); } catch (OptimisticConcurrencyException ex) { ObjectStateEntry entry = ex.StateEntries[0]; GoodsReceipt post = entry.Entity as GoodsReceipt; //Post is the entity name he is using. Rename it with yours Console.WriteLine("Failed to save {0} because it was changed in the database", post.Purchase_Order_Id); return(View("Error")); } //catch (Exception ex) //{ // ExceptionHandler.LogException(ex); // ViewBag.AppErrorMessage = ex.Message; // return View("Error"); //} }
/// <summary>Constructor.</summary> /// <param name="parent">The audit parent.</param> /// <param name="entry">The object state entry.</param> #if EF5 || EF6 public AuditEntry(Audit parent, ObjectStateEntry entry)
private static IRelatedEnd GetRelatedEnd(ObjectStateEntry entry, ObjectStateEntry relationEntry) { return(entry.RelationshipManager .GetAllRelatedEnds() .First(r => r.RelationshipSet == relationEntry.EntitySet)); }
public static List <BusinessObjectStructure> GetTableFields(Type currentType, ObjectStateEntry entry) { if (entry.Entity.GetType() != currentType) { throw new ApplicationException(string.Format( "GetTableFields was called for '{0}' with a '{1}'", currentType, entry.Entity.GetType())); } List <BusinessObjectStructure> _tableFields = new List <BusinessObjectStructure>(); EntityType currentEntityType = GetEntityType(currentType, entry); // find all properities in the cspace foreach (FieldMetadata prop in entry.CurrentValues.DataRecordInfo.FieldMetadata) { EdmProperty prop2 = currentEntityType.Properties[prop.FieldType.Name]; if (prop.FieldType.BuiltInTypeKind != BuiltInTypeKind.ComplexType) { PropertyInfo currentProperty = GetPropertyInfo(currentType, prop2.Name); // don't add hidden properities if (currentProperty == null) { continue; } _tableFields.Add(new Adage.EF.Interfaces.BusinessObjectStructure( currentProperty.PropertyType, prop.FieldType.Name, prop2.Nullable, 0, true, prop.Ordinal, currentProperty)); } } //find all properities marked as DataObjectField PropertyInfo[] props; props = currentType.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (System.Reflection.PropertyInfo propInfo in props) { AddDataObjectFieldProperties(_tableFields, propInfo); } PropertyInfo[] childProps; childProps = currentType.BaseType.GetProperties(BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public); foreach (PropertyInfo propInfo in childProps) { AddDataObjectFieldProperties(_tableFields, propInfo); } return(_tableFields); }
partial void OnBorrar(ObjectStateEntry entry);
public void OnAgregarBase(ObjectStateEntry entry) { OnAgregar(entry); }
public void aggiungiUnaRigaAdUnCarrelloEsistente() { int countRigheCarrello = 0; Carrello carrelloCorrente; using (LumenEntities dbContext = new LumenEntities()) { carrelloCorrente = dbContext.Carrelli.Include("righeCarrello").Take(1).Single(); countRigheCarrello = carrelloCorrente.righeCarrello.Count(); } FormatoCarta formato; using (LumenEntities dbContext = new LumenEntities()) { formato = dbContext.FormatiCarta.First(); } Fotografia fotografia; using (LumenEntities dbContext = new LumenEntities()) { fotografia = dbContext.Fotografie.Include("fotografo").Where(f => f.fotografo != null).First(); } Fotografo fotografo; using (LumenEntities dbContext = new LumenEntities()) { fotografo = dbContext.Fotografi.First(); } using (LumenEntities dbContext = new LumenEntities()) { var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext; objectContext.AttachTo("Carrelli", carrelloCorrente); ObjectStateEntry s1 = objectContext.ObjectStateManager.GetObjectStateEntry(carrelloCorrente); objectContext.AttachTo("FormatiCarta", formato); ObjectStateEntry s2 = objectContext.ObjectStateManager.GetObjectStateEntry(formato); objectContext.AttachTo("Fotografie", fotografia); ObjectStateEntry s3 = objectContext.ObjectStateManager.GetObjectStateEntry(fotografia); // ======= Occhio qui !!!! poi ti spiego ===== if (fotografo.id.Equals(fotografia.fotografo.id)) { fotografo = fotografia.fotografo; } else { objectContext.AttachTo("Fotografi", fotografo); } ObjectStateEntry s4 = objectContext.ObjectStateManager.GetObjectStateEntry(fotografo); // ======= Occhio qui !!!! poi ti spiego ===== RigaCarrello riga = objectContext.CreateObject <RigaCarrello>(); riga.id = Guid.NewGuid(); riga.discriminator = RigaCarrello.TIPORIGA_STAMPA; riga.prezzoLordoUnitario = new Decimal(5); riga.quantita = 3; riga.prezzoNettoTotale = Decimal.Multiply(riga.prezzoLordoUnitario, riga.quantita); riga.descrizione = "SaveCarrelloLodingTest"; riga.totFogliStampati = 3; riga.prodotto = formato; riga.fotografo = fotografo; riga.fotografia = fotografia; carrelloCorrente.righeCarrello.Add(riga); s1 = objectContext.ObjectStateManager.GetObjectStateEntry(carrelloCorrente); int quanti = dbContext.SaveChanges(); } // Controllo che le righe siano aumentate di uno. using (LumenEntities dbContext = new LumenEntities()) { var testCarrello2 = dbContext.Carrelli.Include("righeCarrello").Where(c => c.id == carrelloCorrente.id).Single(); Assert.IsTrue(countRigheCarrello + 1 == testCarrello2.righeCarrello.Count); } }
partial void OnModificar(ObjectStateEntry entry);
private static bool IsDomainEntity(ObjectStateEntry entry) { return(typeof(Entity).IsAssignableFrom(ObjectContext.GetObjectType(entry.Entity.GetType()))); }
/// <summary>Checks if the entity is audited.</summary> /// <param name="entry">The entry.</param> /// <returns>true if the entity is audited, false if not.</returns> #if EF5 || EF6 public bool IsAuditedEntity(ObjectStateEntry entry)
public virtual bool IsTargetEntity(ObjectStateEntry item) { return(item.State != EntityState.Detached && TargetType.IsInstanceOfType(item.Entity)); }
/// <summary> /// Finds the foreign key related ends for a property, if any /// </summary> /// <param name="objectStateEntry"></param> /// <param name="propertyName"></param> /// <returns></returns> private static IEnumerable <IRelatedEnd> GetDependentForeignKeyRelatedEndsForProperty(ObjectStateEntry objectStateEntry, string propertyName) { return(objectStateEntry.RelationshipManager.GetAllRelatedEnds().Where(x => { if (!(x is EntityReference)) // we only handle entity references; we can't handle entity collections { return false; } var associationType = ((AssociationType)x.RelationshipSet.ElementType); if (associationType == null) { return false; } var referentialConstraints = associationType.ReferentialConstraints; return associationType.IsForeignKey && referentialConstraints.Any(c => c.ToProperties.Contains(propertyName)); }).ToList()); }
private static ObjectStateEntry GetEntityEntryFromRelation(ObjectContext context, ObjectStateEntry relationEntry, int index) { var firstKey = (EntityKey)relationEntry.OriginalValues[index]; var entry = context.ObjectStateManager.GetObjectStateEntry(firstKey); if (entry.Entity == null) { // This hilariously populates the Entity if it was null... context.GetObjectByKey(firstKey); } return(entry); }
internal CurrentValueRecord(ObjectStateEntry cacheEntry) : base(cacheEntry) { }
public List <AuditingDetail> GetAuditEntries(ObjectStateEntry objectStateEntry) { List <AuditingDetail> auditDetails = new List <AuditingDetail>(); var allProperties = getAllProperties(objectStateEntry); var modifiedProperties = objectStateEntry.GetModifiedProperties(); var currentValues = objectStateEntry.CurrentValues; if (objectStateEntry.State == EntityState.Added) { foreach (var propertyName in allProperties) { // Add whole entry to database auditDetails.Add(new AuditingDetail() { ColumnName = propertyName.Key.ToString(), OldValue = null, NewValue = currentValues[propertyName.Key.ToString()].ToString() }); } } else if (objectStateEntry.State == EntityState.Modified) { var originalValues = objectStateEntry.OriginalValues; // If object was in Modified state and property is Deleted => records has been Deleted // Record all of its properties to Audit if (currentValues[modifiedProperties.First()].ToString() == ("Deleted").ToLower()) { foreach (var propertyName in allProperties) { auditDetails.Add(new AuditingDetail() { ColumnName = propertyName.Key.ToString(), OldValue = originalValues[propertyName.Key.ToString()].ToString(), NewValue = null }); } } else { // Loop modified properties and make audit foreach (var propertyName in modifiedProperties) { // write Decision date everytime if (!currentValues[propertyName].Equals(originalValues[propertyName]) || propertyName == "ChangeDate") { string oldValue = originalValues[propertyName].ToString(); string newValue = currentValues[propertyName].ToString(); if (oldValue.Length > 0 && oldValue != "DELETED-VALUE" && newValue == "") { newValue = "DELETED-VALUE"; } // Add only modified properties auditDetails.Add(new AuditingDetail() { ColumnName = propertyName, OldValue = oldValue, NewValue = newValue }); } } } } return(auditDetails); }
/// <summary>Gets the state of the entity modified (EntityModified, EntitySoftAdded, EntitySoftDeleted).</summary> /// <param name="entry">The entry.</param> /// <returns>The state of the entity modified (EntityModified, EntitySoftAdded, EntitySoftDeleted).</returns> #if EF5 || EF6 public AuditEntryState GetEntityModifiedState(ObjectStateEntry entry)
/// <summary>Format a value for the specified entry and property name.</summary> /// <param name="entry">The entry.</param> /// <param name="propertyName">The property name.</param> /// <returns>The formatted value.</returns> #if EF5 || EF6 public string FormatValue(ObjectStateEntry entry, string propertyName, object currentValue)
public void OnModificarBase(ObjectStateEntry entry) { OnModificar(entry); }
private static bool IsMemberOfObjectSet <TElement>(ObjectSet <TElement> objectSet, ObjectStateEntry entry) where TElement : class { return(!entry.IsRelationship && // must be an entity null != entry.Entity && // must not be a key entry entry.EntitySet == objectSet.EntitySet); // must belong to the current set }
public void OnBorrarBase(ObjectStateEntry entry) { OnBorrar(entry); }
public ActionResult Index(string submitButton, SalesDeliveryViewModels model, HttpPostedFileBase file = null) { try { //ApplicationUser currentUser = ApplicationUserManager.GetApplicationUser(User.Identity.Name, HttpContext.GetOwinContext()); if (submitButton == "Save") { model.salesdelivery.Document_Date = DateTime.Now; model.salesdelivery.Posting_Date = DateTime.Now; model.salesdelivery.Branch = CurrentBranchId; model.salesdelivery.Doc_Status = "Open"; model.salesdelivery.TargetDocId = "0"; model.salesdelivery.Created_Branc_Id = CurrentBranchId; //CurrentBranchId; model.salesdelivery.Created_Date = DateTime.Now; model.salesdelivery.Created_User_Id = CurrentUser.Id; //CurrentUser.Id; var OrderList = model.salesdeliverytitemlist.Where(x => x.IsDummy == 0); model.salesdeliverytitemlist = OrderList.ToList(); for (int i = 0; i < model.salesdeliverytitemlist.Count; i++) { model.salesdeliverytitemlist[i].BaseDocLink = "N"; //model.goodreceiptitemlist[i].Product_id = model.PurchaseOrderItemsList[i].Product_id; //model.goodreceiptitemlist[i].Quantity = model.PurchaseOrderItemsList[i].Quantity; //model.goodreceiptitemlist[i].Unit_price = model.PurchaseOrderItemsList[i].Unit_price; //model.goodreceiptitemlist[i].Discount_percent = model.PurchaseOrderItemsList[i].Discount_percent; //model.goodreceiptitemlist[i].Vat_Code = model.PurchaseOrderItemsList[i].Vat_Code; //model.goodreceiptitemlist[i].Freight_Loading = Convert.ToDecimal(model.PurchaseOrderItemsList[i].Freight_Loading); } if (deliveryrepository.AddNewQuotation(model.salesdelivery, model.salesdeliverytitemlist, ref ErrorMessage)) { return(RedirectToAction("Index", "SalesDelivery")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } else if (submitButton == "Save ") { SalesDeliveryViewModels model1 = new SalesDeliveryViewModels(); model1.BranchList = deliveryrepository.GetAddressbranchList().ToList(); model1.BussinessList = deliveryrepository.GetAddressbusinessList().ToList(); model1.productlist = deliveryrepository.GetProductList(); model1.VATList = deliveryrepository.GetVATList(); model1.salesorder = deliveryrepository.FindOneQuotationById1(model.salesorder.Sales_Order_Id); model1.salesorderitemlist = deliveryrepository.FindOneQuotationItemById1(model.salesorder.Sales_Order_Id); // model1.PurchaseOrderItems = goodsrepository.FindOneQuotationItemById1(model.PurchaseOrderList.FirstOrDefault().Purchase_Order_Id); if (model1.salesorder.Customer == model.salesorder.Customer) { //for BaseDocId for (int j = 0; j < model.salesorderitemlist.Count; j++) { if (model1.salesorderitemlist[j].Product_id == model.salesorderitemlist[j].Product_id) { model.salesdelivery.BaseDocId = model.salesorder.Sales_Order_Id; } } //for BaseDocLink for (int j = 0; j < model.salesorderitemlist.Count; j++) { if (model1.salesorderitemlist[j].Product_id == model.salesorderitemlist[j].Product_id) { model.salesdeliverytitemlist[j].BaseDocLink = "Y"; } else { model.salesdeliverytitemlist[j].BaseDocLink = "N"; } model.salesdelivery.Doc_Status = "Open"; model.salesdelivery.Remarks = Convert.ToString(model.salesorder.Sales_Order_Id); model.salesdelivery.Created_Branc_Id = CurrentBranchId; //CurrentBranchId; model.salesdelivery.Created_Date = DateTime.Now; model.salesdelivery.Created_User_Id = CurrentBranchId; //CurrentUser.Id; model.salesdelivery.Sales_Delivery_Id = model.salesorder.Sales_Order_Id; model.salesdelivery.Reference_Number = model.salesorder.Reference_Number; model.salesdelivery.Customer = model.salesorder.Customer; //model.salesorder.Doc_Status = model.PurchaseOrder.Order_Status; model.salesdelivery.Posting_Date = model.salesorder.Posting_Date; model.salesdelivery.Delivery_Date = model.salesorder.Delivery_Date; // model.salesorder.Delivery_Date = model.SalesQuotation.Delivery_Date; model.salesdelivery.Document_Date = model.salesorder.Document_Date; model.salesdelivery.Branch = model.salesorder.Branch; model.salesdelivery.TotalBefDocDisc = model.salesorder.TotalBefDocDisc; model.salesdelivery.DocDiscAmt = model.salesorder.DocDiscAmt; model.salesdelivery.TotalSlsDlvryAmt = model.salesorder.TotalOrdAmt; model.salesdelivery.TaxAmt = model.salesorder.TaxAmt; model.salesdelivery.TargetDocId = "0"; //model.PurchaseOrder.BaseDocId = qq; var Goodslist = model.salesorderitemlist.Where(x => x.IsDummy == 0); model.salesorderitemlist = Goodslist.ToList(); for (int i = 0; i < model.salesorderitemlist.Count; i++) { //model.salesdeliverytitemlist[i].BaseDocLink = "Y"; model.salesdeliverytitemlist[i].Product_Id = model.salesorderitemlist[i].Product_id; model.salesdeliverytitemlist[i].Quantity = model.salesorderitemlist[i].Quantity; model.salesdeliverytitemlist[i].Unit_Price = model.salesorderitemlist[i].Unit_price; model.salesdeliverytitemlist[i].Discount_Precent = model.salesorderitemlist[i].Discount_percent; model.salesdeliverytitemlist[i].Vat_Code = Convert.ToInt16(model.salesorderitemlist[i].Vat_Code); // model.goodreceiptitemlist[i].Freight_Loading = Convert.ToDecimal(model.SalesQuotationItemList[i].Freight_Loading); } if (deliveryrepository.AddNewQuotation(model.salesdelivery, model.salesdeliverytitemlist, ref ErrorMessage)) { for (int k = 0; k < model.salesorderitemlist.Count; k++) { if (model1.salesorderitemlist[k].Product_id == model.salesorderitemlist[k].Product_id && model.salesorderitemlist[k].Quantity >= model1.salesorderitemlist[k].Delivered_Qty) { model1.salesorder.Order_Status = "Closed"; //model1.PurchaseOrder.TargetDocId = Convert.ToString(model.PurchaseOrder.Purchase_Order_Id); if (model1.salesorder.TargetDocId == "") { model1.salesorder.TargetDocId = Convert.ToString(model.salesorder.Sales_Order_Id); } else { model1.salesorder.TargetDocId = model1.salesorder.TargetDocId + "," + Convert.ToString(model.salesorder.Sales_Order_Id); } // model.PurchaseOrderItemsList[k].BaseDocLink = "N"; model1.salesorderitemlist[k].Sale_Orderitem_Id = model1.salesorderitemlist[k].Sale_Orderitem_Id; model1.salesorderitemlist[k].Sales_Order_Id = model1.salesorderitemlist[k].Sales_Order_Id; //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date; model1.salesorderitemlist[k].Delivered_Qty = Convert.ToInt32(model.salesorderitemlist[k].Quantity); model1.salesorderitemlist[k].Product_id = model.salesorderitemlist[k].Product_id; model1.salesorderitemlist[k].Unit_price = model.salesorderitemlist[k].Unit_price; model1.salesorderitemlist[k].Discount_percent = model.salesorderitemlist[k].Discount_percent; model1.salesorderitemlist[k].Vat_Code = model.salesorderitemlist[k].Vat_Code; } else if (model1.salesorderitemlist[k].Product_id == model.salesorderitemlist[k].Product_id && model.salesorderitemlist[k].Quantity < model1.salesorderitemlist[k].Delivered_Qty) { model1.salesorder.Order_Status = "Open"; model1.salesorder.TargetDocId = Convert.ToString(model.salesorder.Sales_Order_Id); // model.PurchaseOrderItemsList[k].BaseDocLink = "N"; model1.salesorderitemlist[k].Sale_Orderitem_Id = model1.salesorderitemlist[k].Sale_Orderitem_Id; model1.salesorderitemlist[k].Sales_Order_Id = model1.salesorderitemlist[k].Sales_Order_Id; //model1.PurchaseOrderItemsList[j].Quoted_date = model1.PurchaseOrderItemsList[j].Quoted_date; model1.salesorderitemlist[k].Delivered_Qty = Convert.ToInt32(model.salesorderitemlist[k].Quantity); model1.salesorderitemlist[k].Product_id = model.salesorderitemlist[k].Product_id; model1.salesorderitemlist[k].Unit_price = model.salesorderitemlist[k].Unit_price; model1.salesorderitemlist[k].Discount_percent = model.salesorderitemlist[k].Discount_percent; model1.salesorderitemlist[k].Vat_Code = model.salesorderitemlist[k].Vat_Code; } } //model1.PurchaseOrder.Creating_Branch = 1; model1.salesorder.Created_Branc_Id = CurrentBranchId; //currentUser.Created_Branch_Id; model1.salesorder.Created_Date = DateTime.Now; model1.salesorder.Created_User_Id = CurrentUser.Id; //currentUser.Created_User_Id; //GetUserId() model1.salesorder.Modified_User_Id = CurrentUser.Id; //currentUser.Modified_User_Id; model1.salesorder.Modified_Date = DateTime.Now; model1.salesorder.Modified_Branch_Id = CurrentBranchId; //currentUser.Modified_Branch_Id; deliveryrepository.Updateorder(model1.salesorder, model1.salesorderitemlist, ref ErrorMessage); return(RedirectToAction("Index", "SalesDelivery")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } } } else if (submitButton == "Update") { // model.salesdelivery.Reference_Number = model.salesorder.Reference_Number; model.salesdelivery.Modified_Branc_Id = CurrentBranchId; //CurrentBranchId; model.salesdelivery.Modified_Date = DateTime.Now; model.salesdelivery.Modified_User_Id = CurrentUser.Id; //CurrentUser.Id; model.salesdelivery.TargetDocId = "1"; for (int i = 0; i < model.salesdeliverytitemlist.Count; i++) { // model.salesdeliverytitemlist[i].Sales_Delivery_Id = model.salesdelivery.Sales_Delivery_Id; model.salesdeliverytitemlist[i].BaseDocLink = "N"; } if (deliveryrepository.UpdateQuotation(model.salesdelivery, model.salesdeliverytitemlist, ref ErrorMessage)) { return(RedirectToAction("Index", "SalesDelivery")); } else { ViewBag.AppErrorMessage = ErrorMessage; return(View("Error")); } } return(RedirectToAction("Index", "SalesDelivery")); } catch (OptimisticConcurrencyException ex) { ObjectStateEntry entry = ex.StateEntries[0]; SalesDelivery post = entry.Entity as SalesDelivery; //Post is the entity name he is using. Rename it with yours Console.WriteLine("Failed to save {0} because it was changed in the database", post.Sales_Delivery_Id); return(View("Error")); } //catch (Exception ex) //{ // ExceptionHandler.LogException(ex); // ViewBag.AppErrorMessage = ex.Message; // return View("Error"); //} }
/// <summary>Gets the state of the entity modified (EntityModified, EntitySoftAdded, EntitySoftDeleted).</summary> /// <param name="entry">The entry.</param> /// <returns>The state of the entity modified (EntityModified, EntitySoftAdded, EntitySoftDeleted).</returns> #if EF5 || EF6 public AuditEntryState GetEntityModifiedState(ObjectStateEntry entry)
/// <summary>Checks if the entity is audited.</summary> /// <param name="entry">The entry.</param> /// <returns>true if the entity is audited, false if not.</returns> #if EF5 || EF6 public bool IsAuditedEntity(ObjectStateEntry entry)
partial void OnAgregar(ObjectStateEntry entry);
private void AuditEntity() { var modifieds = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified || e.State == EntityState.Added); var currentUser = string.Empty; if (HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity != null) { currentUser = HttpContext.Current.User.Identity.Name; } DateTime now = DateTime.Now; foreach (DbEntityEntry item in modifieds) { if (item.Entity is IAuditable changedOrAddedItem) { if (item.State == EntityState.Added) { changedOrAddedItem.CreatedDate = now; // When using user manager Http context is null so not update the current user with string empty if (!string.IsNullOrEmpty(currentUser)) { changedOrAddedItem.CreatedBy = currentUser; } } changedOrAddedItem.UpdatedDate = now; // When using user manager Http context is null so not update the current user with string empty if (!string.IsNullOrEmpty(currentUser)) { changedOrAddedItem.UpdatedBy = currentUser; } if (item.State == EntityState.Modified && item.Entity is IFieldChangeLog logItem) { ObjectContext objContext = ((IObjectContextAdapter)this).ObjectContext; ObjectStateEntry objState = objContext.ObjectStateManager.GetObjectStateEntry(item.Entity); string primaryKeyName = objState.EntitySet.ElementType.KeyMembers.Select(k => k.Name).FirstOrDefault(); string id = !string.IsNullOrEmpty(primaryKeyName) ? item.CurrentValues[primaryKeyName].ToString() : string.Empty; List <FieldChangeLogDetail> changeLogs = new List <FieldChangeLogDetail>(); IEnumerable <string> modifiedProperties = objState.GetModifiedProperties(); foreach (var propName in modifiedProperties) { changeLogs.Add(new FieldChangeLogDetail { Field = propName, PreviousValue = objState.OriginalValues[propName].ToString(), UpdatedValue = objState.CurrentValues[propName].ToString() }); } string changeLog = JsonConvert.SerializeObject(changeLogs); this.FieldChangeLogs.Add(new FieldChangeLog { Entity = ObjectContext.GetObjectType(item.Entity.GetType()).Name, EntityId = id, ChangeLog = changeLog, Action = logItem.LatestAction, CreatedBy = currentUser, CreatedDate = now, UpdatedBy = currentUser, UpdatedDate = now }); } } } }
/// <summary> /// Returns the entity set name for the given object state entry. /// </summary> /// <param name="entry">object state entry for the object whose entity set name needs to be retreived.</param> /// <param name="defaultContainerName">default container name.</param> /// <returns>entity set name for the given entity entry.</returns> private static string GetEntitySetName(ObjectStateEntry entry, string defaultContainerName) { return ObjectContextServiceProvider.GetEntitySetName( entry.EntitySet.Name, entry.EntitySet.EntityContainer.Name, entry.EntitySet.EntityContainer.Name == defaultContainerName); }
/// <summary> /// Gets either CurrentValues or OriginalValues depending on which the entry /// makes available. (e.g. entries that are Added have no OriginalValues, and /// entries that are Deleted only have OriginalValues). /// </summary> private IExtendedDataRecord useableValues(ObjectStateEntry entry) { return(entry.State == EntityState.Deleted ? (IExtendedDataRecord)entry.OriginalValues : entry.CurrentValues); }
/// <summary>Audit relationship added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> #if EF5 || EF6 public static void AuditRelationAdded(Audit audit, ObjectStateEntry objectStateEntry)
/// <summary>Audit entity added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> #if EF5 || EF6 public static void AuditEntityAdded(Audit audit, ObjectStateEntry objectStateEntry)
/// <summary>Check if the property name is audited.</summary> /// <param name="entry">The entry.</param> /// <param name="propertyName">The property name.</param> /// <returns>true if the property name is audited, false if not.</returns> #if EF5 || EF6 public bool IsAuditedProperty(ObjectStateEntry entry, string propertyName)
/// <summary> /// Updates each entry in the ChangeSet with its corresponding conflict info. /// </summary> /// <param name="operationConflictMap">Map of conflicts to their corresponding operations entries.</param> private void SetChangeSetConflicts(Dictionary <DbEntityEntry, ChangeSetEntry> operationConflictMap) { object storeValue; EntityKey refreshEntityKey; ObjectContext objectContext = ((IObjectContextAdapter)this.DbContext).ObjectContext; ObjectStateManager objectStateManager = objectContext.ObjectStateManager; if (objectStateManager == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DbResource.ObjectStateManagerNotFoundException, this.DbContext.GetType().Name)); } foreach (var conflictEntry in operationConflictMap) { DbEntityEntry entityEntry = conflictEntry.Key; ObjectStateEntry stateEntry = objectStateManager.GetObjectStateEntry(entityEntry.Entity); if (stateEntry.State == EntityState.Unchanged) { continue; } // Note: we cannot call Refresh StoreWins since this will overwrite Current entity and remove the optimistic concurrency ex. ChangeSetEntry operationInConflict = conflictEntry.Value; refreshEntityKey = this.RefreshContext.CreateEntityKey(stateEntry.EntitySet.Name, stateEntry.Entity); this.RefreshContext.TryGetObjectByKey(refreshEntityKey, out storeValue); operationInConflict.StoreEntity = storeValue; // StoreEntity will be null if the entity has been deleted in the store (i.e. Delete/Delete conflict) bool isDeleted = (operationInConflict.StoreEntity == null); if (isDeleted) { operationInConflict.IsDeleteConflict = true; } else { // Determine which members are in conflict by comparing original values to the current DB values PropertyDescriptorCollection propDescriptors = TypeDescriptor.GetProperties(operationInConflict.Entity.GetType()); List <string> membersInConflict = new List <string>(); object originalValue; PropertyDescriptor pd; for (int i = 0; i < stateEntry.OriginalValues.FieldCount; i++) { originalValue = stateEntry.OriginalValues.GetValue(i); if (originalValue is DBNull) { originalValue = null; } string propertyName = stateEntry.OriginalValues.GetName(i); pd = propDescriptors[propertyName]; if (pd == null) { // This might happen in the case of a private model // member that isn't mapped continue; } if (!object.Equals(originalValue, pd.GetValue(operationInConflict.StoreEntity))) { membersInConflict.Add(pd.Name); } } operationInConflict.ConflictMembers = membersInConflict; } } }
/// <summary>Audit entity deleted.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> #if EF5 || EF6 public static void AuditEntityDeleted(Audit audit, ObjectStateEntry objectStateEntry)
/// <summary>Audit entity modified.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> #if EF5 || EF6 public static void AuditEntityModified(Audit audit, ObjectStateEntry objectStateEntry, AuditEntryState state)
/// <summary>Audit relationship added.</summary> /// <param name="audit">The audit to use to add changes made to the context.</param> /// <param name="objectStateEntry">The object state entry.</param> #if EF5 || EF6 public static void AuditRelationAdded(Audit audit, ObjectStateEntry objectStateEntry)
/// <summary>Check if the property name is audited.</summary> /// <param name="entry">The entry.</param> /// <param name="propertyName">The property name.</param> /// <returns>true if the property name is audited, false if not.</returns> #if EF5 || EF6 public bool IsAuditedProperty(ObjectStateEntry entry, string propertyName)
internal CurrentValueRecord(ObjectStateEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject) : base(cacheEntry, metadata, userObject) { }
public StateEntryAdapter(ObjectStateEntry stateEntry) { DebugCheck.NotNull(stateEntry); _stateEntry = stateEntry; }
/// <summary>Format a value for the specified entry and property name.</summary> /// <param name="entry">The entry.</param> /// <param name="propertyName">The property name.</param> /// <returns>The formatted value.</returns> #if EF5 || EF6 public string FormatValue(ObjectStateEntry entry, string propertyName, object currentValue)
/// <summary> /// 更新数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Update(tblUser UserNew) { tblUser UserOld; int counts = 0;//影响行数标记 using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { UserOld = MWDB.tblUser.FirstOrDefault(t => t.UserID == UserNew.UserID); //更新数据字段 UserOld.UserName = UserNew.UserName; UserOld.LoginName = UserNew.LoginName; UserOld.LoginPwd = UserNew.LoginPwd; UserOld.UserCode = UserNew.UserCode; UserOld.State = UserNew.State; UserOld.Email = UserNew.Email; UserOld.Desc = UserNew.Desc; UserOld.Avatar = UserNew.Avatar; //获取当前登录用户的ID(Cookies) string strUserID = HttpContext.Current.User.Identity.Name; if (string.IsNullOrEmpty(strUserID)) { FormsAuthentication.RedirectToLoginPage(); return(false); } UserOld.LastModifiedByID = new Guid(strUserID); DateTime dates = System.DateTime.Now; UserOld.LastModifiedDate = dates; UserOld.SystemModstamp = dates; ObjectStateEntry ose = MWDB.ObjectStateManager.GetObjectStateEntry(UserOld); IEnumerable <string> list = ose.GetModifiedProperties(); string logBody = string.Empty; foreach (string pr in list) { string strs = pr;//更新实体的属性名 string strNew = ose.CurrentValues[strs].ToString(); string strOld = ose.OriginalValues[strs].ToString(); if (strNew != strOld) { strNew = string.IsNullOrEmpty(strNew) ? "null" : strNew;//如果字符串为空,则将null赋给字符串 strOld = string.IsNullOrEmpty(strOld) ? "null" : strOld; switch (strs) { case "LastModifiedByID": //系统字段不进行发送 break; case "LastModifiedDate": //系统字段不进行发送 break; case "SystemModstamp": //系统字段不进行发送 break; default: logBody += ", " + strs + ": '" + strOld + "'" + " had been changed '" + strNew + "'"; break; } } } counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Update user info failed! User update log: '" + logBody + "'. User host address: '" + userHostAddress + "' ."); return(true); } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Update user info failed! User id: '" + UserNew.UserID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return(false); } } return(false); }