public void SaveBulk(IEnumerable <ReadOnlyRelation> relations) { foreach (IGrouping <bool, ReadOnlyRelation> hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) { if (hasIdentityGroup.Key) { // Do updates, we can't really do a bulk update so this is still a 1 by 1 operation // however we can bulk populate the object types. It might be possible to bulk update // with SQL but would be pretty ugly and we're not really too worried about that for perf, // it's the bulk inserts we care about. foreach (ReadOnlyRelation relation in hasIdentityGroup) { RelationDto dto = RelationFactory.BuildDto(relation); Database.Update(dto); } } else { // Do bulk inserts IEnumerable <RelationDto> dtos = hasIdentityGroup.Select(RelationFactory.BuildDto); Database.InsertBulk(dtos); } } }
private static IRelation DtoToEntity(RelationDto dto, IRelationType relationType) { var entity = RelationFactory.BuildEntity(dto, relationType); // reset dirty initial properties (U4-1946) entity.ResetDirtyProperties(false); return(entity); }
private static IRelation DtoToEntity(RelationDto dto, RelationFactory factory) { var entity = factory.BuildEntity(dto); // reset dirty initial properties (U4-1946) ((BeingDirtyBase)entity).ResetDirtyProperties(false); return(entity); }
private static IRelation DtoToEntity(RelationDto dto, RelationFactory factory) { var entity = factory.BuildEntity(dto); //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); return(entity); }
protected override void PersistUpdatedItem(IRelation entity) { entity.UpdatingEntity(); RelationDto dto = RelationFactory.BuildDto(entity); Database.Update(dto); PopulateObjectTypes(entity); entity.ResetDirtyProperties(); }
protected override void PersistNewItem(IRelation entity) { entity.AddingEntity(); RelationDto dto = RelationFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; PopulateObjectTypes(entity); entity.ResetDirtyProperties(); }
public async Task <IActionResult> AddUserToProjectAsync(int userId) { var relation = new RelationDto() { UserId = userId, ProjectId = HttpContext.Session.GetInt32("ProjectId").Value }; var mappedRelation = _mapper.Map <ProjectUserRelation>(relation); _context.ProjectUserRelation.Add(mappedRelation); await _context.SaveChangesAsync(); return(View()); }
public IRelation BuildEntity(RelationDto dto) { var entity = new Relation(dto.ParentId, dto.ChildId, _relationType) { Comment = dto.Comment, CreateDate = dto.Datetime, Id = dto.Id, UpdateDate = dto.Datetime }; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 entity.ResetDirtyProperties(false); return(entity); }
public void CheckRelationsSaving() { Random rand = new Random(); bool exist = false; var task = new RelationDto() { UserId = rand.Next(1, int.MaxValue), ProjectId = rand.Next(1, int.MaxValue) }; if (task is RelationDto && task != null) { exist = true; } Assert.IsTrue(exist); }
public void Save(IEnumerable <IRelation> relations) { foreach (IGrouping <bool, IRelation> hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) { if (hasIdentityGroup.Key) { // Do updates, we can't really do a bulk update so this is still a 1 by 1 operation // however we can bulk populate the object types. It might be possible to bulk update // with SQL but would be pretty ugly and we're not really too worried about that for perf, // it's the bulk inserts we care about. IRelation[] asArray = hasIdentityGroup.ToArray(); foreach (IRelation relation in hasIdentityGroup) { relation.UpdatingEntity(); RelationDto dto = RelationFactory.BuildDto(relation); Database.Update(dto); } PopulateObjectTypes(asArray); } else { // Do bulk inserts var entitiesAndDtos = hasIdentityGroup.ToDictionary( r => // key = entity { r.AddingEntity(); return(r); }, RelationFactory.BuildDto); // value = DTO foreach (RelationDto dto in entitiesAndDtos.Values) { Database.Insert(dto); } // All dtos now have IDs assigned foreach (KeyValuePair <IRelation, RelationDto> de in entitiesAndDtos) { // re-assign ID to the entity de.Key.Id = de.Value.Id; } PopulateObjectTypes(entitiesAndDtos.Keys.ToArray()); } } }
public RelationDto BuildDto(IRelation entity) { var dto = new RelationDto { ChildId = entity.ChildId, Comment = string.IsNullOrEmpty(entity.Comment) ? string.Empty : entity.Comment, Datetime = entity.CreateDate, ParentId = entity.ParentId, RelationType = entity.RelationType.Id }; if (entity.HasIdentity) { dto.Id = entity.Id; } return(dto); }
public static IRelation BuildEntity(RelationDto dto, IRelationType relationType) { var entity = new Relation(dto.ParentId, dto.ChildId, dto.ParentObjectType, dto.ChildObjectType, relationType); try { entity.DisableChangeTracking(); entity.Comment = dto.Comment; entity.CreateDate = dto.Datetime; entity.Id = dto.Id; entity.UpdateDate = dto.Datetime; // reset dirty initial properties (U4-1946) entity.ResetDirtyProperties(false); return(entity); } finally { entity.EnableChangeTracking(); } }
public IRelation BuildEntity(RelationDto dto) { var entity = new Relation(dto.ParentId, dto.ChildId, _relationType); try { entity.DisableChangeTracking(); entity.Comment = dto.Comment; entity.CreateDate = dto.Datetime; entity.Id = dto.Id; entity.UpdateDate = dto.Datetime; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 entity.ResetDirtyProperties(false); return(entity); } finally { entity.EnableChangeTracking(); } }
private async Task GetRelations() { try { if (attendees == null || attendees.Count == 0) { return; } List <string> emails = new List <string>(); foreach (Attendee att in attendees) { emails.Add(att.Email); } var header = new Dictionary <string, List <string> > { { "emails", emails } }; string jsonObject = JsonConvert.SerializeObject(header); string jsonObject2 = JsonConvert.SerializeObject(emails); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("email", jsonObject2); Debug.WriteLine("Writing headers"); Debug.WriteLine(client.DefaultRequestHeaders); string url = AppConstants.BaseUrl + AppConstants.getRelations; var res = await client.GetStringAsync(url); //Debug.WriteLine(res.Content); var info = JsonConvert.DeserializeObject <RelationResponse>(res); List <RelationDto> peopleInfo = info.result; Debug.WriteLine(peopleInfo.ToString()); for (int i = 0; i < attendees.Count; i++) { RelationDto person = peopleInfo[i]; if (person.first_name != null && person.first_name != "") { if (person.last_name != null && person.last_name != "") { attendees[i].Name = person.first_name + " " + person.last_name; } else { attendees[i].Name = person.first_name; } } if (person.role != null && person.role != "") { attendees[i].Relation = person.role; } else { attendees[i].Relation = "Unknown"; } if (person.picture != null && person.picture != "") { attendees[i].PicUrl = person.picture; attendees[i].HavePic = true; } if (person.phone_number != null && person.phone_number != "") { attendees[i].PhoneNumber = person.phone_number; attendees[i].HasPhoneNumber = true; } else { attendees[i].HasPhoneNumber = false; } } } catch (Exception e) { await DisplayAlert("Error", "Error in EventsPage in GetRelations function: " + e.ToString(), "OK"); } }
public Task RelationAddAsync(RelationDto add) { return(RelationAddAsync(new[] { add })); }
public Task RelationRemoveAsync(RelationDto remove) { return(RelationRemoveAsync(new[] { remove })); }
public async Task DeleteAsync([FromBody] RelationDto rdto) { IStreamFeed userTimeline = _streamApi.StreamClient.Feed("timeline", User.Identity.Name); await userTimeline.UnfollowFeed("user", rdto.UserToFollowUnfollow); }