public async Task SaveAsync(T objectModel, long userId, long?targetObjectId, long houseId) { var objectTypeName = objectModel.GetType().Name; var objectTypeId = context.Set <ObjectType>().Where(x => x.Name == objectTypeName).FirstOrDefault().Id; var _object = new Models.Object() { CreatedById = userId, ModifiedById = userId, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, ObjectTypeId = objectTypeId }; await context.AddAsync(_object); await context.SaveChangesAsync(); historyContext.PopulateHistory((int)HistoryFunctionTypes.Create, objectModel, _object, userId, targetObjectId, houseId); objectModel.ObjectId = _object.ObjectId; await context.AddAsync <T>(objectModel); await context.SaveChangesAsync(); }
public async Task SaveAsync(T objectModel, long userId, long houseId, long?targetObjectId) { var objectTypeName = objectModel.GetType().Name; var objectTypeId = context.Set <ObjectType>().Where(x => x.Name == objectTypeName).FirstOrDefault().Id; var _object = new APPartment.Models.Object() { CreatedById = userId, ModifiedById = userId, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, ObjectTypeId = objectTypeId }; await context.AddAsync(_object); await context.SaveChangesAsync(); objectModel.ObjectId = _object.ObjectId; await this.SaveChangesAsync(true, houseId, userId, targetObjectId, _object.ObjectId, objectModel, ContextExecutionTypes.Create); }
/// <summary> /// Sends an instance of a liked post to the database /// </summary> /// <param name="like"></param> /// <returns></returns> public async Task <bool> LikePost(Likes like) { await _ctx.AddAsync(like); return(await _ctx.SaveChangesAsync() > 0); }