private void UpdatePropertyPartyFromModel(PropertyParty target, PropertyPartyModel source) { target.PropertyPartyId = source.PropertyPartyId; target.PropertyGuid = source.PropertyGuid; target.PartyId = source.PartyId; target.PropertyId = source.PropertyId; target.IsGroup = source.IsGroup; target.IsPrimaryParty = source.IsPrimaryParty; }
public async Task <int> DeletePropertyPartyAsync(PropertyPartyModel model) { var property = new PropertyParty { PropertyPartyId = model.PropertyPartyId }; using (var dataService = DataServiceFactory.CreateDataService()) { return(await dataService.DeletePropertyPartyAsync(property)); } }
public async Task <int> AddPropertyPartyAsync(List <PropertyPartyModel> propertyParties) { using (var dataService = DataServiceFactory.CreateDataService()) { List <PropertyParty> list = new List <PropertyParty>(); foreach (var model in propertyParties) { PropertyParty party = new PropertyParty(); UpdatePropertyPartyFromModel(party, model); list.Add(party); } return(await dataService.AddPropertyParty(list)); } }
static public async Task <PropertyPartyModel> CreatePropertyPartyModelAsync(PropertyParty source) { var model = new PropertyPartyModel() { PropertyPartyId = source.PropertyPartyId, PropertyGuid = source.PropertyGuid, PartyId = source.PartyId, PropertyId = source.PropertyId, PartyName = source.PartyName, IsGroup = source.IsGroup, IsPrimaryParty = source.IsPrimaryParty }; return(model); }
public async Task <int> AddPropertyParty(List <PropertyParty> propertyParties) { if (propertyParties == null) { return(0); } var party = propertyParties[0]; var properties = await _dataSource.Properties.Where(x => x.GroupGuid == party.PropertyGuid).ToListAsync(); foreach (var prop in properties) { var existParty = _dataSource.PropertyParty.Where(x => x.PropertyId == prop.PropertyId).ToList(); if (existParty != null) { _dataSource.PropertyParty.RemoveRange(existParty); await _dataSource.SaveChangesAsync(); } var entity = new PropertyParty { PropertyId = prop.PropertyId, IsGroup = party.IsGroup, IsPrimaryParty = party.IsPrimaryParty, PartyId = party.PartyId, PropertyGuid = party.PropertyGuid }; _dataSource.Entry(entity).State = EntityState.Added; } //foreach (var model in propertyParties) { // if(model.PropertyPartyId==0) // _dataSource.Entry(model).State = EntityState.Added; // else // _dataSource.Entry(model).State = EntityState.Modified; //} int res = await _dataSource.SaveChangesAsync(); return(res); }
public async Task <int> DeletePropertyPartyAsync(PropertyParty model) { _dataSource.PropertyParty.Remove(model); return(await _dataSource.SaveChangesAsync()); }