public async Task <PropertyModel> AddPropertyAsync(PropertyModel model, ICollection <PropertyDocumentTypeModel> propDocType, ICollection <ImagePickerResult> docs) { using (var dataService = DataServiceFactory.CreateDataService()) { var property = new Property(); List <PropertyDocumentType> propertyDocumentTypeList = new List <PropertyDocumentType>(); var propertyDoc = propDocType.First(); var propertyDocumentType = new PropertyDocumentType(); UpdatePropertyDocumentTypeFromModel(propertyDocumentType, propertyDoc); if (propertyDoc.PropertyDocuments != null && propertyDoc.PropertyDocuments.Count > 0) { List <PropertyDocuments> docList = new List <PropertyDocuments>(); foreach (var obj in propertyDoc.PropertyDocuments) { var doc = new PropertyDocuments(); UpdateDocumentFromModel(doc, obj); docList.Add(doc); } propertyDocumentType.PropertyDocuments = docList; } propertyDocumentTypeList.Add(propertyDocumentType); property.PropertyDocumentType = propertyDocumentTypeList; UpdatePropertyFromModel(property, model); property.PropertyGuid = Guid.NewGuid(); property.GroupGuid = (model.GroupGuid == null || model.GroupGuid == Guid.Empty) ? Guid.NewGuid() : model.GroupGuid;// For Grouping property var propertyID = await dataService.AddPropertyAsync(property); model.Merge(await GetPropertyAsync(dataService, propertyID)); return(model); } }
public async Task <PropertyModel> UpdatePropertyAsync(PropertyModel model, ICollection <PropertyDocumentTypeModel> propDocType, ICollection <ImagePickerResult> docs) { using (var dataService = DataServiceFactory.CreateDataService()) { var property = new Property(); List <PropertyDocumentType> propertyDocumentTypeList = new List <PropertyDocumentType>(); foreach (var propertyDoc in propDocType) { var propertyDocumentType = new PropertyDocumentType(); UpdatePropertyDocumentTypeFromModel(propertyDocumentType, propertyDoc); if (propertyDoc.PropertyDocuments != null && propertyDoc.PropertyDocuments.Count > 0) { List <PropertyDocuments> docList = new List <PropertyDocuments>(); foreach (var obj in propertyDoc.PropertyDocuments) { var doc = new PropertyDocuments(); UpdateDocumentFromModel(doc, obj); docList.Add(doc); } propertyDocumentType.PropertyDocuments = docList; } propertyDocumentTypeList.Add(propertyDocumentType); } property.PropertyDocumentType = propertyDocumentTypeList; UpdatePropertyFromModel(property, model); await dataService.UpdatePropertyAsync(property); model.Merge(await GetPropertyAsync(dataService, property.PropertyId)); return(model); } }