protected virtual bool SetValue <T>(T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = "") { CheckDeleted(); if (current.TryGetValue(propertyName, out object oldValue)) { if (object.Equals(oldValue, value)) { return(false); } } if (// Property was populated previously, this is a change (current.ContainsKey(propertyName)) // Property was never loaded, but since the model was requested we consider this as a changed property || (this is IRequestable && (this as IRequestable).Requested && !(typeof(T).ImplementsInterface(typeof(IManageableCollection)))) ) { // Call ValidateHandler in case of an update bool updateField = true; if (ValidateUpdateHandler != null) { var fieldUpdateRequest = new PropertyUpdateRequest(propertyName, value); ValidateUpdateHandler.Invoke(fieldUpdateRequest); if (!fieldUpdateRequest.Cancelled) { value = (T)fieldUpdateRequest.Value; } else { updateField = false; if (!string.IsNullOrEmpty(fieldUpdateRequest.CancellationReason)) { //TODO: log message } } } if (updateField) { // We're changing this property if (!initial.ContainsKey(propertyName)) { initial[propertyName] = value; } current[propertyName] = value; changes.Add(propertyName); } } else { // initial load current[propertyName] = value; } return(true); }
public async Task <IActionResult> Update(PropertyUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var affectedResult = await _ownerPropertyService.Update(request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }
public async Task <int> Update(PropertyUpdateRequest request) { var property = await _context.Properties.FindAsync(request.Id); if (property == null) { throw new RealEstateException($"Không thể tìm thấy mã tin: {request.Id}"); } property.Title = request.Title; property.ApartmentNumber = request.ApartmentNumber; property.StreetNames = request.StreetNames; property.WardId = request.WardId; property.Area = request.Area; property.AreaFrom = request.AreaFrom; property.AreaTo = request.AreaTo; property.Length = request.Length; property.Width = request.Width; property.Facade = request.Facade; property.Price = request.Price; property.PriceFrom = request.PriceFrom; property.PriceTo = request.PriceTo; property.Description = request.Description; property.EvaluationStatusId = request.EvaluationStatusId; property.LegalPapersId = request.LegalPapersId; property.NumberOfStoreys = request.NumberOfStoreys; property.NumberOfBedrooms = request.NumberOfBedrooms; property.NumberOfWCs = request.NumberOfWCs; property.HouseDirectionId = request.HouseDirectionId; property.Lat = request.Lat; property.Lng = request.Lng; if (request.ThumbnailImage != null) { var thumbnailImage = await _context.PropertyImages.FirstOrDefaultAsync(i => i.IsDefault == true && i.PropertyId == request.Id); if (thumbnailImage != null) { thumbnailImage.FileSize = request.ThumbnailImage.Length; thumbnailImage.LinkName = await this.SaveFile(request.ThumbnailImage); _context.PropertyImages.Update(thumbnailImage); } } return(await _context.SaveChangesAsync()); }