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); } } } }
public List<BaseObject> GetDisplayObject(long? currentHouseId) { var displayObjects = new List<BaseObject>(); var lastInventoryModel = new Inventory(); var lastHygieneModel = new Hygiene(); var lastIssueModel = new Issue(); var inventoryObjects = _context.Set<Inventory>().Where(x => x.HouseId == currentHouseId); if (inventoryObjects.Count() > 0) { var inventoryObject = _context.Set<Models.Object>().Where(x => x.ObjectTypeId == (long)ObjectTypes.Inventory).OrderByDescending(x => x.ModifiedDate).First(); lastInventoryModel = _context.Set<Inventory>().Where(x => x.ObjectId == inventoryObject.ObjectId).FirstOrDefault(); var when = _context.Histories.Where(x => x.ObjectId == lastInventoryModel.ObjectId || x.TargetId == lastInventoryModel.ObjectId) .OrderByDescending(x => x.Id).FirstOrDefault().When; lastInventoryModel.LastUpdated = when == null ? string.Empty : timeConverter.CalculateRelativeTime(when); lastInventoryModel.LastUpdatedBy = _context.Users.Where(x => x.UserId == inventoryObject.ModifiedById).FirstOrDefault().Username; lastInventoryModel.LastUpdate = historyHtmlBuilder.BuildLastUpdateBaseObjectHistoryForWidget(lastInventoryModel.ObjectId); } var hygieneObjects = _context.Set<Hygiene>().Where(x => x.HouseId == currentHouseId); if (hygieneObjects.Count() > 0) { var hygieneObject = _context.Set<Models.Object>().Where(x => x.ObjectTypeId == (long)ObjectTypes.Hygiene).OrderByDescending(x => x.ModifiedDate).First(); lastHygieneModel = _context.Set<Hygiene>().Where(x => x.ObjectId == hygieneObject.ObjectId).FirstOrDefault(); var when = _context.Histories.Where(x => x.ObjectId == lastHygieneModel.ObjectId || x.TargetId == lastHygieneModel.ObjectId) .OrderByDescending(x => x.Id).FirstOrDefault().When; lastHygieneModel.LastUpdated = when == null ? string.Empty : timeConverter.CalculateRelativeTime(when); lastHygieneModel.LastUpdatedBy = _context.Users.Where(x => x.UserId == hygieneObject.ModifiedById).FirstOrDefault().Username; lastHygieneModel.LastUpdate = historyHtmlBuilder.BuildLastUpdateBaseObjectHistoryForWidget(lastHygieneModel.ObjectId); } var issueObjects = _context.Set<Issue>().Where(x => x.HouseId == currentHouseId); if (issueObjects.Count() > 0) { var issueObject = _context.Set<Models.Object>().Where(x => x.ObjectTypeId == (long)ObjectTypes.Issue).OrderByDescending(x => x.ModifiedDate).First(); lastIssueModel = _context.Set<Issue>().Where(x => x.ObjectId == issueObject.ObjectId).FirstOrDefault(); var when = _context.Histories.Where(x => x.ObjectId == lastIssueModel.ObjectId || x.TargetId == lastIssueModel.ObjectId) .OrderByDescending(x => x.Id).FirstOrDefault().When; lastIssueModel.LastUpdated = when == null ? string.Empty : timeConverter.CalculateRelativeTime(when); lastIssueModel.LastUpdatedBy = _context.Users.Where(x => x.UserId == issueObject.ModifiedById).FirstOrDefault().Username; lastIssueModel.LastUpdate = historyHtmlBuilder.BuildLastUpdateBaseObjectHistoryForWidget(lastIssueModel.ObjectId); } displayObjects.Add(lastInventoryModel); displayObjects.Add(lastHygieneModel); displayObjects.Add(lastIssueModel); return displayObjects; }
public async Task <IActionResult> Completed() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("HouseId"))) { return(RedirectToAction("Login", "Account")); } var currentHouseId = long.Parse(HttpContext.Session.GetString("HouseId")); var modelObjects = await _context.Set <Survey>().Where(x => x.HouseId == currentHouseId && x.IsCompleted == true).ToListAsync(); ViewData["GridTitle"] = "Surveys - Completed"; ViewData["Module"] = "Surveys"; ViewData["Manage"] = false; return(View("_Grid", modelObjects)); }
protected DataAccessRepository(DataAccessContext context, IMapper mapper) { _context = context ?? throw new ArgumentNullException(nameof(context)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _context = context; context.Database.OpenConnection(); _dbSet = context.Set <T>(); }
public async Task <IActionResult> Cleaned() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("HouseId"))) { return(RedirectToAction("Login", "Account")); } var currentHouseId = long.Parse(HttpContext.Session.GetString("HouseId")); var modelObjects = await _context.Set <Hygiene>().Where(x => x.HouseId == currentHouseId && x.IsCompleted == true).ToListAsync(); ViewData["GridTitle"] = "Hygiene - Cleaned"; ViewData["Module"] = "Hygiene"; ViewData["Manage"] = false; ViewData["Statuses"] = baseService.GetStatuses(typeof(Hygiene)); return(View("_Grid", modelObjects)); }
public async Task <IActionResult> Others() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("HouseId"))) { return(RedirectToAction("Login", "Account")); } var currentHouseId = long.Parse(HttpContext.Session.GetString("HouseId")); var currentUserId = long.Parse(HttpContext.Session.GetString("UserId")); var modelObjects = await _context.Set <Chore>().Where(x => x.HouseId == currentHouseId && x.AssignedToId != currentUserId).ToListAsync(); ViewData["GridTitle"] = "Chores - Others"; ViewData["Module"] = "Chores"; ViewData["Manage"] = false; ViewData["Statuses"] = baseService.GetStatuses(typeof(Chore)); return(View("_Grid", modelObjects)); }
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 virtual async Task <IActionResult> Index() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("HouseId"))) { return(RedirectToAction("Login", "Account")); } var currentHouseId = long.Parse(HttpContext.Session.GetString("HouseId")); var modelObjects = await _context.Set <T>().Where(x => x.HouseId == currentHouseId).ToListAsync(); ViewData["Manage"] = true; ViewData["Statuses"] = baseService.GetStatuses(typeof(T)); return(View("_Grid", modelObjects)); }
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); }
public GenericRepository(DataAccessContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public bool ObjectExists(long id) { return(_context.Set <T>().Any(e => e.Id == id)); }