public void UploadImage(Guid objectId, string name) { Object currentObject = _context.Objects.FirstOrDefault(o => o.Id == objectId); currentObject.ImageName = name; _context.Entry(currentObject).Property(o => o.ImageName).IsModified = true; _context.SaveChanges(); }
private string GetPathToObject(Guid objectId) { Object obj = _objectRepository.GetById(objectId); if (obj.ParentId != null) { return($"{GetPathToObject(obj.ParentId.GetValueOrDefault())}/{_objectRepository.GetObjectName(objectId)}"); } else { return(_objectRepository.GetObjectName(objectId)); } }
public void UpdateObject(Object obj, List <Department> departments, int applyForChildren) { _context.Objects.Attach(obj); _context.Entry(obj).Property(o => o.Name).IsModified = true; _context.Entry(obj).Property(o => o.ObjectIdentifier).IsModified = true; _context.Entry(obj).Property(o => o.Latitude).IsModified = true; _context.Entry(obj).Property(o => o.Longitude).IsModified = true; _context.Entry(obj).Property(o => o.Comment).IsModified = true; _context.Entry(obj).Property(o => o.TfmId).IsModified = true; _context.SaveChanges(); UpdateDepartmentsForObject(obj.Id, departments); }
public IActionResult GetObject(Guid id) { Object objectFromRepo = _objectRepository.GetById(id); IEnumerable <User> usersFromRepo = objectFromRepo.ObjectUsers.Select(od => od.User); IEnumerable <UserDto> users = Mapper.Map <IEnumerable <User>, IEnumerable <UserDto> >(usersFromRepo); ObjectDto obj = Mapper.Map <ObjectDto>(objectFromRepo); obj.Departments = objectFromRepo.ObjectDepartments.Select(od => od.Department); obj.Users = users; obj.Path = GetPathToObject(id); return(Ok(obj)); }
public IActionResult UpdateObject(Guid objectId, [FromQuery(Name = "apply")] int applyForChildren, [FromBody] ObjectDto obj) { if (_objectRepository.ObjectExists(objectId) == false) { return(NotFound()); } List <Department> departmentsToBeUpdated = obj.Departments.ToList(); Object objectFromBody = Mapper.Map <Object>(obj); _objectRepository.UpdateObject(objectFromBody, departmentsToBeUpdated, applyForChildren); if (applyForChildren == 1) { ApplyDepartmentChangesForChildren(objectId, departmentsToBeUpdated); } return(Ok()); }