Пример #1
0
        public async Task DeleteAsync(T objectModel, long userId, long houseId, long?targetObjectId)
        {
            var _object = context.Set <APPartment.Models.Object>().Where(x => x.ObjectId == objectModel.ObjectId).FirstOrDefault();

            context.Remove(_object);

            await this.SaveChangesAsync(true, houseId, userId, targetObjectId, 0, objectModel, ContextExecutionTypes.Delete);
        }
Пример #2
0
        private void DeleteObjectMetadataSubObjects(Models.Object @object)
        {
            if (@object.ObjectTypeId == (long)ObjectTypes.House)
            {
                var currentHouseId = context.Set <House>().Where(x => x.ObjectId == @object.ObjectId).FirstOrDefault().Id;

                var hasAnyHouseStatuses = context.HouseStatuses.Any(x => x.HouseId == currentHouseId);
                var hasAnyHouseSettings = context.HouseSettings.Any(x => x.HouseId == currentHouseId);

                if (hasAnyHouseStatuses)
                {
                    var houseStatuses = context.HouseStatuses.Where(x => x.HouseId == currentHouseId);

                    foreach (var houseStatus in houseStatuses)
                    {
                        context.Remove(houseStatus);
                    }
                }

                if (hasAnyHouseSettings)
                {
                    var houseSettings = context.HouseSettings.Where(x => x.HouseId == currentHouseId);

                    foreach (var houseSetting in houseSettings)
                    {
                        context.Remove(houseSetting);
                    }
                }
            }
            else if (@object.ObjectTypeId == (long)ObjectTypes.Inventory || @object.ObjectTypeId == (long)ObjectTypes.Hygiene ||
                     @object.ObjectTypeId == (long)ObjectTypes.Issue)
            {
                var hasAnyComments = context.Comments.Any(x => x.TargetId == @object.ObjectId);
                var hasAnyImages   = context.Images.Any(x => x.TargetId == @object.ObjectId);

                if (hasAnyComments)
                {
                    var comments = context.Comments.Where(x => x.TargetId == @object.ObjectId);

                    foreach (var comment in comments)
                    {
                        context.Remove(comment);
                    }
                }

                if (hasAnyImages)
                {
                    var images = context.Images.Where(x => x.TargetId == @object.ObjectId);

                    foreach (var image in images)
                    {
                        context.Remove(image);
                    }
                }
            }
        }
Пример #3
0
        public async Task DeleteAsync(T objectModel, long userId, long?targetObjectId, long houseId)
        {
            var _object = context.Set <Models.Object>().Where(x => x.ObjectId == objectModel.ObjectId).FirstOrDefault();

            historyContext.PopulateHistory((int)HistoryFunctionTypes.Delete, objectModel, _object, userId, targetObjectId, houseId);

            context.Remove(_object);
            context.Remove(objectModel);

            await context.SaveChangesAsync();
        }